1

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?

2
  • 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? Commented Apr 9, 2012 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? Commented Apr 9, 2012 at 21:16

2 Answers 2

1

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

0

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

2
  • 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? Óò Commented Apr 9, 2012 at 22:04
  • So, I enabled xhprof. The main load producer ist Twig... Commented Apr 10, 2012 at 14:53

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.