Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Since today my webserver (nginx + php-fpm + mysql on a VPS) is very slow.

htop says:

 1  [|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||100.0%]     Tasks: 63 total, 13 running
  2  [|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||100.0%]     Load average: 11.67 10.95 6.95
  3  [|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||100.0%]     Uptime: 00:18:40
  4  [|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||100.0%]
  5  [|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||100.0%]
  6  [|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||100.0%]
  Mem[|||||||||||                                                137/1280MB]
  Swp[                                                                0/0MB]

  PID USER     PRI  NI  VIRT   RES   SHR S CPU% MEM%   TIME+  Command
 6802 www       20   0 76232 12320  5716 R 27.0  0.9  0:06.48 php-fpm: pool www
 7048 www       20   0 75200 12136  5700 R 52.0  0.9  0:03.64 php-fpm: pool www
 6699 www       20   0 74176 11124  5700 R 27.0  0.8  0:07.36 php-fpm: pool www
 7029 www       20   0 73668 10380  5676 R 42.0  0.8  0:03.52 php-fpm: pool www
 6995 www       20   0 76228 12456  5644 R 42.0  1.0  0:03.98 php-fpm: pool www
 6858 www       20   0 74172 10684  5620 R 35.0  0.8  0:05.52 php-fpm: pool www
 6998 www       20   0 75200 12072  5620 R 37.0  0.9  0:03.95 php-fpm: pool www
 7098 www       20   0 75200 12052  5616 R 42.0  0.9  0:02.33 php-fpm: pool www
 7093 www       20   0 76228 12496  5612 R 37.0  1.0  0:03.02 php-fpm: pool www
 7226 www       20   0 74692 11080  5588 R 32.0  0.8  0:00.66 php-fpm: pool www

CPU: (cat /proc/cpuinfo | grep model)

model           : 44
model name      : Intel(R) Xeon(R) CPU           E5620  @ 2.40GHz
model           : 44
model name      : Intel(R) Xeon(R) CPU           E5620  @ 2.40GHz
model           : 44
model name      : Intel(R) Xeon(R) CPU           E5620  @ 2.40GHz
model           : 44
model name      : Intel(R) Xeon(R) CPU           E5620  @ 2.40GHz
model           : 44
model name      : Intel(R) Xeon(R) CPU           E5620  @ 2.40GHz
model           : 44
model name      : Intel(R) Xeon(R) CPU           E5620  @ 2.40GHz

I think a load of 10 and 100% cpu usage is not normal... How can i fix that?

Edit: I think it could be because of mysql. Here is the PhpMyAdmin Process List:

Show Full Queries   ID  User    Host    Database    Command     Time    Status  SQL query
Kill    3567    bs  localhost   bs  Sleep   2   ---     ---
Kill    3575    bs  localhost   bs  Sleep   1   ---     ---
Kill    3576    bs  localhost   bs  Sleep   1   ---     ---
Kill    3578    bs  localhost   bs  Sleep   0   ---     ---
Kill    3579    bs  localhost   bs  Sleep   0   ---     ---
Kill    3580    bs  localhost   bs  Query   0   Writing to net  SELECT count( id )
FROM messages
WHERE uid_to =345
AND unread =1
Kill    3581    bs  localhost   bs  Sleep   0   ---     ---
Kill    3582    unauthenticated user    connecting host     None    Connect         login   ---
Kill    3583    phpmyadmin  localhost   None    Sleep   0   ---     ---
Kill    3584    root    localhost   mysql   Query   0   ---     SHOW PROCESSLIST

As you see, there is only one thread used, but Google Analytics says:

Right now
429
active visitors on site 

I connect to Mysql per PDO. How can I get more threads?

share|improve this question
    
What is your code doing? There are profilers available for PHP go and take a look what is the most costly. Legitimate clients are connecting? Are you using some kind of framework or custom code? –  cstamas Apr 9 '12 at 21:13
    
@cstamas my code is fetching data from mysql and output it, not really more. I'm not using a framework. Which profiler is good? –  Derp Derpington Apr 9 '12 at 21:16

2 Answers 2

Here is a link to profile your code: StackOverflow: Simplest way to profile a PHP script

share|improve this answer

The load should not be higher than the amount of cores. Currently you have 6, a load higher than this will produce slow responses.

It looks like you PHP scripts are consuming all CPU resources. Profiling them would be a good idea.

You may also increase PHP processing with some caching. I would recommend give a try to eaccelerator which should be easy to enable, and also take a look on nginx caching options.

Another good profiler we used was xhprof : https://github.com/facebook/xhprof but requires a bit more reading to use.

good luck

share|improve this answer
    
Well APC is enabled, and i enabled APD for profiling... But what should I profile? My page works with rewrite and many many different subpages... And how should i read this pprof file? Óò –  Derp Derpington Apr 9 '12 at 22:04
    
So, I enabled xhprof. The main load producer ist Twig... –  Derp Derpington Apr 10 '12 at 14:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.