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.
When running a mono application as a cgroup task which is limited to a particular cpuset (such as when the application is running under a docker container which was created using --cpuset-cpus argument), mono will create its various threadpools sized as though it has access to all CPU cores.
This complicates running in a multi-tenant dockerized environment, as per above, docker uses cgroups to set processor affinity for each container. For more information about this, see  below.
This cause of this problem appears to be that when running on linux, mono appears to set thread pool sizes based on the number of system processors. At present this count is determined either by parsing /proc/stat, or via the glibc sysconf extension _SC_NPROCESSORS_ONLN. When running as a cgroup task limited to a specific cpuset (as is the case with docker), or when running with processor affinity set, these values still report the full core count of the host machine.
It seems likely that mono should instead account for processor affinity when determining these thread sizes. It's arguable that mono may also wish to consider CPU affinity when reporting System.Environment.Processors, as I'm not sure that any other runtime call would exist to signal to code within the VM that it is running on a reduced set of processors.
er, that should have read System.Environment.ProcessorCount :-/
Here is a PR to fix this issue: https://github.com/mono/mono/pull/2722. Could you please review it, and check that it fixes your issue, as I don't have any docker container set up or anything.
Thanks heaps for the quick turn-around, Ludovic! At first glance it looks like it should work. Since it appears to be merged into master I'll see if I can't fire up a test container running our application which has been experiencing this issue.
I'll likely only be able to get to this tomorrow, however. Either way I'll keep you posted.