Linux

讓mysql共享所有cpu

  • April 29, 2015

我對 linux 伺服器非常陌生。我正在使用 centos。有時我的 cpu 會因為程序 mysqld 超過 100% 而過載

PID   USER   PR    NI    VIRT    RES    SHR S    %CPU %MEM    TIME+  COMMAND
2221    mysql  20     0     2810m   797m  5648 S   99.3  5.0  262:15.91   mysqld

所以為了調試,我在 ssh 中執行了top命令,結果如下

Cpu(s):  2.9%us,  2.3%sy,  0.0%ni, 94.7%id,  0.0%wa,  0.0%hi,  0.1%si,  0.0%st
Mem:  16291440k total, 14893024k used,  1398416k free,  1673232k buffers
Swap: 16433144k total,    30168k used, 16402976k free, 10713048k cached

我對此一無所知,但我明白了,只有一個 CPU(94.7%id)被大量使用,其他 CPU 是空閒的。如何讓 mysql 共享更多的 cpu 並減少負載。

第 3 行:top命令中表示cpu 是如何使用的。分別了解每一項

% of the CPU for user processes (2.9%us)
% of the CPU for system processes (2.3%sy)
% of the CPU processes with priority upgrade nice (0.0%ni)
% of the CPU not used (94.7%id)
% of the CPU processes waiting for I/O operations(0.0%wa)
% of the CPU serving hardware interrupts (0.0% hi)
% of the CPU serving software interrupts (0.1% si)

**第 4 行和第 5 行:**提供 RAM(物理記憶體)和 SWAP 詳細資訊。


這顯示了程序列表

%CPU – % of CPU used by this process (99.3)
%MEM – % of RAM used by the process (5.0)

對於 CPU 分配,請參閱

https://stackoverflow.com/questions/14787046/how-to-allocate-more-cpu-and-ram-to-a-c-program-in-linux

https://askubuntu.com/questions/115478/how-do-i-assign-different-cpu-cores-to-different-processes

引用自:https://serverfault.com/questions/686388