LinuxÐÔÄÜÓÅ»¯ÖªÊ¶µã×ܽá´óÈ« ¡¤ ʵ¼ù+Õä²Ø°æ
Part1LinuxÐÔÄÜÓÅ»¯
1ÐÔÄÜÓÅ»¯
ÐÔÄÜÖ¸±ê
¸ß²¢·¢ºÍÏìÓ¦¿ì¶ÔÓ¦×ÅÐÔÄÜÓÅ»¯µÄÁ½¸ö½¹µãÖ¸±ê£ºÍÌͺÍÑÓʱ
ͼƬÀ´×Ô: www.ctq6.cn
Ó¦ÓøºÔؽǶȣºÖ±½ÓÓ°ÏìÁ˲úÆ·Öն˵ÄÓû§ÌåÑé
ϵͳ×ÊÔ´½Ç¶È£º×ÊԴʹÓÃÂÊ¡¢±¥ºÍ¶ÈµÈ
ÐÔÄÜÎÊÌâµÄʵÖʾÍÊÇϵͳ×ÊÔ´ÒѾµÖ´ïÆ¿¾±£¬µ«ÇëÇóµÄ´¦Àí»¹²»·ó¿ì£¬ÎÞ·¨Ö§³Ö¸ü¶àµÄÇëÇó¡£ÐÔÄÜÆÊÎöÏÖʵÉϾÍÊÇÕÒ³öÓ¦ÓûòϵͳµÄÆ¿¾±£¬Ï뷨ȥ×èÖ¹»ò»º½âËüÃÇ¡£
Ñ¡ÔñÖ¸±êÆÀ¹ÀÓ¦ÓóÌÐòºÍϵͳÐÔÄÜ
ΪӦÓóÌÐòºÍϵͳÉèÖÃÐÔÄÜÄ¿µÄ
¾ÙÐÐÐÔÄÜ»ù×¼²âÊÔ
ÐÔÄÜÆÊÎö¶¨Î»Æ¿¾±
ÐÔÄܼà¿ØºÍ¸æ¾¯
¹ØÓÚ²î±ðµÄÐÔÄÜÎÊÌâҪѡȡ²î±ðµÄÐÔÄÜÆÊÎö¹¤¾ß¡£ÏÂÃæÊdz£ÓõÄLinux Performance ToolsÒÔ¼°¶ÔÓ¦ÆÊÎöµÄÐÔÄÜÎÊÌâÀàÐÍ¡£
ͼƬÀ´×Ô: www.ctq6.cn
¾¿¾¹Ó¦¸ÃÔõôÃ÷È·”ƽ¾ù¸ºÔØ”
ƽ¾ù¸ºÔØ£ºµ¥Î»Ê±¼äÄÚ£¬ÏµÍ³´¦ÓÚ¿ÉÔËÐÐ״̬ºÍ²»¿ÉÖÐֹ״̬µÄƽ¾ùÀú³ÌÊý£¬Ò²¾ÍÊÇƽ¾ù»îÔ¾Àú³ÌÊý¡£ËüºÍÎÒÃǹŰåÒâÒåÉÏÃ÷È·µÄCPUʹÓÃÂʲ¢Ã»ÓÐÖ±½Ó¹Øϵ¡£
ÆäÖв»¿ÉÖÐÖ¹Àú³ÌÊÇÕý´¦ÓÚÄÚºË̬Ҫº¦Á÷³ÌÖеÄÀú³Ì£¨Èç³£¼ûµÄÆÚ´ý×°±¸µÄI/OÏìÓ¦£©¡£²»¿ÉÖÐֹ״̬ÏÖʵÉÏÊÇϵͳ¶ÔÀú³ÌºÍÓ²¼þ×°±¸µÄÒ»ÖÖ±£»¤»úÖÆ¡£
ƽ¾ù¸ºÔؼ¸¶àʱºÏÀí
ÏÖʵÉú²úÇéÐÎÖн«ÏµÍ³µÄƽ¾ù¸ºÔؼà¿ØÆðÀ´£¬Æ¾Ö¤ÀúÊ·Êý¾ÝÅжϸºÔصÄת±äÇ÷ÊÆ¡£µ±¸ºÔر£´æÏÔ×ÅÉý¸ßÇ÷ÊÆʱ£¬ÊµÊ±¾ÙÐÐÆÊÎöºÍÊӲ졣ËäȻҲ¿ÉÒÔµ±ÉèÖÃãÐÖµ£¨È統ƽ¾ù¸ºÔظßÓÚCPUÊýÄ¿µÄ70%ʱ£©
ÏÖʵÊÂÇéÖÐÎÒÃǻᾳ£»ìÏýƽ¾ù¸ºÔغÍCPUʹÓÃÂʵĿ´·¨£¬×ÅʵÁ½Õß²¢²»ÍêÈ«¶ÔµÈ£º
CPU÷缯ÐÍÀú³Ì£¬´ó×ÚCPUʹÓûᵼÖÂƽ¾ù¸ºÔØÉý¸ß£¬´ËʱÁ½ÕßÒ»ÖÂ
I/O÷缯ÐÍÀú³Ì£¬ÆÚ´ýI/OÒ²»áµ¼ÖÂƽ¾ù¸ºÔØÉý¸ß£¬´ËʱCPUʹÓÃÂʲ¢·×Æ綨¸ß
´ó×ÚÆÚ´ýCPUµÄÀú³Ìµ÷Àí»áµ¼ÖÂƽ¾ù¸ºÔØÉý¸ß£¬´ËʱCPUʹÓÃÂÊÒ²»á½ÏÁ¿¸ß
ƽ¾ù¸ºÔظßʱ¿ÉÄÜÊÇCPU÷缯ÐÍÀú³Ìµ¼Ö£¬Ò²¿ÉÄÜÊÇI/Oæµµ¼Ö¡£ÏêϸÆÊÎöʱ¿ÉÒÔÍŽámpstat/pidstat¹¤¾ß¸¨ÖúÆÊÎö¸ºÔØȪԴ
2CPU
CPUÉÏÏÂÎÄÇл»(ÉÏ)
CPUÉÏÏÂÎÄÇл»£¬¾ÍÊÇ°ÑÇ°Ò»¸öʹÃüµÄCPUÉÏÏÂÎÄ£¨CPU¼Ä´æÆ÷ºÍPC£©ÉúÑÄÆðÀ´£¬È»ºó¼ÓÔØÐÂʹÃüµÄÉÏÏÂÎĵ½ÕâЩ¼Ä´æÆ÷ºÍ³ÌÐò¼ÆÊýÆ÷£¬×îºóÔÙÌøתµ½³ÌÐò¼ÆÊýÆ÷ËùÖ¸µÄλÖã¬ÔËÐÐÐÂʹÃü¡£ÆäÖУ¬ÉúÑÄÏÂÀ´µÄÉÏÏÂÎÄ»á´æ´¢ÔÚϵͳÄÚºËÖУ¬´ýʹÃüÖØе÷ÀíÖ´ÐÐʱÔÙ¼ÓÔØ£¬°ü¹ÜÔÀ´µÄʹÃü״̬²»ÊÜÓ°Ïì¡£¹Ø×¢LinuxÖÐÎÄÉçÇø
ƾ֤ʹÃüÀàÐÍ£¬CPUÉÏÏÂÎÄÇл»·ÖΪ£º
Àú³ÌÉÏÏÂÎÄÇл»
Ïß³ÌÉÏÏÂÎÄÇл»
ÖÐÖ¹ÉÏÏÂÎÄÇл»
Àú³ÌÉÏÏÂÎÄÇл»
LinuxÀú³Ìƾ֤Ʒ¼¶È¨ÏÞ½«Àú³ÌµÄÔËÐпռä·ÖΪÄں˿ռäºÍÓû§¿Õ¼ä¡£´ÓÓû§Ì¬ÏòÄÚºË̬ת±äʱÐèҪͨ¹ýϵͳŲÓÃÀ´Íê³É¡£
Ò»´ÎϵͳŲÓÃÀú³Ì×Åʵ¾ÙÐÐÁËÁ½´ÎCPUÉÏÏÂÎÄÇл»£º
CPU¼Ä´æÆ÷ÖÐÓû§Ì¬µÄÖ¸ÁîλÖÃÏÈÉúÑÄÆðÀ´£¬CPU¼Ä´æÆ÷¸üÐÂΪÄÚºËָ̬ÁîµÄλÖã¬Ìøתµ½ÄÚºË̬ÔËÐÐÄÚºËʹÃü£»
ϵͳŲÓÿ¢Êºó£¬CPU¼Ä´æÆ÷»Ö»Ø¸´À´ÉúÑĵÄÓû§Ì¬Êý¾Ý£¬ÔÙÇл»µ½Óû§¿Õ¼ä¼ÌÐøÔËÐС£
ϵͳŲÓÃÀú³ÌÖв¢²»»áÉæ¼°ÐéÄâÄÚ´æµÈÀú³ÌÓû§Ì¬×ÊÔ´£¬Ò²²»»áÇл»Àú³Ì¡£ºÍ¹Å°åÒâÒåÉϵÄÀú³ÌÉÏÏÂÎÄÇл»²î±ð¡£Òò´ËϵͳŲÓÃͨ³£³ÆΪÌØȨģʽÇл»¡£
Àú³ÌÊÇÓÉÄÚºËÖÎÀíºÍµ÷ÀíµÄ£¬Àú³ÌÉÏÏÂÎÄÇл»Ö»Äܱ¬·¢ÔÚÄÚºË̬¡£Òò´ËÏà±ÈϵͳŲÓÃÀ´Ëµ£¬ÔÚÉúÑÄÄ¿½ñÀú³ÌµÄÄÚºË״̬ºÍCPU¼Ä´æÆ÷֮ǰ£¬ÐèÒªÏȰѸÃÀú³ÌµÄÐéÄâÄڴ棬ջÉúÑÄÏÂÀ´¡£ÔÙ¼ÓÔØÐÂÀú³ÌµÄÄÚºË̬ºó£¬»¹ÒªË¢ÐÂÀú³ÌµÄÐéÄâÄÚ´æºÍÓû§Õ»¡£
Àú³ÌÖ»ÓÐÔÚµ÷Àíµ½CPUÉÏÔËÐÐʱ²ÅÐèÒªÇл»ÉÏÏÂÎÄ£¬ÓÐÒÔϼ¸ÖÖ³¡¾°£ºCPUʱ¼äƬÂÖÁ÷·ÖÅÉ£¬ÏµÍ³×ÊԴȱ·¦µ¼ÖÂÀú³Ì¹ÒÆð£¬Àú³Ìͨ¹ýsleepº¯Êý×Ô¶¯¹ÒÆ𣬸ßÓÅÏȼ¶Àú³ÌÇÀռʱ¼äƬ£¬Ó²¼þÖÐֹʱCPUÉϵÄÀú³Ì±»¹ÒÆðת¶øÖ´ÐÐÄÚºËÖеÄÖÐֹЧÀÍ¡£
Ïß³ÌÉÏÏÂÎÄÇл»
Ïß³ÌÉÏÏÂÎÄÇл»·ÖΪÁ½ÖÖ£º
Ç°ºóÏß³ÌͬÊôÓÚÒ»¸öÀú³Ì£¬Çл»Ê±ÐéÄâÄÚ´æ×ÊÔ´Îȹ̣¬Ö»ÐèÒªÇл»Ï̵߳Ä˽ÓÐÊý¾Ý£¬¼Ä´æÆ÷µÈ£»
Ç°ºóÏß³ÌÊôÓÚ²î±ðÀú³Ì£¬ÓëÀú³ÌÉÏÏÂÎÄÇл»Ïàͬ¡£
ͬÀú³ÌµÄÏß³ÌÇл»ÏûºÄ×ÊÔ´½ÏÉÙ£¬ÕâÒ²ÊǶàÏ̵߳ÄÓÅÊÆ¡£
ÖÐÖ¹ÉÏÏÂÎÄÇл»
ÖÐÖ¹ÉÏÏÂÎÄÇл»²¢²»Éæ¼°µ½Àú³ÌµÄÓû§Ì¬£¬ÒòÆäÖÐÖ¹ÉÏÏÂÎÄÖ»°üÀ¨ÄÚºË̬ÖÐֹЧÀͳÌÐòÖ´ÐÐËù±ØÐèµÄ״̬£¨CPU¼Ä´æÆ÷£¬Äں˿ÍÕ»£¬Ó²¼þÖÐÖ¹²ÎÊýµÈ£©¡£
ÖÐÖ¹´¦ÀíÓÅÏȼ¶±ÈÀú³Ì¸ß£¬ÒÔÊÇÖÐÖ¹ÉÏÏÂÎÄÇл»ºÍÀú³ÌÉÏÏÂÎÄÇл»²»»áͬʱ±¬·¢
CPUÉÏÏÂÎÄÇл»(ÏÂ)
ͨ¹ývmstat¿ÉÒÔÉó²éϵͳ×ÜÌåµÄÉÏÏÂÎÄÇл»ÇéÐÎ
vmstat 5 #ÿ¸ô5sÊä³öÒ»×éÊý¾Ý procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu----- r b swpd free buff cache si so bi bo in cs us sy id wa st 1 0 0 103388 145412 511056 0 0 18 60 1 1 2 1 96 0 0 0 0 0 103388 145412 511076 0 0 0 2 450 1176 1 1 99 0 0 0 0 0 103388 145412 511076 0 0 0 8 429 1135 1 1 98 0 0 0 0 0 103388 145412 511076 0 0 0 0 431 1132 1 1 98 0 0 0 0 0 103388 145412 511076 0 0 0 10 467 1195 1 1 98 0 0 1 0 0 103388 145412 511076 0 0 0 2 426 1139 1 0 99 0 0 4 0 0 95184 145412 511108 0 0 0 74 500 1228 4 1 94 0 0 0 0 0 103512 145416 511076 0 0 0 455 723 1573 12 3 83 2 0
µÇ¼ºó¸´ÖÆ
cs £¨context switch£© ÿÃëÉÏÏÂÎÄÇл»´ÎÊý
in £¨interrupt£© ÿÃëÖÐÖ¹´ÎÊý
r £¨runnning or runnable£©Í£µ±ÐÐÁеij¤¶È£¬ÕýÔÚÔËÐкÍÆÚ´ýCPUµÄÀú³ÌÊý
b £¨Blocked£© ´¦ÓÚ²»¿ÉÖÐֹ˯Ãß״̬µÄÀú³ÌÊý
ÒªÉó²éÿ¸öÀú³ÌµÄÏêϸÇéÐΣ¬ÐèҪʹÓÃpidstatÀ´Éó²éÿ¸öÀú³ÌÉÏÏÂÎÄÇл»ÇéÐÎ
pidstat -w 5 14ʱ51·Ö16Ãë UID PID cswch/s nvcswch/s Command 14ʱ51·Ö21Ãë 0 1 0.80 0.00 systemd 14ʱ51·Ö21Ãë 0 6 1.40 0.00 ksoftirqd/0 14ʱ51·Ö21Ãë 0 9 32.67 0.00 rcu_sched 14ʱ51·Ö21Ãë 0 11 0.40 0.00 watchdog/0 14ʱ51·Ö21Ãë 0 32 0.20 0.00 khugepaged 14ʱ51·Ö21Ãë 0 271 0.20 0.00 jbd2/vda1-8 14ʱ51·Ö21Ãë 0 1332 0.20 0.00 argusagent 14ʱ51·Ö21Ãë 0 5265 10.02 0.00 AliSecGuard 14ʱ51·Ö21Ãë 0 7439 7.82 0.00 kworker/0:2 14ʱ51·Ö21Ãë 0 7906 0.20 0.00 pidstat 14ʱ51·Ö21Ãë 0 8346 0.20 0.00 sshd 14ʱ51·Ö21Ãë 0 20654 9.82 0.00 AliYunDun 14ʱ51·Ö21Ãë 0 25766 0.20 0.00 kworker/u2:1 14ʱ51·Ö21Ãë 0 28603 1.00 0.00 python3
µÇ¼ºó¸´ÖÆ
cswch ÿÃë×ÔÔ¸ÉÏÏÂÎÄÇл»´ÎÊý £¨Àú³ÌÎÞ·¨»ñÈ¡ËùÐè×ÊÔ´µ¼ÖµÄÉÏÏÂÎÄÇл»£©
nvcswch ÿÃë·Ç×ÔÔ¸ÉÏÏÂÎÄÇл»´ÎÊý £¨Ê±¼äƬÂÖÁ÷µÈϵͳǿÖƵ÷Àí£©
vmstat 1 1 #Ê×ÏÈ»ñÈ¡¿ÕÏÐϵͳµÄÉÏÏÂÎÄÇл»´ÎÊý sysbench --threads=10 --max-time=300 threads run #Ä£Äâ¶àÏß³ÌÇл»ÎÊÌâ vmstat 1 1 #ÐÂÖÕ¶ËÊÓ²ìÉÏÏÂÎÄÇл»ÇéÐÎ ´Ëʱ·¢Ã÷csÊý¾ÝÏÔ×ÅÉý¸ß£¬Í¬Ê±ÊÓ²ìÆäËûÖ¸±ê£º rÁУº Ô¶³¬ÏµÍ³CPU¸öÊý£¬ËµÃ÷±£´æ´ó×ÚCPU¾ºÕù usºÍsyÁУºsyÁÐÕ¼±È80%£¬ËµÃ÷CPUÖ÷Òª±»ÄÚºËÕ¼Óà inÁУº ÖÐÖ¹´ÎÊýÏÔ×ÅÉÏÉý£¬ËµÃ÷ÖÐÖ¹´¦ÀíÒ²ÊÇDZÔÚÎÊÌâ
µÇ¼ºó¸´ÖÆ
˵Ã÷ÔËÐÐ/ÆÚ´ýCPUµÄÀú³Ì¹ý¶à£¬µ¼Ö´ó×ÚµÄÉÏÏÂÎÄÇл»£¬ÉÏÏÂÎÄÇл»µ¼ÖÂϵͳµÄCPUÕ¼ÓÃÂʸß
pidstat -w -u 1 #Éó²é¾¿¾¹ÄĸöÀú³Ìµ¼ÖµÄÎÊÌâ
µÇ¼ºó¸´ÖÆ
´ÓЧ¹ûÖп´³öÊÇsysbenchµ¼ÖÂCPUʹÓÃÂʹý¸ß£¬¿ÉÊÇpidstatÊä³öµÄÉÏÏÂÎÄ´ÎÊý¼ÓÆðÀ´Ò²²¢Î´¼¸¡£ÆÊÎösysbenchÄ£ÄâµÄÊÇÏ̵߳ÄÇл»£¬Òò´ËÐèÒªÔÚpidstatºó¼Ó-t²ÎÊýÉó²éÏß³ÌÖ¸±ê¡£
ÁíÍâ¹ØÓÚÖÐÖ¹´ÎÊý¹ý¶à£¬ÎÒÃÇ¿ÉÒÔͨ¹ý/proc/interruptsÎļþ¶ÁÈ¡
watch -d cat /proc/interrupts
µÇ¼ºó¸´ÖÆ
·¢Ã÷´ÎÊýת±äËÙÂÊ×î¿ìµÄÊÇÖص÷ÀíÖÐÖ¹£¨RES£©£¬¸ÃÖÐÖ¹ÓÃÀ´½ÐÐÑ¿ÕÏÐ״̬µÄCPUÀ´µ÷ÀíеÄʹÃüÔËÐС£ÆÊÎöÕÕ¾ÉÓÉÓÚ¹ý¶àʹÃüµÄµ÷ÀíÎÊÌ⣬ºÍÉÏÏÂÎÄÇл»ÆÊÎöÒ»Ö¡£
ij¸öÓ¦ÓõÄCPUʹÓÃÂʵִï100%£¬Ôõô°ì£¿
Linux×÷Ϊ¶àʹÃü²Ù×÷ϵͳ£¬½«CPUʱ¼ä»®·ÖΪºÜ¶ÌµÄʱ¼äƬ£¬Í¨¹ýµ÷ÀíÆ÷ÂÖÁ÷·ÖÅɸø¸÷¸öʹÃüʹÓá£ÎªÁËά»¤CPUʱ¼ä£¬Linuxͨ¹ýÊÂÏȽç˵µÄ½Ú×àÂÊ£¬´¥·¢Ê±¼äÖÐÖ¹£¬²¢Ê¹ÓÃÈ«¾Ö±äÁËjiffies¼Í¼¿ª»úÒÔÀ´µÄ½Ú×àÊý¡£Ê±¼äÖÐÖ¹±¬·¢Ò»´Î¸ÃÖµ+1.
CPUʹÓÃÂÊ£¬³ýÁË¿ÕÏÐʱ¼äÒÔÍâµÄÆäËûʱ¼äÕ¼×ÜCPUʱ¼äµÄ°Ù·Ö±È¡£¿ÉÒÔͨ¹ý/proc/statÖеÄÊý¾ÝÀ´ÅÌËã³öCPUʹÓÃÂÊ¡£ÓÉÓÚ/proc/statʱ¿ª»úÒÔÀ´µÄ½Ú×àÊýÀÛ¼ÓÖµ£¬ÅÌËã³öÀ´µÄÊÇ¿ª»úÒÔÀ´µÄƽ¾ùCPUʹÓÃÂÊ£¬Ò»Ñùƽ³£ÒâÒå²»´ó¡£¿ÉÒÔ¾àÀëÈ¡Ò»¶Îʱ¼äµÄÁ½´ÎÖµ×÷²îÀ´ÅÌËã¸Ã¶Îʱ¼äÄÚµÄƽ¾ùCPUʹÓÃÂÊ¡£ÐÔÄÜÆÊÎö¹¤¾ß¸ø³öµÄ¶¼ÊǾàÀëÒ»¶Îʱ¼äµÄƽ¾ùCPUʹÓÃÂÊ£¬Òª×¢ÖؾàÀëʱ¼äµÄÉèÖá£
CPUʹÓÃÂÊ¿ÉÒÔͨ¹ýtop »ò psÀ´Éó²é¡£ÆÊÎöÀú³ÌµÄCPUÎÊÌâ¿ÉÒÔͨ¹ýperf£¬ËüÒÔÐÔÄÜÊÂÎñ²ÉÑùΪ»ù´¡£¬²»µ«¿ÉÒÔÆÊÎöϵͳµÄÖÖÖÖÊÂÎñºÍÄÚºËÐÔÄÜ£¬»¹¿ÉÒÔÓÃÀ´ÆÊÎöÖ¸¶¨Ó¦ÓóÌÐòµÄÐÔÄÜÎÊÌâ¡£
perf top / perf record / perf report £¨-g ¿ªÆôŲÓùØϵµÄ²ÉÑù£©
sudo docker run --name nginx -p 10000:80 -itd feisky/nginx sudo docker run --name phpfpm -itd --network container:nginx feisky/php-fpm ab -c 10 -n 100 http://XXX.XXX.XXX.XXX:10000/ #²âÊÔNginxЧÀÍÐÔÄÜ
µÇ¼ºó¸´ÖÆ
·¢Ã÷´ËʱÿÃë¿ÉÔâÊÜÇëÇó¸ø³¤ÉÙ£¬´Ëʱ½«²âÊÔµÄÇëÇóÊý´Ó100ÔöÌíµ½10000¡£ÔÚÁíÍâÒ»¸öÖÕ¶ËÔËÐÐtopÉó²éÿ¸öCPUµÄʹÓÃÂÊ¡£·¢Ã÷ϵͳÖм¸¸öphp-fpmÀú³Ìµ¼ÖÂCPUʹÓÃÂÊÖèÉý¡£
½Ó×ÅÓÃperfÀ´ÆÊÎöÏêϸÊÇphp-fpmÖÐÄĸöº¯Êýµ¼Ö¸ÃÎÊÌâ¡£
perf top -g -p XXXX #¶Ôijһ¸öphp-fpmÀú³Ì¾ÙÐÐÆÊÎö
µÇ¼ºó¸´ÖÆ
·¢Ã÷ÆäÖÐsqrtºÍadd_functionÕ¼ÓÃCPU¹ý¶à£¬ ´ËʱÉó²éÔ´ÂëÕÒµ½ÔÀ´ÊÇsqrtÖÐÔÚÐû²¼Ç°Ã»ÓÐɾ³ý²âÊÔ´úÂë¶Î£¬±£´æÒ»¸ö°ÙÍò´ÎµÄÑ»·µ¼Ö¡£½«¸ÃÎÞÓôúÂëɾ³ýºó·¢Ã÷nginx¸ºÔØÄÜÁ¦ÏÔ×ÅÌáÉý
ϵͳµÄCPUʹÓÃÂʺܸߣ¬ÎªÊ²Ã´ÕÒ²»µ½¸ßCPUµÄÓ¦Óã¿
sudo docker run --name nginx -p 10000:80 -itd feisky/nginx:sp sudo docker run --name phpfpm -itd --network container:nginx feisky/php-fpm:sp ab -c 100 -n 1000 http://XXX.XXX.XXX.XXX:10000/ #²¢·¢100¸öÇëÇó²âÊÔ
µÇ¼ºó¸´ÖÆ
ʵÑéЧ¹ûÖÐÿÃëÇëÇóÊýÒÀ¾É²»¸ß£¬ÎÒÃǽ«²¢·¢ÇëÇóÊý½µÎª5ºó£¬nginx¸ºÔØÄÜÁ¦ÒÀ¾ÉºÜµÍ¡£
´ËʱÓÃtopºÍpidstat·¢Ã÷ϵͳCPUʹÓÃÂʹý¸ß£¬¿ÉÊDz¢Ã»Óз¢Ã÷CPUʹÓÃÂʸߵÄÀú³Ì¡£
·ºÆðÕâÖÖÇéÐÎÒ»Ñùƽ³£Ê±ÎÒÃÇÆÊÎöʱÒÅ©µÄʲôÐÅÏ¢£¬ÖØÐÂÔËÐÐtopÏÂÁî²¢ÊÓ²ìÒ»»á¡£·¢Ã÷Í£µ±ÐÐÁÐÖд¦ÓÚRunning״̬µÄ¾ÙÐйý¶à£¬Áè¼ÝÁËÎÒÃǵIJ¢·¢ÇëÇó´ÎÊý5. ÔÙ×ÐϸÉó²éÀú³ÌÔËÐÐÊý¾Ý£¬·¢Ã÷nginxºÍphp-fpm¶¼´¦ÓÚsleep״̬£¬ÕæÕý´¦ÓÚÔËÐеÄÈ´ÊǼ¸¸östressÀú³Ì¡£
ÏÂÒ»²½¾ÍʹÓÃpidstatÆÊÎöÕ⼸¸östressÀú³Ì£¬·¢Ã÷ûÓÐÈκÎÊä³ö¡£ÓÃps aux½»Ö¯ÑéÖ¤·¢Ã÷ÒÀ¾É²»±£´æ¸ÃÀú³Ì¡£ËµÃ÷²»Êǹ¤¾ßµÄÎÊÌâ¡£ÔÙtopÉó²é·¢Ã÷stressÀú³ÌµÄÀú³ÌºÅת±äÁË£¬´ËʱÓпÉÄÜʱÒÔÏÂÁ½ÖÖÔµ¹ÊÔÓɵ¼Ö£º
Àú³ÌÒ»Ö±µÄÍß½âÖØÆô£¨Èç¶Î¹ýʧ/ÉèÖùýʧµÈ£©£¬´ËʱÀú³ÌÍ˳öºó¿ÉÄÜÓÖ±»¼à¿ØϵͳÖØÆô£»
¶ÌʱÀú³Ìµ¼Ö£¬¼´ÆäËûÓ¦ÓÃÄÚ²¿Í¨¹ýexecŲÓõÄÍâÃæÏÂÁÕâЩÏÂÁîÒ»Ñùƽ³£Ö»ÔËÐкܶÌʱ¼ä¾Í¿¢Ê£¬ºÜÄÑÓÃtopÕâÖÖ¾àÀë½Ï³¤µÄ¹¤¾ßÀ´·¢Ã÷
¿ÉÒÔͨ¹ýpstreeÀ´²éÕÒ stressµÄ¸¸Àú³Ì£¬ÕÒ³öŲÓùØϵ¡£
pstree | grep stress
µÇ¼ºó¸´ÖÆ
·¢Ã÷ÊÇphp-fpmŲÓõĸÃ×ÓÀú³Ì£¬´ËʱȥÉó²éÔ´Âë¿ÉÒÔ¿´³öÿ¸öÇëÇ󶼻áŲÓÃÒ»¸östressÏÂÁîÀ´Ä£ÄâI/OѹÁ¦¡£Ö®Ç°topÏÔʾµÄЧ¹ûÊÇCPUʹÓÃÂÊÉý¸ß£¬ÊÇ·ñÕæµÄÊÇÓɸÃstressÏÂÁîµ¼Öµģ¬»¹ÐèÒª¼ÌÐøÆÊÎö¡£´úÂëÖиøÿ¸öÇëÇó¼ÓÁËverbose=1µÄ²ÎÊýºó¿ÉÒÔÉó²éstressÏÂÁîµÄÊä³ö£¬ÔÚÖÐÖ¹²âÊÔ¸ÃÏÂÁîЧ¹ûÏÔʾstressÏÂÁîÔËÐÐʱ±£´æÒòȨÏÞÎÊÌâµ¼ÖµÄÎļþ½¨Éèʧ°ÜµÄbug¡£
´ËʱÒÀ¾ÉÖ»ÊÇÍƲ⣬ÏÂÒ»²½¼ÌÐøͨ¹ýperf¹¤¾ßÀ´ÆÊÎö¡£ÐÔÄܱ¨¸æÏÔʾȷʵʱstressÕ¼ÓÃÁË´ó×ÚµÄCPU£¬Í¨¹ýÐÞ¸´È¨ÏÞÎÊÌâÀ´ÓÅ»¯½â¾ö¼´¿É.
ϵͳÖзºÆð´ó×Ú²»¿ÉÖÐÖ¹Àú³ÌºÍ½©Ê¬Àú³ÌÔõô°ì£¿
Àú³Ì״̬
R Running/Runnable£¬ÌåÏÖÀú³ÌÔÚCPUµÄÍ£µ±ÐÐÁÐÖУ¬ÕýÔÚÔËÐлòÕßÆÚ´ýÔËÐУ»
D Disk Sleep£¬²»¿ÉÖÐֹ״̬˯Ãߣ¬Ò»Ñùƽ³£ÌåÏÖÀú³ÌÕýÔÚ¸úÓ²¼þ½»»¥£¬²¢ÇÒ½»»¥Àú³ÌÖв»ÔÊÐí±»ÆäËûÀú³ÌÖÐÖ¹£»
Z Zombie£¬½©Ê¬Àú³Ì£¬ÌåÏÖÀú³ÌÏÖʵÉÏÒѾ¿¢Ê£¬¿ÉÊǸ¸Àú³Ì»¹Ã»ÓнÓÄÉËüµÄ×ÊÔ´£»
S Interruptible Sleep£¬¿ÉÖÐֹ˯Ãß״̬£¬ÌåÏÖÀú³ÌÓÉÓÚÆÚ´ýij¸öÊÂÎñ¶ø±»ÏµÍ³¹ÒÆ𣬵±ÆÚ´ýÊÂÎñ±¬·¢Ôò»á±»½ÐÐѲ¢½øÈëR״̬£»
I Idle£¬¿ÕÏÐ״̬£¬ÓÃÔÚ²»¿ÉÖÐֹ˯ÃßµÄÄÚºËÏß³ÌÉÏ¡£¸Ã״̬²»»áµ¼ÖÂƽ¾ù¸ºÔØÉý¸ß£»
T Stop/Traced£¬ÌåÏÖÀú³Ì´¦ÓÚÔÝÍ£»ò¸ú×Ù״̬£¨SIGSTOP/SIGCONT£¬ GDBµ÷ÊÔ£©£»
X Dead£¬Àú³ÌÒѾÏûÍö£¬²»»áÔÚtop/psÖп´µ½¡£
¹ØÓÚ²»¿ÉÖÐֹ״̬£¬Ò»Ñùƽ³£¶¼ÊÇÔںܶÌʱ¼äÄÚ¿¢Ê£¬¿ÉºöÂÔ¡£¿ÉÊÇÈôÊÇϵͳ»òÓ²¼þ±¬·¢¹ÊÕÏ£¬Àú³Ì¿ÉÄÜ»á¼á³Ö²»¿ÉÖÐֹ״̬Á¼¾Ã£¬ÉõÖÁϵͳÖзºÆð´ó×Ú²»¿ÉÖÐֹ״̬£¬´ËʱÐè×¢ÖØÊÇ·ñ·ºÆðÁËI/OÐÔÄÜÎÊÌâ¡£
½©Ê¬Àú³ÌÒ»Ñùƽ³£¶àÀú³ÌÓ¦ÓÃÈÝÒ×Óöµ½£¬¸¸Àú³ÌÀ´È±·¦´¦Àí×ÓÀú³Ì״̬ʱ×ÓÀú³Ì¾ÍÌáÇ°Í˳ö£¬´Ëʱ×ÓÀú³Ì¾ÍÄð³ÉÁ˽©Ê¬Àú³Ì¡£´ó×ڵĽ©Ê¬Àú³Ì»áÓþ¡PIDÀú³ÌºÅ£¬µ¼ÖÂÐÂÀú³ÌÎÞ·¨½¨Éè¡£
´ÅÅÌO_DIRECTÎÊÌâ
sudo docker run --privileged --name=app -itd feisky/app:iowait ps aux | grep '/app'
µÇ¼ºó¸´ÖÆ
¿ÉÒÔ¿´µ½´ËʱÓжà¸öappÀú³ÌÔËÐУ¬×´Ì¬»®·ÖʱSs+ºÍD+¡£ÆäÖкóÃæsÌåÏÖÀú³ÌÊÇÒ»¸ö»á»°µÄÏòµ¼Àú³Ì£¬+ºÅÌåÏÖǰ̨Àú³Ì×é¡£
ÆäÖÐÀú³Ì×éÌåÏÖÒ»×éÏ໥¹ØÁªµÄÀú³Ì£¬×ÓÀú³ÌÊǸ¸Àú³ÌËùÔÚ×éµÄ×éÔ±¡£»á»°Ö¸¹²Ïíͳһ¸ö¿ØÖÆÖն˵ÄÒ»¸ö»ò¶à¸öÀú³Ì×é¡£
ÓÃtopÉó²éϵͳ×ÊÔ´·¢Ã÷£º1£©Æ½¾ù¸ºÔØÔÚÖð½¥ÔöÌí£¬ÇÒ1·ÖÖÓÄÚƽ¾ù¸ºÔصִïÁËCPU¸öÊý£¬ËµÃ÷ϵͳ¿ÉÄÜÒѾÓÐÁËÐÔÄÜÆ¿¾±£»2£©½©Ê¬Àú³Ì½ÏÁ¿¶àÇÒÔÚÒ»Ö±ÔöÌí£»3£©usºÍsys CPUʹÓÃÂʶ¼²»¸ß£¬iowaitÈ´½ÏÁ¿¸ß£»4£©Ã¿¸öÀú³ÌCPUʹÓÃÂÊÒ²²»¸ß£¬µ«ÓÐÁ½¸öÀú³Ì´¦ÓÚD״̬£¬¿ÉÄÜÔÚÆÚ´ýIO¡£
ÆÊÎöÏÖÔÚÊý¾Ý¿ÉÖª£ºiowait¹ý¸ßµ¼ÖÂϵͳƽ¾ù¸ºÔØÉý¸ß£¬½©Ê¬Àú³ÌÒ»Ö±ÔöÌí˵Ã÷ÓгÌÐòûÄÜ׼ȷÕûÀí×ÓÀú³Ì×ÊÔ´¡£
ÓÃdstatÀ´ÆÊÎö£¬ÓÉÓÚËü¿ÉÒÔͬʱÉó²éCPUºÍI/OÁ½ÖÖ×ÊÔ´µÄʹÓÃÇéÐΣ¬±ãÓÚ±ÈÕÕÆÊÎö¡£
dstat 1 10 #¾àÀë1ÃëÊä³ö10×éÊý¾Ý
µÇ¼ºó¸´ÖÆ
¿ÉÒÔ¿´µ½µ±wai£¨iowait£©Éý¸ßʱ´ÅÅÌÇëÇóread¶¼»áºÜ´ó£¬ËµÃ÷iowaitµÄÉý¸ßºÍ´ÅÅ̵ĶÁÇëÇóÓйء£½ÓÏÂÀ´ÆÊÎö¾¿¾¹Ê±ÄĸöÀú³ÌÔÚ¶Á´ÅÅÌ¡£
֮ǰtopÉó²éµÄ´¦ÓÚD״̬µÄÀú³ÌºÅ£¬ÓÃpidstat -d -p XXX չʾÀú³ÌµÄI/Oͳ¼ÆÊý¾Ý¡£·¢Ã÷´¦ÓÚD״̬µÄÀú³Ì¶¼Ã»ÓÐÈκζÁд²Ù×÷¡£ÔÚÓÃpidstat -d Éó²éËùÓÐÀú³ÌµÄI/Oͳ¼ÆÊý¾Ý£¬¿´µ½appÀú³ÌÔÚ¾ÙÐдÅÅ̶Á²Ù×÷£¬Ã¿Ãë¶ÁÈ¡32MBµÄÊý¾Ý¡£Àú³Ì»á¼û´ÅÅ̱ØÐèʹÓÃϵͳŲÓô¦ÓÚÄÚºË̬£¬½ÓÏÂÀ´Öصã¾ÍÊÇÕÒµ½appÀú³ÌµÄϵͳŲÓá£
sudo strace -p XXX #¶ÔappÀú³ÌŲÓþÙÐиú×Ù
µÇ¼ºó¸´ÖÆ
±¨´íûÓÐȨÏÞ£¬ÓÉÓÚÒѾʱrootȨÏÞÁË¡£ÒÔÊÇÓöµ½ÕâÖÖÇéÐΣ¬Ê×ÏÈÒª¼ì²éÀú³Ì״̬ÊÇ·ñÕý³£¡£psÏÂÁî²éÕÒ¸ÃÀú³ÌÒѾ´¦ÓÚZ״̬£¬¼´½©Ê¬Àú³Ì¡£
ÕâÖÖÇéÐÎÏÂtop pidstatÖ®ÀàµÄ¹¤¾ßÎÞ·¨¸ø³ö¸ü¶àµÄÐÅÏ¢£¬´ËʱÏñµÚ5ƪһÑù£¬ÓÃperf record -dºÍperf report¾ÙÐÐÆÊÎö£¬Éó²éappÀú³ÌŲÓÃÕ»¡£
¿´µ½appÈ·×Åʵͨ¹ýϵͳŲÓÃsys_read()¶ÁÈ¡Êý¾Ý£¬²¢ÇÒ´Ónew_sync_readºÍblkdev_direct_IO¿´³öÀú³Ìʱ¾ÙÐÐÖ±½Ó¶Á²Ù×÷£¬ÇëÇóÖ±½Ó´Ó´ÅÅ̶Á£¬Ã»ÓÐͨ¹ý»º´æµ¼ÖÂiowaitÉý¸ß¡£
ͨ¹ý²ã²ãÆÊÎöºó£¬root causeÊÇappÄÚ²¿¾ÙÐÐÁË´ÅÅ̵ÄÖ±½ÓI/O¡£È»ºó¶¨Î»µ½Ïêϸ´úÂëλÖþÙÐÐÓÅ»¯¼´¿É¡£
½©Ê¬Àú³Ì
ÉÏÊöÓÅ»¯ºóiowaitÏÔÖøϽµ£¬¿ÉÊǽ©Ê¬Àú³ÌÊýÄ¿ÈÔÈ»ÔÚÔöÌí¡£Ê×ÏÈÒª¶¨Î»½©Ê¬Àú³ÌµÄ¸¸Àú³Ì£¬Í¨¹ýpstree -aps XXX£¬´òÓ¡³ö¸Ã½©Ê¬Àú³ÌµÄŲÓÃÊ÷£¬·¢Ã÷¸¸Àú³Ì¾ÍÊÇappÀú³Ì¡£
Éó²éapp´úÂ룬¿´¿´×ÓÀú³Ì¿¢ÊµĴ¦ÀíÊÇ·ñ׼ȷ£¨ÊÇ·ñŲÓÃwait()/waitpid(),ÓÐûÓÐ×¢²áSIGCHILDÐźŵĴ¦Àíº¯ÊýµÈ£©¡£
Óöµ½iowaitÉý¸ßʱ£¬ÏÈÓÃdstat pidstatµÈ¹¤¾ßÈ·ÈÏÊÇ·ñ±£´æ´ÅÅÌI/OÎÊÌ⣬ÔÙÕÒÊÇÄÄЩÀú³Ìµ¼ÖÂI/O£¬²»¿ÉÓÃstraceÖ±½ÓÆÊÎöÀú³ÌŲÓÃʱ¿ÉÒÔͨ¹ýperf¹¤¾ßÆÊÎö¡£
¹ØÓÚ½©Ê¬ÎÊÌ⣬ÓÃpstreeÕÒµ½¸¸Àú³Ì£¬È»ºó¿´Ô´Âë¼ì²é×ÓÀú³Ì¿¢ÊµĴ¦ÀíÂß¼¼´¿É¡£
CPUÐÔÄÜÖ¸±ê
CPUʹÓÃÂÊ
Óû§CPUʹÓÃÂÊ, °üÀ¨Óû§Ì¬(user)ºÍµÍÓÅÏȼ¶Óû§Ì¬(nice). ¸ÃÖ¸±ê¹ý¸ß˵Ã÷Ó¦ÓóÌÐò½ÏÁ¿Ã¦Âµ.
ϵͳCPUʹÓÃÂÊ, CPUÔÚÄÚºË̬ÔËÐеÄʱ¼ä°Ù·Ö±È(²»º¬ÖÐÖ¹). ¸ÃÖ¸±ê¸ß˵Ã÷Äں˽ÏÁ¿Ã¦Âµ.
ÆÚ´ýI/OµÄCPUʹÓÃÂÊ, iowait, ¸ÃÖ¸±ê¸ß˵Ã÷ϵͳÓëÓ²¼þ×°±¸I/O½»»¥Ê±¼ä½ÏÁ¿³¤.
Èí/Ó²ÖÐÖ¹CPUʹÓÃÂÊ, ¸ÃÖ¸±ê¸ß˵Ã÷ϵͳÖб¬·¢´ó×ÚÖÐÖ¹.
steal CPU / guest CPU, ÌåÏÖÐéÄâ»úÕ¼ÓõÄCPU°Ù·Ö±È.
ƽ¾ù¸ºÔØ
ÀíÏëÇéÐÎÏÂƽ¾ù¸ºÔؼ´ÊÇÂß¼CPU¸öÊý,ÌåÏÖÿ¸öCPU¶¼±»³ä·ÖʹÓÃ. Èô´óÓÚÔò˵Ã÷ϵͳ¸ºÔؽÏÖØ.
Àú³ÌÉÏÏÂÎÄÇл»
°üÀ¨ÎÞ·¨»ñÈ¡×ÊÔ´µÄ×ÔÔ¸Çл»ºÍϵͳǿÖƵ÷ÀíʱµÄ·Ç×ÔÔ¸Çл». ÉÏÏÂÎÄÇл»×Ô¼ºÊÇ°ü¹ÜLinuxÕý³£ÔËÐеÄÒ»Ïî½¹µã¹¦Ð§. ¹ý¶àµÄÇл»Ôò»á½«Ô±¾ÔËÐÐÀú³ÌµÄCPUʱ¼äÏûºÄÔڼĴæÆ÷,ÄÚºËÕ¼¼°ÐéÄâÄÚ´æµÈÊý¾ÝÉúÑĺͻָ´ÉÏ
CPU»º´æÖÀÖÐÂÊ
CPU»º´æµÄ¸´ÓÃÇéÐÎ,ÖÀÖÐÂÊÔ½¸ßÐÔÄÜÔ½ºÃ. ÆäÖÐL1/L2³£ÓÃÔÚµ¥ºË,L3ÔòÓÃÔÚ¶àºËÖÐ
ÐÔÄܹ¤¾ß
ƽ¾ù¸ºÔØ°¸Àý
ÏÈÓÃuptimeÉó²éϵͳƽ¾ù¸ºÔØ
ÅжϸºÔØÔÚÉý¸ßºóÔÙÓÃmpstatºÍpidstat»®·ÖÉó²éÿ¸öCPUºÍÿ¸öÀú³ÌCPUʹÓÃÇéÐÎ.ÕÒ³öµ¼ÖÂƽ¾ù¸ºÔؽϸߵÄÀú³Ì.ÁíÍ⣬ËÑË÷ÃñÖÚºÅLinux¾Í¸ÃÕâÑùѧºǫ́»Ø¸´¡°gitÊé¼®¡±£¬»ñÈ¡Ò»·Ý¾ªÏ²Àñ°ü¡£
ÉÏÏÂÎÄÇл»°¸Àý
ÏÈÓÃvmstatÉó²éϵͳÉÏÏÂÎÄÇл»ºÍÖÐÖ¹´ÎÊý
ÔÙÓÃpidstatÊÓ²ìÀú³ÌµÄ×ÔÔ¸ºÍ·Ç×ÔÔ¸ÉÏÏÂÎÄÇл»ÇéÐÎ
×îºóͨ¹ýpidstatÊÓ²ìÏ̵߳ÄÉÏÏÂÎÄÇл»ÇéÐÎ
Àú³ÌCPUʹÓÃÂʸ߰¸Àý
ÏÈÓÃtopÉó²éϵͳºÍÀú³ÌµÄCPUʹÓÃÇéÐÎ,¶¨Î»µ½Àú³Ì
ÔÙÓÃperf topÊÓ²ìÀú³ÌŲÓÃÁ´,¶¨Î»µ½Ïêϸº¯Êý
ϵͳCPUʹÓÃÂʸ߰¸Àý
ÏÈÓÃtopÉó²éϵͳºÍÀú³ÌµÄCPUʹÓÃÇéÐÎ,top/pidstat¶¼ÎÞ·¨ÕÒµ½CPUʹÓÃÂʸߵÄÀú³Ì
ÖØÐÂÉóÔÄtopÊä³ö
´ÓCPUʹÓÃÂʲ»¸ß,¿ÉÊÇ´¦ÓÚRunning״̬µÄÀú³ÌÈëÊÖ
perf record/report·¢Ã÷¶ÌʱÀú³Ìµ¼Ö (execsnoop¹¤¾ß)
²»¿ÉÖÐÖ¹ºÍ½©Ê¬Àú³Ì°¸Àý
ÏÈÓÃtopÊÓ²ìiowaitÉý¸ß,·¢Ã÷´ó×Ú²»¿ÉÖÐÖ¹ºÍ½©Ê¬Àú³Ì
straceÎÞ·¨¸ú×ÙÀú³ÌϵͳŲÓÃ
perfÆÊÎöŲÓÃÁ´·¢Ã÷ȪԴÀ´×Ô´ÅÅÌÖ±½ÓI/O
ÈíÖÐÖ¹°¸Àý
topÊÓ²ìϵͳÈíÖÐÖ¹CPUʹÓÃÂʸß
Éó²é/proc/softirqsÕÒµ½×ª±äËÙÂʽϿìµÄ¼¸ÖÖÈíÖÐÖ¹
sarÏÂÁî·¢Ã÷ÊÇÍøÂçС°üÎÊÌâ
tcpdumpÕÒ³öÍøÂçÖ¡µÄÀàÐͺÍȪԴ, È·¶¨SYN FLOOD¹¥»÷µ¼ÖÂ
ƾ֤²î±ðµÄÐÔÄÜÖ¸±êÀ´ÕÒºÏÊʵŤ¾ß:
ͼƬÀ´×Ô: www.ctq6.cn
ÔÚÉú²úÇéÐÎÖÐÍùÍù¿ª·¢ÕßûÓÐȨÏÞ×°ÖÃÐµĹ¤¾ß°ü,Ö»ÄÜ×î´ó»¯Ê¹ÓúÃϵͳÖÐÒѾװÖúõŤ¾ß. Òò´ËÒªÏàʶһЩÖ÷Á÷¹¤¾ßÄܹ»ÌṩÄÄЩָ±êÆÊÎö.
ͼƬÀ´×Ô: www.ctq6.cn
ÏÈÔËÐм¸¸öÖ§³ÖÖ¸±ê½Ï¶àµÄ¹¤¾ß, Èçtop/vmstat/pidstat,ƾ֤ËüÃǵÄÊä³ö¿ÉÒԵóöÊÇÄÄÖÖÀàÐ͵ÄÐÔÄÜÎÊÌâ. ¶¨Î»µ½Àú³ÌºóÔÙÓÃstrace/perfÆÊÎöŲÓÃÇéÐνøÒ»²½ÆÊÎö. ÈôÊÇÊÇÈíÖÐÖ¹µ¼ÖÂÓÃ/proc/softirqs
ͼƬÀ´×Ô: www.ctq6.cn
CPUÓÅ»¯
Ó¦ÓóÌÐòÓÅ»¯
±àÒëÆ÷ÓÅ»¯: ±àÒë½×¶Î¿ªÆôÓÅ»¯Ñ¡Ïî, Èçgcc -O2
Ëã·¨ÓÅ»¯
Òì²½´¦Àí: ×èÖ¹³ÌÐòÓÉÓÚÆÚ´ýij¸ö×ÊÔ´¶øÒ»Ö±ÛÕ±Õ,ÌáÉý³ÌÐòµÄ²¢·¢´¦ÀíÄÜÁ¦. (½«ÂÖѯÌ滻ΪÊÂÎñ֪ͨ)
¶àÏß³ÌÈ¡´ú¶àÀú³Ì: ïÔÌÉÏÏÂÎÄÇл»±¾Ç®
ÉÆÓûº´æ: ¼ÓËÙ³ÌÐò´¦ÀíËÙÂÊ
ϵͳÓÅ»¯
CPU°ó¶¨: ½«Àú³Ì°ó¶¨Òª1¸ö/¶à¸öCPUÉÏ,Ìá¸ßCPU»º´æÖÀÖÐÂÊ,ïÔÌCPUµ÷Àí´øÀ´µÄÉÏÏÂÎÄÇл»
CPU¶ÀÍÌ: CPUÇ׺ÍÐÔ»úÖÆÀ´·ÖÅÉÀú³Ì
ÓÅÏȼ¶µ÷½â:ʹÓÃniceÊʵ±½µµÍ·Ç½¹µãÓ¦ÓõÄÓÅÏȼ¶
ΪÀú³ÌÉèÖÃ×ÊÔ´ÏÔʾ: cgroupsÉèÖÃʹÓÃÉÏÏÞ,±ÜÃâÓÉij¸öÓ¦ÓÃ×ÔÉíÎÊÌâºÄ¾¡ÏµÍ³×ÊÔ´
NUMAÓÅ»¯: CPU¾¡¿ÉÄÜ»á¼ûÍâµØÄÚ´æ
ÖÐÖ¹¸ºÔØƽºâ: irpbalance,½«ÖÐÖ¹´¦ÀíÀú³Ì×Ô¶¯¸ºÔØƽºâµ½¸÷¸öCPUÉÏ
TPS¡¢QPS¡¢ÏµÍ³ÍÌÍÂÁ¿µÄÇø±ðºÍÃ÷È·
QPS(TPS)
²¢·¢Êý
ÏìӦʱ¼ä
QPS(TPS)=²¢·¢Êý/ƽ¾ùÏìӦʱ¼ä
Óû§ÇëÇóЧÀÍÆ÷
ЧÀÍÆ÷ÄÚ²¿´¦Àí
ЧÀÍÆ÷·µ»Ø¸ø¿Í»§
QPSÀàËÆTPS,¿ÉÊǹØÓÚÒ»¸öÒ³ÃæµÄ»á¼ûÐγÉÒ»¸öTPS,¿ÉÊÇÒ»´ÎÒ³ÃæÇëÇó¿ÉÄÜ°üÀ¨¶à´Î¶ÔЧÀÍÆ÷µÄÇëÇó,¿ÉÄܼÆÈë¶à´ÎQPS
QPS (Queries Per Second)ÿÃëÅÌÎÊÂÊ,һ̨ЧÀÍÆ÷ÿÃëÄܹ»ÏìÓ¦µÄÅÌÎÊ´ÎÊý.
TPS (Transactions Per Second)ÿÃëÊÂÎñÊý,Èí¼þ²âÊÔµÄЧ¹û.
ϵͳÍÌÍÂÁ¿, °üÀ¨¼¸¸öÖ÷Òª²ÎÊý:
3ÄÚ´æ
LinuxÄÚ´æÊÇÔõôÊÂÇéµÄ
ÄÚ´æÓ³Éä
´ó´ó¶¼ÅÌËã»úÓõÄÖ÷´æ¶¼ÊǶ¯Ì¬Ëæʱ»ú¼ûÄÚ´æ(DRAM)£¬Ö»ÓÐÄں˲ſÉÒÔÖ±½Ó»á¼ûÎïÀíÄÚ´æ¡£LinuxÄں˸øÿ¸öÀú³ÌÌṩÁËÒ»¸ö×ÔÁ¦µÄÐéÄâµØµã¿Õ¼ä£¬²¢ÇÒÕâ¸öµØµã¿Õ¼äÊÇÒ»Á¬µÄ¡£ÕâÑùÀú³Ì¾Í¿ÉÒÔºÜÀû±ãµÄ»á¼ûÄÚ´æ(ÐéÄâÄÚ´æ)¡£
ÐéÄâµØµã¿Õ¼äµÄÄÚ²¿·ÖΪÄں˿ռäºÍÓû§¿Õ¼äÁ½²¿·Ö£¬²î±ð×Ö³¤µÄ´¦ÀíÆ÷µØµã¿Õ¼äµÄ¹æÄ£²î±ð¡£32λϵͳÄں˿ռäÕ¼ÓÃ1G£¬Óû§¿Õ¼äÕ¼3G¡£64λϵͳÄں˿ռäºÍÓû§¿Õ¼ä¶¼ÊÇ128T£¬»®·ÖÕ¼ÄÚ´æ¿Õ¼äµÄ×î¸ßºÍ×îµÍ´¦£¬ÖÐÑ벿·ÖΪδ½ç˵¡£
²¢²»ÊÇËùÓеÄÐéÄâÄڴ涼»á·ÖÅÉÎïÀíÄڴ棬ֻÓÐÏÖʵʹÓõIJŻᡣ·ÖÅɺóµÄÎïÀíÄÚ´æͨ¹ýÄÚ´æÓ³ÉäÖÎÀí¡£ÎªÁËÍê³ÉÄÚ´æÓ³É䣬ÄÚºËΪÿ¸öÀú³Ì¶¼Î¬»¤ÁËÒ»¸öÒ³±í£¬¼Í¼ÐéÄâµØµãºÍÎïÀíµØµãµÄÓ³Éä¹Øϵ¡£Ò³ÏÔ¶ʵ´æ´¢ÔÚCPUµÄÄÚ´æÖÎÀíµ¥Î»MMUÖУ¬´¦ÀíÆ÷¿ÉÒÔÖ±½Óͨ¹ýÓ²¼þÕÒ³öÒª»á¼ûµÄÄÚ´æ¡£
µ±Àú³Ì»á¼ûµÄÐéÄâµØµãÔÚÒ³±íÖв鲻µ½Ê±£¬ÏµÍ³»á±¬·¢Ò»¸öȱҳÒì³££¬½øÈëÄں˿ռä·ÖÅÉÎïÀíÄڴ棬¸üÐÂÀú³ÌÒ³±í£¬ÔÙ·µ»ØÓû§¿Õ¼ä»Ö¸´Àú³ÌµÄÔËÐС£
MMUÒÔҳΪµ¥Î»ÖÎÀíÄڴ棬ҳ¾Þϸ4KB¡£ÎªÏàʶ¾öÒ³±íÏî¹ý¶àÎÊÌâLinuxÌṩÁ˶༶ҳ±íºÍHugePageµÄ»úÖÆ¡£
ÐéÄâÄÚ´æ¿Õ¼äÂþÑÜ
Óû§¿Õ¼äÄÚ´æ´ÓµÍµ½¸ßÊÇÎåÖÖ²î±ðµÄÄÚ´æ¶Î£º
Ö»¶Á¶Î ´úÂëºÍ³£Á¿µÈ
Êý¾Ý¶Î È«¾Ö±äÁ¿µÈ
¶Ñ ¶¯Ì¬·ÖÅɵÄÄڴ棬´ÓµÍµØµã×îÏÈÏòÉÏÔöÌí
ÎļþÓ³Éä ¶¯Ì¬¿â¡¢¹²ÏíÄÚ´æµÈ£¬´Ó¸ßµØµã×îÏÈÏòÏÂÔöÌí
Õ» °üÀ¨¾Ö²¿±äÁ¿ºÍº¯ÊýŲÓõÄÉÏÏÂÎĵȣ¬Õ»µÄ¾ÞϸÊÇÀο¿µÄ¡£Ò»Ñùƽ³£8MB
ÄÚ´æ·ÖÅÉÓë½ÓÄÉ
·ÖÅÉ
malloc¶ÔÓ¦µ½ÏµÍ³Å²ÓÃÉÏÓÐÁ½ÖÖʵÏÖ·½·¨£º
brk() Õë¶ÔС¿éÄÚ´æ(<128K)£¬Í¨¹ýÒƶ¯¶Ñ¶¥Î»ÖÃÀ´·ÖÅÉ¡£ÄÚ´æÊͷźó²»Á¬Ã¦ËÍ»¹Äڴ棬¶øÊDZ»»º´æÆðÀ´¡£
**mmap()**Õë¶Ô´ó¿éÄÚ´æ(>128K)£¬Ö±½ÓÓÃÄÚ´æÓ³ÉäÀ´·ÖÅÉ£¬¼´ÔÚÎļþÓ³Éä¶ÎÕÒÒ»¿é¿ÕÏÐÄÚ´æ·ÖÅÉ¡£
Ç°ÕߵĻº´æ¿ÉÒÔïÔÌȱҳÒì³£µÄ±¬·¢£¬Ìá¸ßÄÚ´æ»áÊÕЧÂÊ¡£¿ÉÊÇÓÉÓÚÄÚ´æûÓÐËÍ»¹ÏµÍ³£¬ÔÚÄÚ´æÊÂÇéæµʱ£¬ÆµÈÔµÄÄÚ´æ·ÖÅÉ/ÊÍ·Å»áÔì³ÉÄÚ´æËéƬ¡£
ºóÕßÔÚÊÍ·Åʱֱ½ÓËÍ»¹ÏµÍ³£¬ÒÔÊÇÿ´Îmmap¶¼»á±¬·¢È±Ò³Òì³£¡£ÔÚÄÚ´æÊÂÇéæµʱ£¬ÆµÈÔÄÚ´æ·ÖÅɻᵼÖ´ó×ÚȱҳÒì³££¬Ê¹ÄÚºËÖÎÀí¼ç¸ºÔöÌí¡£
ÉÏÊöÁ½ÖÖŲÓò¢Ã»ÓÐÕæÕý·ÖÅÉÄڴ棬ÕâЩÄÚ´æÖ»ÓÐÔÚÊ״λá¼ûʱ£¬²Åͨ¹ýȱҳÒì³£½øÈëÄÚºËÖУ¬ÓÉÄÚºËÀ´·ÖÅÉ
½ÓÄÉ
ÄÚ´æÖ÷Ҫʱ£¬ÏµÍ³Í¨¹ýÒÔÏ·½·¨À´½ÓÄÉÄڴ棺
½ÓÄÉ»º´æ£ºLRUËã·¨½ÓÄÉ×î½ü×îÉÙʹÓõÄÄÚ´æÒ³Ã棻
½ÓÄɲ»³£»á¼ûÄڴ棺°Ñ²»³£ÓõÄÄÚ´æͨ¹ý½»Á÷·ÖÇøдÈë´ÅÅÌ
ɱËÀÀú³Ì£ºOOMÄں˱£»¤»úÖÆ £¨Àú³ÌÏûºÄÄÚ´æÔ½´óoom_scoreÔ½´ó£¬Õ¼ÓÃCPUÔ½¶àoom_scoreԽС£¬¿ÉÒÔͨ¹ý/procÊÖ¶¯µ÷½âoom_adj£©
echo -16 > /proc/$(pidof XXX)/oom_adj
µÇ¼ºó¸´ÖÆ
ÔõÑùÉó²éÄÚ´æʹÓÃÇéÐÎ
freeÀ´Éó²éÕû¸öϵͳµÄÄÚ´æʹÓÃÇéÐÎ
top/psÀ´Éó²éij¸öÀú³ÌµÄÄÚ´æʹÓÃÇéÐÎ
VIRT Àú³ÌµÄÐéÄâÄÚ´æ¾Þϸ
RES ³£×¤ÄÚ´æµÄ¾Þϸ£¬¼´Àú³ÌÏÖʵʹÓõÄÎïÀíÄÚ´æ¾Þϸ£¬²»°üÀ¨swapºÍ¹²ÏíÄÚ´æ
SHR ¹²ÏíÄÚ´æ¾Þϸ£¬ÓëÆäËûÀú³Ì¹²ÏíµÄÄڴ棬¼ÓÔصĶ¯Ì¬Á´½Ó¿âÒÔ¼°³ÌÐò´úÂë¶Î
%MEM Àú³ÌʹÓÃÎïÀíÄÚ´æռϵͳ×ÜÄÚ´æµÄ°Ù·Ö±È
ÔõÑùÃ÷È·ÄÚ´æÖеÄBufferºÍCache£¿
bufferÊǶԴÅÅÌÊý¾ÝµÄ»º´æ£¬cacheÊǶÔÎļþÊý¾ÝµÄ»º´æ£¬ËüÃǼȻáÓÃÔÚ¶ÁÇëÇóÒ²»áÓÃÔÚдÇëÇóÖÐ
ÔõÑùʹÓÃϵͳ»º´æÓÅ»¯³ÌÐòµÄÔËÐÐЧÂÊ
»º´æÖÀÖÐÂÊ
»º´æÖÀÖÐÂÊÊÇÖ¸Ö±½Óͨ¹ý»º´æ»ñÈ¡Êý¾ÝµÄÇëÇó´ÎÊý£¬Õ¼ËùÓÐÇëÇó´ÎÊýµÄ°Ù·Ö±È¡£ÖÀÖÐÂÊÔ½¸ß˵Ã÷»º´æ´øÀ´µÄÊÕÒæÔ½¸ß£¬Ó¦ÓóÌÐòµÄÐÔÄÜÒ²¾ÍÔ½ºÃ¡£
×°ÖÃbcc°üºó¿ÉÒÔͨ¹ýcachestatºÍcachetopÀ´¼à²â»º´æµÄ¶ÁдÖÀÖÐÇéÐΡ£
×°ÖÃpcstatºó¿ÉÒÔÉó²éÎļþÔÚÄÚ´æÖеĻº´æ¾ÞϸÒÔ¼°»º´æ±ÈÀý
#Ê×ÏÈ×°ÖÃGo export GOPATH=~/go export PATH=~/go/bin:$PATH go get golang.org/x/sys/unix go ge github.com/tobert/pcstat/pcstat
µÇ¼ºó¸´ÖÆ
dd»º´æ¼ÓËÙ
dd if=/dev/sda1 of=file bs=1M count=512 #Éú²úÒ»¸ö512MBµÄÔÝʱÎļþ echo 3 > /proc/sys/vm/drop_caches #ÕûÀí»º´æ pcstat file #È·¶¨ÊʲÅÌìÉúÎļþ²»ÔÚϵͳ»º´æÖУ¬´ËʱcachedºÍpercent¶¼ÊÇ0 cachetop 5 dd if=file of=/dev/null bs=1M #²âÊÔÎļþ¶ÁÈ¡ËÙÂÊ #´ËʱÎļþ¶ÁÈ¡ÐÔÄÜΪ30+MB/s£¬Éó²écachetopЧ¹û·¢Ã÷²¢²»ÊÇËùÓеĶÁ¶¼ÂäÔÚ´ÅÅÌÉÏ£¬¶Á»º´æÖÀÖÐÂÊÖ»ÓÐ50%¡£ dd if=file of=/dev/null bs=1M #Öظ´ÉÏÊö¶ÁÎļþ²âÊÔ #´ËʱÎļþ¶ÁÈ¡ÐÔÄÜΪ4+GB/s£¬¶Á»º´æÖÀÖÐÂÊΪ100% pcstat file #Éó²éÎļþfileµÄ»º´æÇéÐΣ¬100%ËùÓлº´æ
µÇ¼ºó¸´ÖÆ
O_DIRECTÑ¡ÏîÈƹýϵͳ»º´æ
cachetop 5 sudo docker run --privileged --name=app -itd feisky/app:io-direct sudo docker logs app #È·ÈÏ°¸ÀýÆô¶¯ÀÖ³É #ʵÑéЧ¹ûÅúעÿ¶Á32MBÊý¾Ý¶¼Òª»¨0.9s£¬ÇÒcachetopÊä³öÖÐÏÔʾ1024´Î»º´æËùÓÐÖÀÖÐ
µÇ¼ºó¸´ÖÆ
¿ÉÊÇƾ¸ÐÊÜ¿ÉÖªÈôÊÇ»º´æÖÀÖжÁËÙÂʲ»Ó¦ÔÆÔÆÂý£¬¶Á´ÎÊýʱ1024£¬Ò³¾ÞϸΪ4K£¬ÎåÃëµÄʱ¼äÄÚ¶ÁÈ¡ÁË1024*4KBÊý¾Ý£¬¼´Ã¿Ãë0.8MB£¬ºÍЧ¹ûÖÐ32MBÏà²î½Ï´ó¡£ËµÃ÷¸Ã°¸ÀýûÓгä·ÖʹÓûº´æ£¬ÏÓÒÉϵͳŲÓÃÉèÖÃÁËÖ±½ÓI/O±ê¼ÇÈƹýϵͳ»º´æ¡£Òò´Ë½ÓÏÂÀ´ÊÓ²ìϵͳŲÓÃ.
strace -p $(pgrep app) #strace Ч¹û¿ÉÒÔ¿´µ½openat·¿ª´ÅÅÌ·ÖÇø/dev/sdb1£¬´«Èë²ÎÊýΪO_RDONLY|O_DIRECT
µÇ¼ºó¸´ÖÆ
Õâ¾ÍÚ¹ÊÍÁËΪʲô¶Á32MBÊý¾ÝÄÇôÂý£¬Ö±½Ó´Ó´ÅÅ̶Áдһ¶¨Ô¶Ô¶ÂýÓÚ»º´æ¡£ÕÒ³öÎÊÌâºóÎÒÃÇÔÙ¿´°¸ÀýµÄÔ´´úÂë·¢Ã÷flagsÖÐÖ¸¶¨ÁËÖ±½ÓIO±ê¼Ç¡£É¾³ý¸ÃÑ¡ÏîºóÖØÅÜ£¬ÑéÖ¤ÐÔÄÜת±ä¡£
ÄÚ´æ×ß©£¬ÔõÑù¶¨Î»ºÍ´¦Àí£¿
¶ÔÓ¦ÓóÌÐòÀ´Ëµ£¬¶¯Ì¬ÄÚ´æµÄ·ÖÅɺͽÓÄÉÊǽ¹µãÓÖÖØ´óµÄÒ»¸öÂß¼¹¦Ð§Ä£¿é¡£ÖÎÀíÄÚ´æµÄÀú³ÌÖлᱬ·¢ÖÖÖÖ¸÷ÑùµÄ¡°Ê¹ʡ±£º
û׼ȷ½ÓÄÉ·ÖÅɵÄÄڴ棬µ¼ÖÂÁË×ß©
»á¼ûµÄÊÇÒÑ·ÖÅÉÄÚ´æ½çÏßÍâµÄµØµã£¬µ¼Ö³ÌÐòÒì³£Í˳ö
ÄÚ´æµÄ·ÖÅÉÓë½ÓÄÉ
ÐéÄâÄÚ´æÂþÑܴӵ͵½¸ß»®·ÖÊÇÖ»¶Á¶Î£¬Êý¾Ý¶Î£¬¶Ñ£¬ÄÚ´æÓ³Éä¶Î£¬Õ»Î岿·Ö¡£ÆäÖлᵼÖÂÄÚ´æ×ß©µÄÊÇ£º
¶Ñ£ºÓÉÓ¦ÓóÌÐò×Ô¼ºÀ´·ÖÅɺÍÖÎÀí£¬³ý·Ç³ÌÐòÍ˳öÕâЩ¶ÑÄÚ´æ²»»á±»ÏµÍ³×Ô¶¯ÊÍ·Å¡£
ÄÚ´æÓ³Éä¶Î£º°üÀ¨¶¯Ì¬Á´½Ó¿âºÍ¹²ÏíÄڴ棬ÆäÖÐ ¹²ÏíÄÚ´æÓɳÌÐò×Ô¶¯·ÖÅɺÍÖÎÀí
ÄÚ´æ×ß©µÄΣº¦½ÏÁ¿´ó£¬ÕâЩÒÅÍüÊͷŵÄÄڴ棬²»µ«Ó¦ÓóÌÐò×Ô¼º²»¿É»á¼û£¬ÏµÍ³Ò²²»¿É°ÑËüÃÇÔٴηÖÅɸøÆäËûÓ¦ÓᣠÄÚ´æ×ß©һֱÀÛ»ýÉõÖÁ»áºÄ¾¡ÏµÍ³ÄÚ´æ.
ÔõÑù¼ì²âÄÚ´æ×ß©
Ô¤ÏÈ×°ÖÃsystat£¬docker£¬bcc
sudo docker run --name=app -itd feisky/app:mem-leak sudo docker logs app vmstat 3
µÇ¼ºó¸´ÖÆ
¿ÉÒÔ¿´µ½freeÔÚһֱϽµ£¬bufferºÍcache»ù±¾¼á³ÖÎȹ̡£ËµÃ÷ϵͳµÄÄÚ´æÒ»ÖÂÔÚÉý¸ß¡£µ«²¢²»¿É˵Ã÷±£´æÄÚ´æ×ß©¡£´Ëʱ¿ÉÒÔͨ¹ýmemleak¹¤¾ßÀ´¸ú×Ùϵͳ»òÀú³ÌµÄÄÚ´æ·ÖÅÉ/ÊÍ·ÅÇëÇó
/usr/share/bcc/tools/memleak -a -p $(pidof app)
µÇ¼ºó¸´ÖÆ
´ÓmemleakÊä³ö¿ÉÒÔ¿´µ½£¬Ó¦ÓÃÔÚÒ»Ö±µØ·ÖÅÉÄڴ棬²¢ÇÒÕâЩ·ÖÅɵĵص㲢ûÓб»½ÓÄÉ¡£Í¨¹ýŲÓÃÕ»¿´µ½ÊÇfibonacciº¯Êý·ÖÅɵÄÄÚ´æûÓÐÊÍ·Å¡£¶¨Î»µ½Ô´ÂëºóÉó²éÔ´ÂëÀ´ÐÞ¸´ÔöÌíÄÚ´æÊͷź¯Êý¼´¿É.
ΪʲôϵͳµÄSwap±ä¸ß
ϵͳÄÚ´æ×ÊÔ´Ö÷Ҫʱͨ¹ýÄÚ´æ½ÓÄɺÍOOMɱËÀÀú³ÌÀ´½â¾ö¡£ÆäÖпɽÓÄÉÄÚ´æ°üÀ¨£º
»º´æ/»º³åÇø£¬ÊôÓڿɽÓÄÉ×ÊÔ´£¬ÔÚÎļþÖÎÀíÖÐͨ³£½Ð×öÎļþÒ³
ÔÚÓ¦ÓóÌÐòÖÐͨ¹ýfsync½«Ôàҳͬ²½µ½´ÅÅÌ
½»¸øϵͳ£¬ÄÚºËÏß³ÌpdflushÈÏÕæÕâЩÔàÒ³µÄË¢ÐÂ
±»Ó¦ÓóÌÐòÐÞ»Ú¸ÄÔÝʱûдÈë´ÅÅ̵ÄÊý¾Ý(ÔàÒ³)£¬ÒªÏÈдÈë´ÅÅÌÈ»ºó²Å»ªÄÚ´æÊÍ·Å
ÄÚ´æÓ³Éä»ñÈ¡µÄÎļþÓ³ÉäÒ³£¬Ò²¿ÉÒÔ±»Êͷŵô£¬Ï´λá¼ûʱ´ÓÎļþÖØжÁÈ¡
¹ØÓÚ³ÌÐò×Ô¶¯·ÖÅɵĶÑÄڴ棬Ҳ¾ÍÊÇÎÒÃÇÔÚÄÚ´æÖÎÀíÖеÄÄäÃûÒ³£¬ËäÈ»ÕâЩÄÚ´æ²»¿ÉÖ±½ÓÊÍ·Å£¬¿ÉÊÇLinuxÌṩÁËSwap»úÖƽ«²»³£»á¼ûµÄÄÚ´æдÈëµ½´ÅÅÌÀ´ÊÍ·ÅÄڴ棬Ôٴλá¼ûʱ´Ó´ÅÅ̶ÁÈ¡µ½ÄÚ´æ¼´¿É¡£
SwapÔÀí
SwapʵÖʾÍÊÇ°ÑÒ»¿é´ÅÅÌ¿Õ¼ä»òÕßÒ»¸öÍâµØÎļþ¿´³ÉÄÚ´æÀ´Ê¹Ó㬰üÀ¨»»ÈëºÍ»»³öÁ½¸öÀú³Ì£º
»»³ö£º½«Àú³ÌÔÝʱ²»±ØµÄÄÚ´æÊý¾Ý´æ´¢µ½´ÅÅÌÖУ¬²¢ÊÍ·ÅÕâЩÄÚ´æ
»»È룺Àú³ÌÔٴλá¼ûÄÚ´æʱ£¬½«ËüÃÇ´Ó´ÅÅ̶Áµ½ÄÚ´æÖÐ
LinuxÔõÑùȨºâÄÚ´æ×ÊÔ´ÊÇ·ñÖ÷Òª£¿
Ö±½ÓÄÚ´æ½ÓÄÉ ÐµĴó¿éÄÚ´æ·ÖÅÉÇëÇ󣬵«Ê£ÓàÄÚ´æȱ·¦¡£´Ëʱϵͳ»á½ÓÄÉÒ»²¿·ÖÄڴ棻
kswapd0 ÄÚºËḬ̈߳´ÆÚ½ÓÄÉÄڴ档ΪÁËȨºâÄÚ´æʹÓÃÇéÐΣ¬½ç˵ÁËpages_min,pages_low,pages_highÈý¸öãÐÖµ£¬²¢Æ¾Ö¤ÆäÀ´¾ÙÐÐÄÚ´æµÄ½ÓÄɲÙ×÷¡£
Ê£ÓàÄÚ´æ < pages_min£¬Àú³Ì¿ÉÓÃÄÚ´æºÄ¾¡ÁË£¬Ö»ÓÐÄں˲ſÉÒÔ·ÖÅÉÄÚ´æ
pages_min < Ê£ÓàÄÚ´æ < pages_low,ÄÚ´æѹÁ¦½Ï´ó£¬kswapd0Ö´ÐÐÄÚ´æ½ÓÄÉ£¬Ö±µ½Ê£ÓàÄÚ´æ > pages_high
pages_low < Ê£ÓàÄÚ´æ < pages_high£¬ÄÚ´æÓÐÒ»¶¨Ñ¹Á¦£¬µ«¿ÉÒÔÖª×ãÐÂÄÚ´æÇëÇó
Ê£ÓàÄÚ´æ > pages_high£¬ËµÃ÷Ê£ÓàÄÚ´æ½Ï¶à£¬ÎÞÄÚ´æѹÁ¦
pages_low = pages_min 5 / 4 pages_high = pages_min 3 / 2
NUMA Óë SWAP
Ðí¶àÇéÐÎÏÂϵͳʣÓàÄÚ´æ½Ï¶à£¬µ«SWAPÒÀ¾ÉÉý¸ß£¬ÕâÊÇÓÉÓÚ´¦ÀíÆ÷µÄNUMA¼Ü¹¹¡£
ÔÚNUMA¼Ü¹¹Ï¶à¸ö´¦ÀíÆ÷»®·Öµ½²î±ðµÄNode£¬Ã¿¸öNode¶¼ÓµÓÐ×Ô¼ºµÄÍâµØÄÚ´æ¿Õ¼ä¡£ÔÚÆÊÎöÄÚ´æµÄʹÓÃʱӦ¸ÃÕë¶Ôÿ¸öNodeµ¥¶ÀÆÊÎö
numactl --hardware #Éó²é´¦ÀíÆ÷ÔÚNodeµÄÂþÑÜÇéÐΣ¬ÒÔ¼°Ã¿¸öNodeµÄÄÚ´æʹÓÃÇéÐÎ
µÇ¼ºó¸´ÖÆ
ÄÚ´æÈý¸öãÐÖµ¿ÉÒÔͨ¹ý/proc/zoneinfoÀ´Éó²é£¬¸ÃÎļþÖл¹°üÀ¨»îÔ¾ºÍ·Ç»îÔ¾µÄÄäÃûÒ³/ÎļþÒ³Êý¡£
µ±Ä³¸öNodeÄÚ´æȱ·¦Ê±£¬ÏµÍ³¿ÉÒÔ´ÓÆäËûNodeÑ°ÕÒ¿ÕÏÐ×ÊÔ´£¬Ò²¿ÉÒÔ´ÓÍâµØÄÚ´æÖнÓÄÉÄڴ档ͨ¹ý/proc/sys/vm/zone_raclaim_modeÀ´µ÷½â¡£
0ÌåÏּȿÉÒÔ´ÓÆäËûNodeÑ°ÕÒ¿ÕÏÐ×ÊÔ´£¬Ò²¿ÉÒÔ´ÓÍâµØ½ÓÄÉÄÚ´æ
1£¬2£¬4ÌåÏÖÖ»½ÓÄÉÍâµØÄڴ棬2ÌåÏÖ¿ÉÒÔ»á»ØÔàÊý¾Ý½ÓÄÉÄڴ棬4ÌåÏÖ¿ÉÒÔÓÃSwap·½·¨½ÓÄÉÄÚ´æ¡£
swappiness
ÔÚÏÖʵ½ÓÄÉÀú³ÌÖÐLinuxƾ֤/proc/sys/vm/swapinessÑ¡ÏîÀ´µ÷½âʹÓÃSwapµÄÆð¾¢Ë®Æ½£¬´Ó0-100£¬ÊýÖµÔ½´óÔ½Æð¾¢Ê¹ÓÃSwap£¬¼´¸üÇãÏòÓÚ½ÓÄÉÄäÃûÒ³£»ÊýֵԽСԽÏû¼«Ê¹ÓÃSwap£¬¼´¸üÇãÏòÓÚ½ÓÄÉÎļþÒ³¡£
×¢ÖØ£ºÕâÖ»Êǵ÷½âSwapÆð¾¢Ë®Æ½µÄȨÖØ£¬×ÝÈ»ÉèÖÃΪ0£¬µ±Ê£ÓàÄÚ´æ+ÎļþҳСÓÚÒ³¸ßãÐֵʱ£¬Õվɻᱬ·¢Swap¡£
SwapÉý¸ßʱÔõÑù¶¨Î»ÆÊÎö
free #Ê×ÏÈͨ¹ýfreeÉó²éswapʹÓÃÇéÐΣ¬Èôswap=0ÌåÏÖδÉèÖÃSwap #ÏȽ¨Éè²¢¿ªÆôswap fallocate -l 8G /mnt/swapfile chmod 600 /mnt/swapfile mkswap /mnt/swapfile swapon /mnt/swapfile free #ÔÙ´ÎÖ´ÐÐfreeÈ·±£SwapÉèÖÃÀÖ³É dd if=/dev/sda1 of=/dev/null bs=1G count=2048 #Ä£Äâ´óÎļþ¶ÁÈ¡ sar -r -S 1 #Éó²éÄÚ´æ¸÷¸öÖ¸±êת±ä -rÄÚ´æ -S swap #ƾ֤Ч¹û¿ÉÒÔ¿´³ö£¬%memusedÔÚÒ»Ö±ÔöÌí£¬Ê£ÓàÄÚ´ækbmemfressÒ»Ö±ïÔÌ£¬»º³åÇøkbbuffersÒ»Ö±Ôö´ó£¬ÓÉ´Ë¿É֪ʣÓàÄÚ´æÒ»Ö±·ÖÅɸøÁË»º³åÇø #Ò»¶Îʱ¼äÖ®ºó£¬Ê£ÓàÄÚ´æºÜС£¬¶ø»º³åÇøÕ¼ÓÃÁ˴󲿷ÖÄÚ´æ¡£´ËʱSwapʹÓÃÖ®¼äÔö´ó£¬»º³åÇøºÍÊ£ÓàÄÚ´æÖ»ÔÚС¹æÄ£²¨¶¯ Í£ÏÂsarÏÂÁî cachetop5 #ÊӲ컺´æ #¿ÉÒÔ¿´µ½ddÀú³Ì¶ÁдֻÓÐ50%µÄÖÀÖÐÂÊ£¬Î´ÖÀÖÐÊýΪ4w+Ò³£¬ËµÃ÷ÕýʽddÀú³Ìµ¼Ö»º³åÇøʹÓÃÉý¸ß watch -d grep -A 15 ¡®Normal¡¯ /proc/zoneinfo #ÊÓ²ìÄÚ´æÖ¸±êת±ä #·¢Ã÷Éý¼¶ÄÚ±£´æÒ»¸öС¹æÄ£Ò»Ö±µÄ²¨¶¯£¬µÍÓÚÒ³µÍãÐֵʱ»áͻȻÔö´óµ½Ò»¸ö´óÓÚÒ³¸ßãÐÖµµÄÖµ
µÇ¼ºó¸´ÖÆ
˵Ã÷Ê£ÓàÄڴ滺ºÍ³åÇøµÄ²¨¶¯×ª±äÕýÊÇÓÉÓÚÄÚ´æ½ÓÄÉ»ººÍ´æÔٴηÖÅɵÄÑ»·Íù¸´¡£ÓÐʱ¼äSwapÓõĶ࣬ÓÐʱ¼ä»º³åÇø²¨¶¯¸ü¶à¡£´ËʱÉó²éswappinessֵΪ60£¬ÊÇÒ»¸öÏà¶ÔÖк͵ÄÉèÖã¬ÏµÍ³»áƾ֤ÏÖʵÔËÐÐÇéÐÎÀ´Ñ¡È¥ºÏÊʵĽÓÄÉÀàÐÍ.
ÔõÑù¡°¿ì×¼ºÝ¡±ÕÒµ½ÏµÍ³ÄÚ´æ±£´æµÄÎÊÌâ
ÄÚ´æÐÔÄÜÖ¸±ê
ϵͳÄÚ´æÖ¸±ê
ÒÑÓÃÄÚ´æ/Ê£ÓàÄÚ´æ
¹²ÏíÄÚ´æ £¨tmpfsʵÏÖ£©
¿ÉÓÃÄڴ棺°üÀ¨Ê£ÓàÄÚ´æºÍ¿É½ÓÄÉÄÚ´æ
»º´æ£º´ÅÅ̶ÁÈ¡ÎļþµÄÒ³»º´æ£¬slab·ÖÅÉÆ÷ÖеĿɽÓÄɲ¿·Ö
»º³åÇø£ºÔʼ´ÅÅÌ¿éµÄÔÝʱ´æ´¢£¬»º´æ½«ÒªÐ´Èë´ÅÅ̵ÄÊý¾Ý
Àú³ÌÄÚ´æÖ¸±ê
ÐéÄâÄڴ棺5´ó²¿·Ö
³£×¤Äڴ棺Àú³ÌÏÖʵʹÓõÄÎïÀíÄڴ棬²»°üÀ¨SwapºÍ¹²ÏíÄÚ´æ
¹²ÏíÄڴ棺ÓëÆäËûÀú³Ì¹²ÏíµÄÄڴ棬ÒÔ¼°¶¯Ì¬Á´½Ó¿âºÍ³ÌÐòµÄ´úÂë¶Î
ÁíÍ⣬ËÑË÷ÃñÖÚºÅÊÖÒÕÉçÇøºǫ́»Ø¸´¡°Ëã·¨¡±£¬»ñÈ¡Ò»·Ý¾ªÏ²Àñ°ü¡£
SwapÄڴ棺ͨ¹ýSwap»»³öµ½´ÅÅ̵ÄÄÚ´æ
ȱҳÒì³£
¿ÉÒÔÖ±½Ó´ÓÎïÀíÄÚ´æÖзÖÅÉ£¬´ÎȱҳÒì³£
ÐèÒª´ÅÅÌIO½éÈë(ÈçSwap)£¬Ö÷ȱҳÒì³£¡£´ËʱÄÚ´æ»á¼û»áÂýÐí¶à
ÄÚ´æÐÔÄܹ¤¾ß
ƾ֤²î±ðµÄÐÔÄÜÖ¸±êÀ´ÕÒºÏÊʵŤ¾ß:
ͼƬÀ´×Ô: www.ctq6.cn
ÄÚ´æÆÊÎö¹¤¾ß°üÀ¨µÄÐÔÄÜÖ¸±ê:
ͼƬÀ´×Ô: www.ctq6.cn
ÔõÑùѸËÙÆÊÎöÄÚ´æµÄÐÔÄÜÆ¿¾±
ͨ³£ÏÈÔËÐм¸¸öÁýÕÖÃæ½ÏÁ¿´óµÄÐÔÄܹ¤¾ß£¬Èçfree£¬top£¬vmstat£¬pidstatµÈ
ÏÈÓÃfreeºÍtopÉó²éϵͳÕûÌåÄÚ´æʹÓÃÇéÐÎ
ÔÙÓÃvmstatºÍpidstat£¬Éó²éÒ»¶Îʱ¼äµÄÇ÷ÊÆ£¬´Ó¶øÅжÏÄÚ´æÎÊÌâµÄÀàÐÍ
×îºó¾ÙÐÐÏêϸÆÊÎö£¬ºÃ±ÈÄÚ´æ·ÖÅÉÆÊÎö£¬»º´æ/»º³åÇøÆÊÎö£¬ÏêϸÀú³ÌµÄÄÚ´æʹÓÃÆÊÎöµÈ
³£¼ûµÄÓÅ»¯Ë¼Ð÷£º
×îºÃեȡSwap£¬Èô±ØÐ迪ÆôÔòÖ»¹Ü½µµÍswappinessµÄÖµ
ïÔÌÄÚ´æµÄ¶¯Ì¬·ÖÅÉ£¬Èç¿ÉÒÔÓÃÄÚ´æ³Ø£¬HugePageµÈ
Ö»¹ÜʹÓûº´æ»ººÍ³åÇøÀ´»á¼ûÊý¾Ý¡£ÈçÓÿÍÕ»Ã÷È·ÉùÃ÷ÄÚ´æ¿Õ¼äÀ´´æ´¢ÐèÒª»º´æµÄÊý¾Ý£¬»òÕßÓÃRedisÍⲿ»º´æ×é¼þÀ´ÓÅ»¯Êý¾ÝµÄ»á¼û
cgroupsµÈ·½·¨À´ÏÞÖÆÀú³ÌµÄÄÚ´æʹÓÃÇéÐΣ¬È·±£ÏµÍ³ÄÚ´æ²»±»Òì³£Àú³ÌºÄ¾¡
/proc/pid/oom_adjµ÷½â½¹µãÓ¦ÓõÄoom_score£¬°ü¹Ü×ÝÈ»ÄÚ´æÖ÷Òª½¹µãÓ¦ÓÃÒ²²»»á±»OOMɱËÀ
vmstatʹÓÃÏê½â
vmstatÏÂÁîÊÇ×î³£¼ûµÄLinux/Unix¼à¿Ø¹¤¾ß£¬¿ÉÒÔÕ¹ÏÖ¸ø׼ʱ¼ä¾àÀëµÄЧÀÍÆ÷µÄ״ֵ̬,°üÀ¨Ð§ÀÍÆ÷µÄCPUʹÓÃÂÊ£¬ÄÚ´æʹÓã¬ÐéÄâÄÚ´æ½»Á÷ÇéÐÎ,IO¶ÁдÇéÐΡ£¿ÉÒÔ¿´µ½Õû¸ö»úеµÄCPU,ÄÚ´æ,IOµÄʹÓÃÇéÐΣ¬¶ø²»Êǵ¥µ¥¿´µ½¸÷¸öÀú³ÌµÄCPUʹÓÃÂʺÍÄÚ´æʹÓÃÂÊ(ʹÓó¡¾°·×ÆçÑù)¡£
vmstat 2 procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu----- r b swpd free buff cache si so bi bo in cs us sy id wa st 1 0 0 1379064 282244 11537528 0 0 3 104 0 0 3 0 97 0 0 0 0 0 1372716 282244 11537544 0 0 0 24 4893 8947 1 0 98 0 0 0 0 0 1373404 282248 11537544 0 0 0 96 5105 9278 2 0 98 0 0 0 0 0 1374168 282248 11537556 0 0 0 0 5001 9208 1 0 99 0 0 0 0 0 1376948 282248 11537564 0 0 0 80 5176 9388 2 0 98 0 0 0 0 0 1379356 282256 11537580 0 0 0 202 5474 9519 2 0 98 0 0 1 0 0 1368376 282256 11543696 0 0 0 0 5894 8940 12 0 88 0 0 1 0 0 1371936 282256 11539240 0 0 0 10554 6176 9481 14 1 85 1 0 1 0 0 1366184 282260 11542292 0 0 0 7456 6102 9983 7 1 91 0 0 1 0 0 1353040 282260 11556176 0 0 0 16924 7233 9578 18 1 80 1 0 0 0 0 1359432 282260 11549124 0 0 0 12576 5495 9271 7 0 92 1 0 0 0 0 1361744 282264 11549132 0 0 0 58 8606 15079 4 2 95 0 0 1 0 0 1367120 282264 11549140 0 0 0 2 5716 9205 8 0 92 0 0 0 0 0 1346580 282264 11562644 0 0 0 70 6416 9944 12 0 88 0 0 0 0 0 1359164 282264 11550108 0 0 0 2922 4941 8969 3 0 97 0 0 1 0 0 1353992 282264 11557044 0 0 0 0 6023 8917 15 0 84 0 0 # Ч¹û˵Ã÷ - r ÌåÏÖÔËÐÐÐÐÁÐ(¾ÍÊÇ˵¼¸¶à¸öÀú³ÌÕæµÄ·ÖÅɵ½CPU)£¬ÎÒ²âÊÔµÄЧÀÍÆ÷ÏÖÔÚCPU½ÏÁ¿¿ÕÏУ¬Ã»Ê²Ã´³ÌÐòÔÚÅÜ£¬µ±Õâ¸öÖµÁè¼ÝÁËCPUÊýÄ¿£¬¾Í»á·ºÆðCPUÆ¿¾±ÁË¡£Õâ¸öÒ²ºÍtopµÄ¸ºÔØÓйØϵ£¬Ò»Ñùƽ³£¸ºÔØÁè¼ÝÁË3¾Í½ÏÁ¿¸ß£¬Áè¼ÝÁË5¾Í¸ß£¬Áè¼ÝÁË10¾Í²»Õý³£ÁË£¬Ð§ÀÍÆ÷µÄ״̬ºÜΣÏÕ¡£topµÄ¸ºÔØÀàËÆÿÃëµÄÔËÐÐÐÐÁС£ÈôÊÇÔËÐÐÐÐÁйý´ó£¬ÌåÏÖÄãµÄCPUºÜæµ£¬Ò»Ñùƽ³£»áÔì³ÉCPUʹÓÃÂʺܸߡ£ - b ÌåÏÖÛÕ±ÕµÄÀú³Ì,Õâ¸öδ¼¸Ëµ£¬Àú³ÌÛÕ±Õ£¬¸÷È˶®µÄ¡£ - swpd ÐéÄâÄÚ´æÒÑʹÓõľÞϸ£¬ÈôÊÇ´óÓÚ0£¬ÌåÏÖÄãµÄ»úеÎïÀíÄÚ´æȱ·¦ÁË£¬ÈôÊDz»ÊdzÌÐòÄÚ´æ鶵ÄÔµ¹ÊÔÓÉ£¬ÄÇôÄã¸ÃÉý¼¶ÄÚ´æÁË»òÕ߰ѺÄÄÚ´æµÄʹÃüǨáãµ½ÆäËû»úе¡£ - free ¿ÕÏеÄÎïÀíÄÚ´æµÄ¾Þϸ£¬ÎҵĻúеÄÚ´æ×ܹ²8G£¬Ê£Óà3415M¡£ - buff Linux/UnixϵͳÊÇÓÃÀ´´æ´¢£¬Ä¿Â¼ÄÚÀïÓÐʲôÄÚÈÝ£¬È¨Ï޵ȵĻº´æ£¬ÎÒ±¾»ú»òÐíÕ¼ÓÃ300¶àM - cache cacheÖ±½ÓÓÃÀ´Ó°ÏóÎÒÃÇ·¿ªµÄÎļþ,¸øÎļþ×ö»º³å£¬ÎÒ±¾»ú»òÐíÕ¼ÓÃ300¶àM(ÕâÀïÊÇLinux/UnixµÄÖÇ»ÛÖ®´¦£¬°Ñ¿ÕÏеÄÎïÀíÄÚ´æµÄÒ»²¿·ÖÄÃÀ´×öÎļþºÍĿ¼µÄ»º´æ£¬ÊÇΪÁËÌá¸ß ³ÌÐòÖ´ÐеÄÐÔÄÜ£¬µ±³ÌÐòʹÓÃÄÚ´æʱ£¬buffer/cached»áºÜ¿ìµØ±»Ê¹Óá£) - si ÿÃë´Ó´ÅÅ̶ÁÈëÐéÄâÄÚ´æµÄ¾Þϸ£¬ÈôÊÇÕâ¸öÖµ´óÓÚ0£¬ÌåÏÖÎïÀíÄÚ´æ²»·óÓûòÕßÄÚ´æй¶ÁË£¬Òª²éÕÒºÄÄÚ´æÀú³Ì½â¾öµô¡£ÎҵĻúеÄÚ´æ³äÔ££¬Ò»ÇÐÕý³£¡£ - so ÿÃëÐéÄâÄÚ´æдÈë´ÅÅ̵ľÞϸ£¬ÈôÊÇÕâ¸öÖµ´óÓÚ0£¬Í¬ÉÏ¡£ - bi ¿é×°±¸Ã¿ÃëÎüÊյĿéÊýÄ¿£¬ÕâÀïµÄ¿é×°±¸ÊÇָϵͳÉÏËùÓеĴÅÅ̺ÍÆäËû¿é×°±¸£¬Ä¬ÈÏ¿é¾ÞϸÊÇ1024byte£¬ÎÒ±¾»úÉÏûʲôIO²Ù×÷£¬ÒÔÊÇÒ»Ö±ÊÇ0£¬¿ÉÊÇÎÒÔøÔÚ´¦Àí¿½±´´ó×ÚÊý¾Ý(2-3T)µÄ»úеÉÏ¿´¹ý¿ÉÒÔµÖ´ï140000/s£¬´ÅÅÌдÈëËÙÂʲîδ¼¸140MÿÃë - bo ¿é×°±¸Ã¿Ãë·¢Ë͵ĿéÊýÄ¿£¬ÀýÈçÎÒÃǶÁÈ¡Îļþ£¬bo¾ÍÒª´óÓÚ0¡£biºÍboÒ»Ñùƽ³£¶¼Òª¿¿½ü0£¬²»È»¾ÍÊÇIO¹ýÓÚƵÈÔ£¬ÐèÒªµ÷½â¡£ - in ÿÃëCPUµÄÖÐÖ¹´ÎÊý£¬°üÀ¨Ê±¼äÖÐÖ¹ - cs ÿÃëÉÏÏÂÎÄÇл»´ÎÊý£¬ÀýÈçÎÒÃÇŲÓÃϵͳº¯Êý£¬¾ÍÒª¾ÙÐÐÉÏÏÂÎÄÇл»£¬Ï̵߳ÄÇл»£¬Ò²ÒªÀú³ÌÉÏÏÂÎÄÇл»£¬Õâ¸öֵҪԽСԽºÃ£¬Ì«´óÁË£¬ÒªË¼Á¿µ÷µÍÏ̻߳òÕßÀú³ÌµÄÊýÄ¿,ÀýÈçÔÚapacheºÍnginxÕâÖÖwebЧÀÍÆ÷ÖУ¬ÎÒÃÇÒ»Ñùƽ³£×öÐÔÄܲâÊÔʱ»á¾ÙÐм¸Ç§²¢·¢ÉõÖÁ¼¸Íò²¢·¢µÄ²âÊÔ£¬Ñ¡ÔñwebЧÀÍÆ÷µÄÀú³Ì¿ÉÒÔÓÉÀú³Ì»òÕßÏ̵߳ķåֵһֱϵ÷£¬Ñ¹²â£¬Ö±µ½csµ½Ò»¸ö½ÏÁ¿Ð¡µÄÖµ£¬Õâ¸öÀú³ÌºÍÏß³ÌÊý¾ÍÊǽÏÁ¿ºÏÊʵÄÖµÁË¡£ÏµÍ³Å²ÓÃÒ²ÊÇ£¬Ã¿´ÎŲÓÃϵͳº¯Êý£¬ÎÒÃǵĴúÂë¾Í»á½øÈëÄں˿ռ䣬µ¼ÖÂÉÏÏÂÎÄÇл»£¬Õâ¸öÊǺܺÄ×ÊÔ´£¬Ò²ÒªÖ»¹Ü×èֹƵÈÔŲÓÃϵͳº¯Êý¡£ÉÏÏÂÎÄÇл»´ÎÊý¹ý¶àÌåÏÖÄãµÄCPU´ó²¿·ÖÆÌÕÅÔÚÉÏÏÂÎÄÇл»£¬µ¼ÖÂCPU¸ÉÕý¾ÊµÄʱ¼äÉÙÁË£¬CPUûÓгä·ÖʹÓã¬ÊDz»¿ÉÈ¡µÄ¡£ - us Óû§CPUʱ¼ä£¬ÎÒÒ»¾ÔÚÒ»¸ö×ö¼ÓÃܽâÃܺÜƵÈÔµÄЧÀÍÆ÷ÉÏ£¬¿ÉÒÔ¿´µ½us¿¿½ü100,rÔËÐÐÐÐÁеִï80(»úеÔÚ×öѹÁ¦²âÊÔ£¬ÐÔÄÜÌåÏÖ²»¼Ñ)¡£ - sy ϵͳCPUʱ¼ä£¬ÈôÊÇÌ«¸ß£¬ÌåÏÖϵͳŲÓÃʱ¼ä³¤£¬ÀýÈçÊÇIO²Ù×÷ƵÈÔ¡£ - id ¿ÕÏÐCPUʱ¼ä£¬Ò»Ñùƽ³£À´Ëµ£¬id + us + sy = 100,Ò»Ñùƽ³£ÎÒÒÔΪidÊÇ¿ÕÏÐCPUʹÓÃÂÊ£¬usÊÇÓû§CPUʹÓÃÂÊ£¬syÊÇϵͳCPUʹÓÃÂÊ¡£ - wt ÆÚ´ýIO CPUʱ¼ä
µÇ¼ºó¸´ÖÆ
pidstat ʹÓÃÏê½â
pidstatÖ÷ÒªÓÃÓÚ¼à¿ØËùÓлòÖ¸¶¨Àú³ÌÕ¼ÓÃϵͳ×ÊÔ´µÄÇéÐÎ,ÈçCPU,ÄÚ´æ¡¢×°±¸IO¡¢Ê¹ÃüÇл»¡¢Ï̵߳ȡ£
ʹÓÃÒªÁ죺
pidstat ¨Cd interval times ͳ¼Æ¸÷¸öÀú³ÌµÄIOʹÓÃÇéÐÎ
pidstat ¨Cu interval times ͳ¼Æ¸÷¸öÀú³ÌµÄCPUͳ¼ÆÐÅÏ¢
pidstat ¨Cr interval times ͳ¼Æ¸÷¸öÀú³ÌµÄÄÚ´æʹÓÃÐÅÏ¢
pidstat -w interval times ͳ¼Æ¸÷¸öÀú³ÌµÄÉÏÏÂÎÄÇл»
p PID Ö¸¶¨PID
1¡¢Í³¼ÆIOʹÓÃÇéÐÎ
pidstat -d 1 10 03:02:02 PM UID PID kB_rd/s kB_wr/s kB_ccwr/s Command 03:02:03 PM 0 816 0.00 918.81 0.00 jbd2/vda1-8 03:02:03 PM 0 1007 0.00 3.96 0.00 AliYunDun 03:02:03 PM 997 7326 0.00 1904.95 918.81 java 03:02:03 PM 997 8539 0.00 3.96 0.00 java 03:02:03 PM 0 16066 0.00 35.64 0.00 cmagent 03:02:03 PM UID PID kB_rd/s kB_wr/s kB_ccwr/s Command 03:02:04 PM 0 816 0.00 1924.00 0.00 jbd2/vda1-8 03:02:04 PM 997 7326 0.00 11156.00 1888.00 java 03:02:04 PM 997 8539 0.00 4.00 0.00 java
µÇ¼ºó¸´ÖÆ
UID
PID
kB_rd/s: ÿÃëÀú³Ì´Ó´ÅÅ̶ÁÈ¡µÄÊý¾ÝÁ¿ KB µ¥Î» read from disk each second KB
kB_wr/s: ÿÃëÀú³ÌÏò´ÅÅÌдµÄÊý¾ÝÁ¿ KB µ¥Î» write to disk each second KB
kB_ccwr/s: ÿÃëÀú³ÌÏò´ÅÅÌдÈ룬¿ÉÊDZ»×÷·ÏµÄÊý¾ÝÁ¿£¬This may occur when the task truncates some dirty pagecache.
iodelay: Block I/O delay, measured in clock ticks
Command: Àú³ÌÃû task name
2¡¢Í³¼ÆCPUʹÓÃÇéÐÎ
# ͳ¼ÆCPU pidstat -u 1 10 03:03:33 PM UID PID %usr %system %guest %CPU CPU Command 03:03:34 PM 0 2321 3.96 0.00 0.00 3.96 0 ansible 03:03:34 PM 0 7110 0.00 0.99 0.00 0.99 4 pidstat 03:03:34 PM 997 8539 0.99 0.00 0.00 0.99 5 java 03:03:34 PM 984 15517 0.99 0.00 0.00 0.99 5 java 03:03:34 PM 0 24406 0.99 0.00 0.00 0.99 5 java 03:03:34 PM 0 32158 3.96 0.00 0.00 3.96 2 ansible
µÇ¼ºó¸´ÖÆ
UID
PID
%usr: Àú³ÌÔÚÓû§¿Õ¼äÕ¼Óà cpu µÄ°Ù·Ö±È
%system: Àú³ÌÔÚÄں˿ռäÕ¼Óà CPU °Ù·Ö±È
%guest: Àú³ÌÔÚÐéÄâ»úÕ¼Óà CPU °Ù·Ö±È
%wait: Àú³ÌÆÚ´ýÔËÐеİٷֱÈ
%CPU: Àú³ÌÕ¼Óà CPU °Ù·Ö±È
CPU: ´¦ÀíÀú³ÌµÄ CPU ±àºÅ
Command: Àú³ÌÃû
3¡¢Í³¼ÆÄÚ´æʹÓÃÇéÐÎ
# ͳ¼ÆÄÚ´æ pidstat -r 1 10 Average: UID PID minflt/s majflt/s VSZ RSS %MEM Command Average: 0 1 0.20 0.00 191256 3064 0.01 systemd Average: 0 1007 1.30 0.00 143256 22720 0.07 AliYunDun Average: 0 6642 0.10 0.00 6301904 107680 0.33 java Average: 997 7326 10.89 0.00 13468904 8395848 26.04 java Average: 0 7795 348.15 0.00 108376 1233 0.00 pidstat Average: 997 8539 0.50 0.00 8242256 2062228 6.40 java Average: 987 9518 0.20 0.00 6300944 1242924 3.85 java Average: 0 10280 3.70 0.00 807372 8344 0.03 aliyun-service Average: 984 15517 0.40 0.00 6386464 1464572 4.54 java Average: 0 16066 236.46 0.00 2678332 71020 0.22 cmagent Average: 995 20955 0.30 0.00 6312520 1408040 4.37 java Average: 995 20956 0.20 0.00 6093764 1505028 4.67 java Average: 0 23936 0.10 0.00 5302416 110804 0.34 java Average: 0 24406 0.70 0.00 10211672 2361304 7.32 java Average: 0 26870 1.40 0.00 1470212 36084 0.11 promtail
µÇ¼ºó¸´ÖÆ
UID
PID
Minflt/s : ÿÃë´Îȱҳ¹ýʧ´ÎÊý £¨minor page faults£©£¬ÐéÄâÄÚ´æµØµãÓ³Éä³ÉÎïÀíÄÚ´æµØµã±¬·¢µÄ page fault ´ÎÊý
Majflt/s : ÿÃëÖ÷ȱҳ¹ýʧ´ÎÊý (major page faults), ÐéÄâÄÚ´æµØµãÓ³Éä³ÉÎïÀíÄÚ´æµØµãʱ£¬ÏìÓ¦ page ÔÚ swap ÖÐ
VSZ virtual memory usage : ¸ÃÀú³ÌʹÓõÄÐéÄâÄÚ´æ KB µ¥Î»
RSS : ¸ÃÀú³ÌʹÓõÄÎïÀíÄÚ´æ KB µ¥Î»
%MEM : ÄÚ´æʹÓÃÂÊ
Command : ¸ÃÀú³ÌµÄÏÂÁî task name
4¡¢Éó²éÏêϸÀú³ÌʹÓÃÇéÐÎ
pidstat -T ALL -r -p 20955 1 10 03:12:16 PM UID PID minflt/s majflt/s VSZ RSS %MEM Command 03:12:17 PM 995 20955 0.00 0.00 6312520 1408040 4.37 java 03:12:16 PM UID PID minflt-nr majflt-nr Command 03:12:17 PM 995 20955 0 0 java
µÇ¼ºó¸´ÖÆ
ÒÔÉϾÍÊÇLinuxÐÔÄÜÓÅ»¯ÖªÊ¶µã×ܽá´óÈ« ¡¤ ʵ¼ù+Õä²Ø°æµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡