Linux 为什么系统 CPU 时间 (%sy) 高?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19547019/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why is the system CPU time (% sy) high?
提问by Abhishek
I am running a script that loads big files. I ran the same script in a single core OpenSuSe server and quad core PC. As expected in my PC it is much more faster than in the server. But, the script slows down the server and makes it impossible to do anything else.
我正在运行一个加载大文件的脚本。我在单核 OpenSuSe 服务器和四核 PC 中运行了相同的脚本。正如在我的 PC 中所预期的那样,它比在服务器中要快得多。但是,该脚本会减慢服务器的速度并使其无法执行任何其他操作。
My script is
我的脚本是
for 100 iterations
Load saved data (about 10 mb)
time myscript (in PC)
时间 myscript(在 PC 中)
real 0m52.564s
user 0m51.768s
sys 0m0.524s
time myscript (in server)
时间 myscript(在服务器中)
real 32m32.810s
user 4m37.677s
sys 12m51.524s
I wonder why "sys" is so high when i run the code in server. I used top command to check the memory and cpu usage.It seems there is still free memory, so swapping is not the reason. % sy is so high, its probably the reason for the speed of server but I dont know what is causing % sy so high. The process that is using highest percent of CPU (99%) is "myscript". %wa is zero in the screenshot but sometimes it gets very high (50 %).
我想知道为什么在服务器中运行代码时“sys”如此之高。我使用 top 命令来检查内存和 CPU 使用情况。似乎还有空闲内存,所以交换不是原因。% sy 如此之高,这可能是服务器速度的原因,但我不知道是什么导致 % sy 如此之高。使用最高百分比 CPU (99%) 的进程是“myscript”。屏幕截图中的 %wa 为零,但有时会变得非常高(50 %)。
When the script is running, load average is greater than 1 but have never seen to be as high as 2.
脚本运行时,平均负载大于1但从未见过高达2。
I also checked my disc:
我还检查了我的光盘:
strt:~ # hdparm -tT /dev/sda
/dev/sda:
Timing cached reads: 16480 MB in 2.00 seconds = 8247.94 MB/sec
Timing buffered disk reads: 20 MB in 3.44 seconds = 5.81 MB/sec
john@strt:~> df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 245G 102G 131G 44% /
udev 4.0G 152K 4.0G 1% /dev
tmpfs 4.0G 76K 4.0G 1% /dev/shm
I have checked these things but I am still not sure what is the real problem in my server and how to fix it. Can anyone identify a probable reason for the slowness? What could be the solution? Or is there anything else I should check?
我已经检查了这些东西,但我仍然不确定我的服务器中的真正问题是什么以及如何解决它。任何人都可以确定缓慢的可能原因吗?解决办法是什么?或者还有什么我应该检查的吗?
Thanks!
谢谢!
回答by Kalin Staykov
You're getting a high sysactivity because the load of the data you're doing takes system calls that happen in kernel. To resolve your slowness problems without upgrading the server might be possible. You can modify scheduling priority. See the man
pages for nice
and renice
. See hereand especially:
您正在获得高sys活动,因为您正在执行的数据加载需要发生在内核中的系统调用。在不升级服务器的情况下解决您的缓慢问题可能是可能的。您可以修改调度优先级。见man
换页nice
和renice
。见这里,特别是:
Niceness values range from -20 (the highest priority, lowest niceness) and 19 (the lowest priority, highest niceness).
Niceness 值范围从-20(最高优先级,最低niceness)和19(最低优先级,最高niceness)。
$ ps -lp 941
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
4 S 0 941 1 0 70 -10 - 1713 poll_s ? 00:00:00 sshd
$ nice -n 19 ./test.sh
My niceness value is 19
$ renice -n 10 -p 941
941 (process ID) old priority -10, new priority 10