简体   繁体   English

python请求占用100%的cpu

[英]python requests taking 100% of cpu

One of our API servers has an issue with CPU usage. 我们的其中一台API服务器的CPU使用率存在问题。 API is written in python and configured in ubuntu AWS EC2 instance. API用python编写,并在ubuntu AWS EC2实例中配置。 This application uses Python 2.7 and Django 1. This can be accessed through port 80 by proxy passing. 该应用程序使用Python 2.7和Django1。可以通过代理传递通过端口80进行访问。 Sometimes we are getting 499 requests in our logs that time $htop value shows 100% CPU usage in the server. 有时我们在日志中收到499个请求,而时间$ htop值显示服务器中100%的CPU使用率。 The only python requires are running in this server. 唯一的python要求正在此服务器上运行。 But in AWS cloudwatch monitoring, it is not. 但是在AWS cloudwatch监控中却不是。 only 40% to 50%. 只有40%到50%。

PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND
23086 root      20   0  815776  96056  12792 S  100  4.7   2:43.12 python                                                                      
24041 root      20   0  292756  92820  12696 S  8.0  4.5   0:33.73 python                                                                      
24072 root      20   0  815656  95696  12792 S  5.3  4.7   0:28.27 python 

Please help TIA 请帮助TIA

You most likely using a dual core server, and your python process is single threaded and using as much CPU as it can (one core). 您最有可能使用双核服务器,而python进程是单线程的,并且使用了尽可能多的CPU(一个核)。

Hence the discrepancy between htop and cloudwatch: 因此,htop和cloudwatch之间的差异:

  • in htop "100%" means "one cpu core", so the total CPU usage can be up to 200% 在htop中,“ 100%”表示“一个cpu内核”,因此总CPU使用率最高可达200​​%
  • in cloudwatch the reported cpu usage is the average between the cores, which explains the 50% (one core at 100%, the other at 0%) 在cloudwatch中,报告的cpu使用率是内核之间的平均值,这解释了50%(一个内核为100%,另一个为0%)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM