-1

My server, Ubuntu 14.04.4 LTS, is running at high load, currently running a single site with Nginx + Wordpress + W3 Total Cache + Memcached.

I'm not sure if mysql is causing the workload issue.

Here are the screenshot for htop and mytop

I can tell from htop that memory is not the bottleneck here.

It shows that mysqld and php-fpm are the processes using the highest resource.

Can someone tell me how to interpret mytop and does it look normal?

1  [|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||93.6%]     Tasks: 361, 71 thr; 12 running
2  [|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||95.6%]     Load average: 19.52 22.34 19.45 
3  [|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||97.5%]     Uptime: 71 days, 08:54:08
4  [|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||96.8%]
Mem[|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||5570/8015MB]
Swp[                                                                         0/0MB]

MySQL on localhost (5.7.13)
load 23.92 23.12 19.55 43/528 10012 up 7+04:05:52 [05:30:09]
Queries: 103.6M   qps:  175 Slow:  0.0  Se/In/Up/De(%):  79/00/00/00 
Sorts:  8693 qps now:  356 Slow qps: 0.0  Threads:  37 (   1/   3) 79/00/00/00 
Key Efficiency: 50.0%  Bps in/out: 28.8k/532.7k   Now in/out: 57.6k/880.7k

Or should I be looking at using fastcgi_cache instead to avoid hitting php-fpm?

UPDATE:

I have tried restarting all my services, Nginx, PHP-FPM, and MySQL.

I'm working on a site with rather high traffic, 1.1M daily pageview impressions.

After restarting all the services, the resource goes up pretty quick again.

During off-peak hours, the load value is max out at around 4.00 on my 4-core machine.

During peak hours, the load is at 20 to even 40.

KDX
  • 233
  • 2
  • 12

1 Answers1

0

That mytop output doesn't tell us what's using your CPU - or at least I don't understand it. I just use top / htop.

I wrote a pretty large six part tutorial on Nginx, Wordpress, and caching. The ideas in that should help you optimise your server.

In short you should avoid at all costs hitting PHP. Static or semi-static public content can be cached from 1 second (micro-caching) to 1 week, reducing load on your server hugely. This can increase throughput by two orders of magnitude and reduce response time a lot as well. I also use a CDN, CloudFlare free tier, for static resource caching and to speed DNS lookups.

Tim
  • 31,888
  • 7
  • 52
  • 78
  • Is there a way to find what what is hitting PHP? Or even what section of the Wordpress code/plugins/template/queries is draining all the resource? In `htop` it only shows something generic. I'm already using W3 Total Cache with Memcached. It should supposingly speed things up. – KDX Aug 15 '16 at 01:24
  • Restart Nginx, PHP-FPM, and MySQL, hit the server for a minute or so with a bunch of requests, then look at CPU time of all the processes. I bet you'll see it's PHP. The solution is to avoid invoking PHP if at all possible, it's relatively slow. It's MUCH quicker to fetch a page out of a RAM cache than it is to call PHP, connect to the database, create HTML, and stream it back. – Tim Aug 15 '16 at 01:26
  • I did that a number of times already. Since I'm working on a site with rather high traffic, 1.1M daily pageview impressions. After restarting, everything goes up pretty quick. During off-peak hours, the load value is max out at around 4.00, during peak hours, the load is at 20 to even 40. That's why I'm looking at a way to figure out what's the cause. I know I can try Nginx fastcgi_cache implementation on the server level to avoid hitting php-fpm, but I would like to find out the cause first before proceeding to this step. – KDX Aug 15 '16 at 01:34
  • If you've done it already please edit your post to share the information. No restart really needed, just post the total CPU time consumed by Nginx, PHP-FPM (all processes), and MySQL. That will tell you what's taking the resources. It will very likely be PHP. The solution will be caching, I already shared a link how to implement caching. You really haven't given enough information to help solve your problem, if this persists you risk your question being closed by a moderator. – Tim Aug 15 '16 at 01:53
  • Question update with extra information. How do I show the total CPU time consume by each process? Using `ps aux | grep php-fpm` is giving me 325 php-fpm process at 0.7% CPU time each. Is this sufficient information to tell PHP is the bottleneck? Nginx has 3 processes with a combined total of less than 1% CPU time, and mysqld is a single process at about 18.7% CPU time. – KDX Aug 15 '16 at 02:33
  • Your question update doesn't have per-process CPU usage. Your comment suggests PHP is taking 227% CPU and mysql is taking 18%. That confirms my theory that it's PHP. Caching inside Wordpress still means PHP has to be hit. Are most of your users anonymous, or are they logged in? You basically can't cached logged in users. – Tim Aug 15 '16 at 02:48
  • I didn't update per process CPU usage because I'm not sure how to show it properly for aggregated result, I don't want to paste hundreds of lines to occupy the question space. And yes, all users are non-login anonymous users. So the idea is taking the PHP to the Nginx caching level to avoid Wordpress hitting it? – KDX Aug 15 '16 at 02:58
  • Yes. Cache pages in Nginx so PHP isn't invoked, like I said in the tutorial I linked to in my answer, which is Wordpress but it will be very similar. – Tim Aug 15 '16 at 03:08