Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
GitHub or Developer Community with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
Description of Problem:
When I call ThreadPool.SetMinThreads it appears that mono only creates one new thread regardless of the delta between the number of existing thread pool threads and what I've requested. I have to run that command in a loop to get the full number of threads. Additionally, it appears that every .5s it will only increase the thread pool by 1, regardless of the load factor. This can lead to a situation where a highly variable workload will get stuck for long periods of time after the load increases instantaneously.
Steps to reproduce the problem:
1. Call SetMinThreads(200, 100) and then use 'top -H -n 1 -b | grep mono | wc -l' to count the number of threads.
Very few threads.
Very many threads.
How often does this happen?
Here is the code that appears to only create 1 new thread when you call SetMinThreads:
I haven't verified the slow increasing number of threads is capped at 1, but that could possibly be argued as a correct behavior anyway.
I have compared this to .NET 4.0. This behaves rather differently to mono 3.0.1 Linux and OSX.
Using worker threads, with a max and min set to 10, on a 4 core platform, creating and releasing 20 threads.
The SetMinThreads() seems to initialise a collection of threads at this size. These can be used without delay. After this limit it reached, extra threads are created with a delay of about .5 seconds.
When released, the thread pool under .NET seems to shrink back down to the value of the SetMaxThreads().
Therefore the test is repeatable after a release of all threads: threads under this limit come from the pool, over this limit are created with a delay.
It seems that both the SetMinThreads() and SetMaxThreads() are ignored. Each thread is created with a delay. On release of threads, the thread pool seems to maintain its maximum size, not the size set in SetMaxThreads(). Therefore a second allocation of threads will allocate without delay.
Is https://github.com/mono/mono/pull/640 a fix or partial fix for this?
This now works as expected.