问题
I would like to know if anyone wrote a code in python that simulates a cpu and memory stress. I saw a code loading the cpus, but how can I force them to work on 90% usage?
回答1:
The below link answers the cpu stress. https://github.com/GaetanoCarlucci/CPULoadGenerator
It appeared in that session: https://superuser.com/questions/396501/how-can-i-produce-high-cpu-load-on-windows/734782#734782?newreg=bec18b2f032a444187a8be7540ec6083
回答2:
A node has mainly 4 resources that are under constant use -
- available memory
- cpu cycles
- storage space
- network load (uploads & downloads)
That is why the task manager on Windows or Activity Monitor on macOS (or top, free commands on *nix systems).
If a specific python solution is required, then I would recommend stress and stressypy modules. Here are the links- https://pypi.org/project/stress/ https://pypi.org/project/stressypy/
simple pip install would do the work.
But personally, I am a fan of stress-ng application. You can easily install and put the required loads on all the above resources Here, find it- https://www.mankier.com/1/stress-ng
Refer to these examples- https://www.mankier.com/1/stress-ng#Examples
stress-ng --cpu 4 --io 2 --vm 1 --vm-bytes 1G --timeout 60s
runs for 60 seconds with 4 cpu stressors, 2 io stressors and 1 vm stressor using 1GB of virtual memory.
stress-ng --iomix 2 --iomix-bytes 10% -t 10m
runs 2 instances of the mixed I/O stressors using a total of 10% of the available file system space for 10 minutes. Each stressor will use 5% of the available file system space.
stress-ng --cpu 8 --cpu-ops 800000
runs 8 cpu stressors and stops after 800000 bogo operations.
stress-ng --sequential 2 --timeout 2m --metrics
run 2 simultaneous instances of all the stressors sequentially one by one, each for 2 minutes and summarise with performance metrics at the end.
来源:https://stackoverflow.com/questions/35312756/how-can-i-simulate-cpu-and-memory-stress-in-python