程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Troubleshooting of high CPU consumption of Python applications in Linux

編輯:Python

The company purchased a set of call center system provided by external suppliers , In the process of using, it is found that LOAD and CPU High occupancy , Because there is no source code and the internal implementation logic is not clear , The problem can only be eliminated by observing the consumption of system resources , The following records the troubleshooting process .

1、 adopt top Command to view its CPU Occupy

You can see it load Occupied as “20.14, 16.42, 19.16”, The three numbers represent cpu stay 1 minute 、5 Minutes and 15 Minutes of load,cpu The utilization rate of is also on the high side , Reached 68.8%, Occupy cpu Higher processes ID by 281020.

2、 adopt ps View this app

$ ps aux|grep 281020
root 212891 0.0 0.0 103328 848 pts/3 S+ 15:41 0:00 grep 281020
ipcc 281020 39.5 2.6 1025560 425540 ? Sl 01:18 341:29 /usr/bin/python ./ctiRealtimeCdrMain.py default.xml

The result shows that the application is python application .

3、 View the threads in the process CPU Occupancy

stay top Add -H Parameters , View the threads in the process cpu Victory situation :

$ top -H -p 281020

give the result as follows :

You can see the process 281020 The thread number in is 281042 The thread of wins CPU most .

4、 Trace the execution stack of the process

adopt watch and pstack Command to view the execution of commands in the thread :

watch pstack 281042

You can see from mysql It takes more resources to read data in .

5、 Trace function calls

Further adoption strace Command to verify :

$ strace -f -p 281042

give the result as follows :

A large amount of data is being written to the database (write) And read (read) operation , above pstack The command does not reflect write The problem of , The problem should be in the database read Operationally , The preliminary guess is that the database select There is a problem with the statement , Or there is no index .

6、 Check MySql Slow log

Further inspection MySql Slow log discovery of :

There are a large number of slow query logs ,SQL Full table scanning is used in count、max、min A function like this , Finally, the cause of the problem is confirmed , The rest is to let the other party optimize .


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved