日期:2014-05-16  浏览次数:20977 次

linux中httpd的cpu占用率非常高,求解决方法
Cpu(s): 74.9%us, 0.0%sy, 0.0%ni, 24.8%id, 0.1%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 8148412k total, 8030588k used, 117824k free, 371544k buffers
Swap: 16771852k total, 196k used, 16771656k free, 6595148k cached

 PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
 7564 web 18 0 616m 64m 5596 S 200.2 0.8 2643:02 httpd
13477 web 18 0 687m 72m 5152 S 200.2 0.9 2642:50 httpd
 7266 web 18 0 626m 65m 5188 S 199.9 0.8 2642:54 httpd

新人小白一枚,现在服务器的CPU占用率太高了,求教怎么查找原因。

------解决方案--------------------
是不是有很多的连接请求?
------解决方案--------------------
很犀利,是apache么。
------解决方案--------------------
使用tx分析
------解决方案--------------------
1、查看apache当前并发访问数:
  netstat -an | grep ESTABLISHED | wc -l
  对比httpd.conf中MaxClients的数字差距多少。
  2、查看有多少个进程数:
  ps aux|grep httpd|wc -l
  3、可以使用如下参数查看数据
  server-status?auto
  #ps -ef|grep httpd|wc -l
  1388
  统计httpd进程数,连个请求会启动一个进程,使用于Apache服务器。
  表示Apache能够处理1388个并发请求,这个值Apache可根据负载情况自动调整。
  #netstat -nat|grep -i "80"|wc -l
  4341
  netstat -an会打印系统当前网络链接状态,而grep -i "80"是用来提取与80端口有关的连接的,wc -l进行连接数统计。
  最终返回的数字就是当前所有80端口的请求总数。
  #netstat -na|grep ESTABLISHED|wc -l
  376
  netstat -an会打印系统当前网络链接状态,而grep ESTABLISHED 提取出已建立连接的信息。 然后wc -l统计。
  最终返回的数字就是当前所有80端口的已建立连接的总数。
  netstat -nat||grep ESTABLISHED|wc - 可查看所有建立连接的详细记录
------解决方案--------------------
m: TIME+ -- CPU Time, hundredths
The same as 'TIME', but reflecting more granularity through hundredths of a second.

意思是百分之一秒的意思么,不懂.

CPU时间如果是多核的话是比较大得,因为一个进程里用到多个核,那么这些时间加起来算作CPU时间,应该是这样.
------解决方案--------------------
CPU时间的话, k: %CPU -- CPU usage
The task's share of the elapsed CPU time since the last screen update, expressed as a percentage of total CPU time. In a true SMP environment,
if 'Irix mode' is Off, top will operate in 'Solaris mode' where a task's cpu usage will be divided by the total number of CPUs. You toggle
'Irix/Solaris' modes with the 'I' interactive command.

看一下.
------解决方案--------------------
不用在意那个TIME+ 感觉就是进程存在总时间
主要是 RES %CPU 
页面访问的效率如何,连接数查询:
netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'

------解决方案--------------------
看看apache的日志文件