Let say I want a Ruby process to not use more than 15% of the CPU. Is it possible? How?
You could try using Process.setrlimit
from the standard core:
Sets the resource limit of the process.
This looks like it is just a wrapper around the setrlimit
from the C library so it may only be available on Unix-ish platforms. setrlimit
doesn't support CPU percentage limits but it does support limiting CPU time in seconds.
If you're just trying to keep your Ruby process from hogging the whole CPU then you could try adjusting its priority with Process.setpriority
which is just a wrapper around libc's setpriority
and offers some control over your process's scheduling priority. Again, availability will probably be limited by your platform but it should work on Linux, OSX, or any other Unix-ish system.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With