Idle loop consumes (too) much CPU
Posted: Thu Dec 19, 2013 4:06 pm
Following simulates 100 client-threads that are doing nothing exept to sleep for one ms each loop. I've two virtual machines running on the same host with same amount of assigned CPUs (one is WinXP 32bit one is Debian Wheezy 64bit). Same code on WinXP consumes most time 0% CPU while it consumes about 12%-13% on Linux (both time debugger is off). If I increase to 256 threads it already consumes about 34% on Linux while it's still most time 0% on windows (sometimes it's short time up to 2-5% ... which is still way less than 34% and grows down to 0% soon again). I read something regading some change in newer kernels so some nanosleep() or usleep() sleeps now way shorter than before (and it seems some apps was built with pretty tiny delays so the loops looped much more then previously). However the granularity of Delay() is only in Milliseconds anyway (so no nanoseconds or microseconds)? Any thoughts on this?
Code: Select all
Procedure idle(*void)
Repeat
Delay(1)
ForEver
EndProcedure
For x = 1 To 100
CreateThread(@idle(),0)
Next
Repeat
Delay(1)
ForEver