Can python script (Or any other programming language scripts) be used to restrict resources (like RAM, CPU Usage) used by other applications?

StackOverflow https://stackoverflow.com//questions/21063991

Question

For my project, I am supposed to measure system performance of OpenStack SWIFT based on available resources like RAM, CPU, etc.. So, I was wondering, can I use a python script or some other programming language scripts to restrict the resources usage by OpenStack SWIFT to measure the impacts of those resources on the OpenStack SWIFT ???

Please reply!!!

Was it helpful?

Solution

By using python resource module you can set the resource limit, please check more detail in the official docs resource

import resource
resource.setrlimit(resource.RLIMIT_CPU, (1, 1))

By using subprocess you can change the ulimit: system wide resource and nice level i.e scheduling priority.

import subprocess
subprocess.Popen('ulimit -t 10; nice -n 15 application_name', shell=True)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top