4

I use wordpress on Ubuntu 12.04 with Nginx + php-fpm on my VPS. There are 2 CPU cores + 4096Mb memory.

I've moved mysql database to another server and set remote access. There are about 300 online visitors at once and php-fpm uses really a lot of CPU:

enter image description here

I also use APC-cache and batcache for wordpress.

php-fpm config:

listen = /var/run/fpm-macradar.sock
;listen.backlog = -1

pm = ondemand
pm.max_children = 30
pm.start_servers = 15
pm.min_spare_servers = 10
pm.max_spare_servers = 20
;pm.process_idle_timeout = 10s;
pm.max_requests = 500

pm.status_path = /status

chdir = /

request_slowlog_timeout = 60s
slowlog = /var/log/$pool.log.slow

request_terminate_timeout = 120s
rlimit_files = 131072
rlimit_core = unlimited
catch_workers_output = yes

;php_flag[display_errors] = off
php_admin_value[error_log] = /var/log/fpm-php.www.log
php_admin_flag[log_errors] = on
php_admin_value[memory_limit] = 128M

Any help will be appreciated

  • You need more CPU, and to do some page caching (e.g. WP Super Cache). – Michael Hampton Jun 6 '14 at 15:26
3

If you have only two CPU and has 30 children in parallel, are carrying on the number of processes that your CPU supports. When there are several children trying to work, each has less CPU, and the result is that everything goes slower, plus the overhead of CPU. This is really important in case like WordPress who use a lot of CPU for each request.

Is better reduce the number of maximum to 2 or 3 children, and nginx which is responsible for managing the queue of connections, queries are not lost.

When FPM is "ondemand" you only need to define pm.max_children, in this case:

pm.max_children = 2 

I hope you find it useful.

| improve this answer | |
  • 1
    You should use more children if your php do external requests (mysql, redis, etc..) and are not using CPU. – Arie Skliarouk Jun 23 '15 at 10:11
3

This is an old question, but it was bumped today by someone editing the post.

While installing a Wordpress caching plugin can be effective, it still means PHP is executed, which is relatively slow. If some of your website visitors are anonymous (ie not logged in) you can do page caching (fastcgi_cache) in Nginx that will avoid calling PHP at all, which dramatically lowers CPU usage and improves response times. The page can be cached for as little as 1 second to be valuable, or if the site is quite static you can take that out to a day or more. The tricky part is clearing the cache when you publish changes, but I have a solution to that - see below.

Have a read of the tutorial I wrote on LEMP. This first part gives you config files to download, they're well commented and the later parts of the tutorial explain them. There's also a great article by Nginx on microcaching.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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