Apache uses 100% CPU. Can "ps" command tell me what it is doing?

8,513

Solution 1

My /etc/httpd/conf/httpd.conf file has this section:

# Allow server status reports generated by mod_status,
# with the URL of http://servername/server-status
# Change the ".example.com" to match your domain to enable.
#
<Location /server-status>
    SetHandler server-status
    Order deny,allow
    Deny from all
    Allow from .example.com
    Allow from 127. 192.168.1.
</Location>

Thus if I go to http://192.168.1.1/server-status, I get a page that tells me:

  1. server version
  2. httpd uptime
  3. current CPU usage
  4. of requests being processed and # of idle workers

  5. a grid of what each process is doing
  6. recent requests

    Apache Server Status for 192.168.3.1

    Server Version: Apache/2.2.3 (Red Hat)
    Server Built: Jul 14 2009 06:04:04

    Current Time: Saturday, 17-Jul-2010 10:20:31 CDT
    Restart Time: Saturday, 17-Jul-2010 10:13:12 CDT
    Parent Server Generation: 0
    Server uptime: 7 minutes 19 seconds
    Total accesses: 51 - Total Traffic: 156 kB
    CPU Usage: u0 s0 cu0 cs0
    .116 requests/sec - 363 B/second - 3132 B/request
    1 requests currently being processed, 7 idle workers

    __W_____........................................................
    ................................................................
    ................................................................
    ................................................................

    Scoreboard Key:
    "_" Waiting for Connection, "S" Starting up, "R" Reading Request,
    "W" Sending Reply, "K" Keepalive (read), "D" DNS Lookup,
    "C" Closing connection, "L" Logging, "G" Gracefully finishing,
    "I" Idle cleanup of worker, "." Open slot with no current process

    Srv PID Acc M CPU SS Req Conn Child Slot Client VHost Request
    0-0 20715 0/2/2 _ 0.00 418 0 0.0 0.01 0.01 192.168.3.97 dit GET /server-status HTTP/1.1
    1-0 20716 0/49/49 _ 0.00 128 0 0.0 0.15 0.15 192.168.3.97 dit GET /server-status HTTP/1.1
    2-0 20717 0/0/0 W 0.00 0 520222374 0.0 0.00 0.00 192.168.3.97 dit GET /server-status HTTP/1.1

Solution 2

strace can tell you what a specific process is doing at the level of system calls, but it won't give you a "50-foot view" of what is happening. You will need to piece together the system calls it's using in order to figure that out.

Solution 3

If you have a website with a database backend then you could look in the DBMS what commands are currently running. Maybe this could help you to narrow down where in your code of the website the load is generated.

Else you could increase the log level of the httpd daemon. Then you have more information in the logs.

Share:
8,513

Related videos on Youtube

Sandra
Author by

Sandra

Updated on September 17, 2022

Comments

  • Sandra
    Sandra almost 2 years

    I have a SLES 10 Linux server, and some times it is maxed out by Apache to 100% CPU.

    With ps ax can I see, that Apache have spawned ~50 Apache processes.

    Can e.g. the ps command tell me what each of these Apache processes are doing?

    Or perhaps some other method so I can see what web pages that triggers the problem?

  • TonyUser
    TonyUser almost 14 years
    You may need to set ExtendedStatus ON to see each request