Unity creates too many threads
We use headless linux build (running in batchmode) for our dedicated servers and we launch multiple application instances on each of our server machines. But we encountered a problem that each process creates too many threads which seem unnecessary. It looks as if number of threads depends on the number of logical cores of the running machine. For example on 1-core VM it creates 30 threads, on 4-core - 37 threads, on 36-core production machine - 99 threads. On my windows machine with 12 cores - 60 threads. So the problem not only for linux builds.
There is another worrying notice, but I'm not sure if it's connected to the threads issue: more than half of CPU time is consumed by system calls and strace shows following results (for a 20 seconds interval):
% time seconds usecs/call calls errors syscall ------ ----------- ----------- --------- --------- ---------------- 99.59 3.971471 38 105655 futex 0.21 0.008423 23 366 stat 0.15 0.006040 33 185 sendto 0.03 0.001224 26 47 47 accept 0.01 0.000269 269 1 restart_syscall 0.00 0.000198 8 24 12 write 0.00 0.000059 5 12 lseek 0.00 0.000000 0 1 clone 0.00 0.000000 0 2 uname ------ ----------- ----------- --------- --------- ---------------- 100.00 3.987684 106293 59 total
We tried following things:
Disabling development mode
Setting "Realtime Global Illumination CPU usage" in graphics settings to low
Disabling GI for each scene by setting "m_EnableRealtimeLightmaps", "m_EnableBakedLightmaps", "m_AlbedoBoost" to 0 and "m_GIWorkflowMode" to 1 in scene files
Setting CPU affinity to a single core using either taskset utility and sched_setaffinity system call
Nothing seems to have any effect on amount of threads. We use Unity 2018.2.12f1 but we also tried 2018.3.8f1
Is there a way to reduce number of threads unity creates and therefore decrease corresponding overhead?
Did you find a solution to this? I'm currently facing the exact same issue... 25-30 threads per game instance....
Answer by LarsGameloft · Nov 02, 2020 at 10:10 PM
Did you get an answer for this? I am having an issue where my app creates more threads than allowed by the hardware. Thank you
Your answer
Follow this Question
Related Questions
Server-side rendering with no display 0 Answers
Cache Server in Batchmode 1 Answer
Linux Standalone player can not find GPU 1 Answer
how to enable graphics device in batchmode 1 Answer
FixedUpdate logic step by step 1 Answer