-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Windows] emulate UNIX os.getloadavg() #1484
Comments
CC-ing @ammaraskar just in case he wants to provide advice/direction. |
Hey, it's entirely possible to do the 3 values. The best literature to read would definitely be: https://en.wikipedia.org/wiki/Load_(computing)#Unix-style_load_calculation which explains really well how the value is calculated. Essentially its the weighted moving average of the number of processes in the run queue of the OS over 1 minute, 5 minutes and 15 minutes. You can find Linux's load average calculation here: https://github.com/torvalds/linux/blob/345671ea0f9258f410eb057b9ced9cefbbe5dc78/include/linux/sched/loadavg.h#L18-L38 which is what is emulated in https://github.com/python/cpython/blob/master/Lib/test/libregrtest/win_utils.py#L97 As the Linux comment eludes, the constants can be calculated by: for example, in CPython we only care about the 1 minute window and we sample every 5 seconds, so the constant comes from: You can calculate out the constants for the other windows (5 minutes and 15 minutes) and track those separately as well like Linux does in order to fully emulate it: https://github.com/torvalds/linux/blob/345671ea0f9258f410eb057b9ced9cefbbe5dc78/kernel/sched/loadavg.c#L356-L358 Hope this helps and lemme know if you have any other questions. |
Oh also, I should say the calculations are the easy part. Getting the actual number of processes in the run queue for windows is an absolute pain and we ended up running the command:
in order to grab the value. There's some win32 apis that can achieve the same thing but are way more involved in the C side. |
Thanks for the info @ammaraskar. It appears this could theoretically be good for inclusion but I suspect that running
Do you know which ones? |
You can find the C based implementation I did for CPython here python/cpython@master...ammaraskar:windows_load Internally, this windows API spins up a thread to do the sampling. |
Sweet, thanks. I'll take a look at that and I will probably ping you later on with some questions. =) |
Some questions:
|
1 minute: 0.92004441462932324789315532405371723167318753495997420170
|
Cool, thanks. To quickly set you up:
|
...last: you may want to change the Python path in make.bat: |
* origin/master: Fix giampaolo#1276: [AIX] use getargs to get process cmdline (giampaolo#1500) (patch by @wiggin15) Fix Process.ionice example using wrong keyword arg (giampaolo#1504) fix history syntax remove catching IOError; let the test fail and adjust it later Fix cpu freq (giampaolo#1496) pre release fix giampaolo#1493: [Linux] cpu_freq(): handle the case where /sys/devices/system/cpu/cpufreq/ exists but is empty. Revert "Fix cpu_freq (giampaolo#1493)" (giampaolo#1495) Fix cpu_freq (giampaolo#1493) Update cpu_freq to return 0 for max/min if not available (giampaolo#1487) give CREDITS to @agnewee for giampaolo#1491 SunOS / net_if_addrs(): free() ifap struct on error (giampaolo#1491) fix giampaolo#1486: add wraps() decorator around wrap_exceptions refactor/move some utilities into _common.py update doc update HISTORY Implement getloadavg on Windows. Fixes giampaolo#604 and giampaolo#1484 (giampaolo#1485) (patch by Ammar Askar) give credits to @amanusk for giampaolo#1472
I'm not sure I understand whether we can really emulate the UNIX counterpart, but this looks interesting:
https://bugs.python.org/issue34060
python/cpython@e16467a
https://github.com/python/cpython/blob/master/Lib/test/libregrtest/win_utils.py
Part of the confusion is that I currently don't really understand how
getloadavg()
should be interpreted (need to read some literature) . My hope is to land something like this:...but returning 1 value (on Windows, average since last call) vs. 3 values (on UNIX, representing the average of last 1, 5, 15 minutes) maybe suggests these are 2 different things so we should call it differently?
The text was updated successfully, but these errors were encountered: