Docs/CloudNative/Docker/cgroup限制cpu
2022-10-18 16:59:37 +08:00

17 lines
No EOL
651 B
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

cgroup用来管理linux下的cpu资源使用cgroup可以很好的限制程序的资源使用情况下面是对cgroup限制程序cpu使用情况的一些介绍
1、首先构造一个占用cpu资源的程序
echo 'while True:pass'|python &
使用top命令可以看到该进程CPU使用达到90%以上
2、进入到/sys/fs/cgroup/cpu目录下创建一个文件夹例如test
3、进入到test文件夹下会看到已自动创建了一些文件此时输入
echo 50000 > cpu.cfs_quota_us
echo 1741 > tasks
会使得把1741进程的cpu占用时间比例降到50%。使用top命令可以确认查看该设置是否成功。