Home > Net >  C # thread between memory and processing
C # thread between memory and processing

Time:11-14

I kept open new threads, thread method the time interval of the running time than open threads,
Causes the threads are on the increase at the same time, the memory is growing, CPU and memory will explode,
Then optimized the method of thread running time and memory processing, but still faces a 100% CPU often lead to stuck, if use a thread pool to control open the queue for a maximum of four threads, CPU and stable operation, but memory will overflow,
At that time what kind of good way?

CodePudding user response:

I remember the thread pool to execute tasks, performed feedback can perform again next, can completely solve the resource abuse

CodePudding user response:

"Doctor, I have a headache"
The doctor said that "to do the check first
"
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Here, we don't like blog garden, have a headache is murder, then say "aspirin", so now we will not give you a prescription,

You have to use vs their diagnostic tools, to the actual detection, what accounts for the memory,

CodePudding user response:

1 using a thread pool, should be no problem
2 out of memory, you check whether there is a Shared variables without recycling,

CodePudding user response:

If there is no Shared variables, then it may be the problem of large objects,
This need you to optimization of large objects, or add threads memory size,

CodePudding user response:

Machine operation ability, memory capacity is so big, if determined to make its ability to deal with more than their things, certainly will lack the resources,
The thread pool can alleviate the optimization scheduling, can't completely solve this problem,
May increase the CPU, more memory is the most direct, most violent solution,

CodePudding user response:

You can use the queue, thread pool, limit the number of concurrent threads

CodePudding user response:

I kept open new thread
- "thread quite a waste of resources, too much thread will cause the CPU usage, the best number of CPU cores, refer to # 6 suggested that limit the number of concurrent threads and query Task usage,
Memory explosion, of course, may also be caused by not only the threads, such as release unmanaged resources occupation, not in time without using a cache, etc.,

CodePudding user response:

Out of memory and thread processing is not absolute, can only say that thread execute the task itself to resources recycling is problematic,

CodePudding user response:

refer to the eighth floor closure guest response:
memory and thread processing is not absolute, can only say that thread execute the task itself to resources recycling is problematic,


Sub-set, thread itself would take resources, short time a large number of threads is enabled, the system cannot perform all of the threads at the same time (CPU core co., LTD.), redundant thread data will be cached in memory to line up, such as to perform again, if this thread accumulation is overmuch, performance result is CPU usage is not high, but the boom in memory,

CodePudding user response:

Said I was in a close study of the process goes beep: I am receiving the image to my camera, 23 frames a second, every image processing, also is the equivalent of a frame image to open a thread, thread method is image processing algorithm, inside thread image can also processing release after the end of the thread to process the image is not the same time, the fastest time 3 ms treatment ends, the slowest 500 ms, this leads to the thread open too much, CPU, then slowly clog thread method, image processing is not timely release of images, resulting in memory explosion

CodePudding user response:

Abandon a thread, use the Async Task, add a callback processing, not possible you say this kind of situation, and I feel your image processing code seems to have a problem, you are asynchronous, the error code of capture?

CodePudding user response:

A basic check for yourself, we can only open first pills and give it a try,
https://github.com/Microsoft/Microsoft.IO.RecyclableMemoryStream

Ps: ditto threads can indeed memory, do not have what relation, don't need to refer to those who see blog garden all day, we have countless times to prove that you are here at the same time open 1 ten million simple threads are no problem, only 1 ms

Problem is not in the thread, in you new stream, we all don't say what the thread is not line, you see the ans is a single-threaded new byte (1024 * 1024 * 1024) continuous system can make you new several times?
  •  Tags:  
  • C#
  • Related