Restrict CPU cores and memory to one single process
by james000 from LinuxQuestions.org on (#6P8Y8)
Hi,
I have a Centos 8 VM with 24 gb memory and 6 CPUs. There is one report which runs every night and application team want this process to use only max of 8 gb memory and 2 CPUs.
Code:[root@centos-8 ~]# ps -ef | grep snapshotreports
webadm4 3651168 1 1 Jul15 ? 00:14:35 /usr/bin/java -Dsnapshotreportsinstance=snapshotreports-4.0 -Xms1G -Xmx4G --add-opens java.base/java.lang=ALL-UNNAMED -Dlog.dir=/export/home/webadm4/snapshotreports-4.0/logs -jar /export/home/webadm4/snapshotreports-4.0/snapshotreports-4.0.0-SNAPSHOT.jar --logging.config=logback-spring.xml
root 3723926 3715482 0 14:51 pts/1 00:00:00 grep --color=auto snapshotreports
[root@centos-8 ~]#Reason is, when this report runs at midnight, it consumes lot of memory and CPU and that leaves other process short of resources and eventually killed. I am trying to figure, how to restrict memory and CPU to a single resource.
I read few pages and I see one option to restrict 2 CPUs is below -
Quote:
But this will be tied to PID only. When the application/server will restart, PID will change. Any other way I can set it ?
For memory - I can set "ulimit -v 2097152" in webadm4. But that will restrict other processes also running under webadm4.
Please advice, what would be best way to achieve both these results.
Thanks
I have a Centos 8 VM with 24 gb memory and 6 CPUs. There is one report which runs every night and application team want this process to use only max of 8 gb memory and 2 CPUs.
Code:[root@centos-8 ~]# ps -ef | grep snapshotreports
webadm4 3651168 1 1 Jul15 ? 00:14:35 /usr/bin/java -Dsnapshotreportsinstance=snapshotreports-4.0 -Xms1G -Xmx4G --add-opens java.base/java.lang=ALL-UNNAMED -Dlog.dir=/export/home/webadm4/snapshotreports-4.0/logs -jar /export/home/webadm4/snapshotreports-4.0/snapshotreports-4.0.0-SNAPSHOT.jar --logging.config=logback-spring.xml
root 3723926 3715482 0 14:51 pts/1 00:00:00 grep --color=auto snapshotreports
[root@centos-8 ~]#Reason is, when this report runs at midnight, it consumes lot of memory and CPU and that leaves other process short of resources and eventually killed. I am trying to figure, how to restrict memory and CPU to a single resource.
I read few pages and I see one option to restrict 2 CPUs is below -
Quote:
taskset -cp 0,1 3651168 |
For memory - I can set "ulimit -v 2097152" in webadm4. But that will restrict other processes also running under webadm4.
Please advice, what would be best way to achieve both these results.
Thanks