The foundation is the top priority ~ The cost of multithreading ~ My memory has been eaten !, Heavy Multithreading

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.