litmuschaos / litmus

Litmus helps SREs and developers practice chaos engineering in a Cloud-native way. Chaos experiments are published at the ChaosHub (https://hub.litmuschaos.io). Community notes is at https://hackmd.io/a4Zu_sH4TZGeih-xCimi3Q
https://litmuschaos.io
Apache License 2.0
4.35k stars 684 forks source link

Fine grained control over cpu usage for CPU Hog Exec experiment #4190

Open rociomroman opened 11 months ago

rociomroman commented 11 months ago

Details:

I've read the stress package makes this easy with the following command: stress --cpu 1 --cpu-load 0.5 --timeout 60s Unfortunately, we're unable to use the stress linux packages at the moment. Looking to leverage a basic cpu utility available in the linux distros by default. From my research, taskset could be useful but it only allows for whole core, not fractions of a core. Any insights are highly appreciated. Thank you

vanshBhatia-A4k9 commented 10 months ago

can you PTAL: @uditgaurav

uditgaurav commented 10 months ago

We may need enhance the logic for this here but it won't be straight forward.

CPUs are designed to be either fully utilised or idle, so trying to precisely control them to be used at a certain intermediate level (like 50% or 75%) is complex. The OS scheduler is designed to allocate CPU time to processes based on need and priority, not to artificially limit a process to a certain percentage of CPU time.

We recommend adopting the 'cpu-hog' method over 'cpu-hog-exec' due to its significant advantages: