The foundation is the top priority ~ The cost of multithreading ~ My memory has been eaten !, Heavy Multithreading
Back to directory
Asynchronous Operation is. the new term net4.5 was launched. In fact, this thing has long been available. It is implemented through the thread pool, which divides a large task into multiple small blocks, each thread processes one of them in parallel, and then tells the result to the main thread. after net4.5 was launched, this technology was encapsulated to make it easier for developers to implement it. However, concurrency (step-by-step, multi-thread) is not applicable anywhere and is improperly used, there may be many serious consequences!
Look at my program. This guy has occupied GB of memory. It's terrible!
The reason for this problem is that I did not clarify the thread. In a call-intensive environment, multithreading is used, there will be more than N threads in the thread pool. I don't think the processing speed is improved, but the memory is very serious,This is because you have too many working threads..
Therefore, multithreading, parallelism, and Asynchronization are not applicable anywhere. It can be used when you call a password, because it will consume a lot of memory. If you have to use it, please set the maximum number of thread pools to 10.
The following is an example of multi-thread memory consumption.
While (true) {// ThreadPool. setMaxThreads (10, 10); // restrict the maximum working thread and I/o thread ThreadPool. queueUserWorkItem (new WaitCallback (a) =>{ ConcurrentDictionary <string, SendingResult> test2 = new ConcurrentDictionary <string, SendingResult> (); test2.TryAdd (Guid. newGuid (). toString (), new SendingResult {BatchNumber = Guid. newGuid (). toString (), DbName = "zzl", EndId = 1, StartId = 1, TableName = "zzl", OccurDate = DateTime. now,}) ;})); if (DateTime. now. minute = 02) {break ;}}
View a task manager
This situation has been improved when I set a limit on the working thread.
WhileIf multiple threads are not used for frequent operations (the Training Service), the performance will be better if no memory is consumed!
Thank you for reading this article!
Back to directory