4

My Ubuntu 18.04 server with 2GB of RAM and 2 CPU cores experiences major CPU load spikes when someone accesses the Wordpress site that the computer serves. This slows down the website very much.

Below is the output from a top command

top command output

In the screengrab above, the load is shown to be 3.8, but most of the time it rises to 5.0 - 6.0.

The server runs Apache2 in Event MPM, MySQL 8 and PHP7.3. Redis caching is also present.

Due to this load spike, my website times out with a Cloudflare 524 error and I'm unable to log into wp-admin.

Is there any way to fix this?

EDIT:

Here is a link to the output of the MySQLTuner tool run on this system. https://pastebin.com/awxRidr3

And here is the link to the output of cat /proc/meminfo. https://pastebin.com/E9uvq5A9

SidS
  • 145
  • 5
  • Page caching for anonymous users can provide a good speed-up, since most Wordpress sites are mostly status. Use CloudFlare to do caching of static resources. My Amazon Linux server has 5% of a CPU core (bursting to 100%), 512MB RAM, 512MB swap, and serves six low traffic websites easily. Wordpress / PHP is VERY CPU hungry, but it shouldn't stop you SSHing in if it's busy. Reduce the number of PHP workers to the number of threads your computer has to prevent overloading the system. – Tim Dec 12 '19 at 23:32

1 Answers1

4

Performance issues can be any number of things. Investigate everything and keep an open mind.

73% IO wait suggests the storage system is a limiting factor.

Install bpfcc-tools and run filetop to see reads and writes by file. Classify what gets lots of I/O: database, uploaded content, the web application, whatever. Use ext4slower (or xfsslower) scripts to find file system operations that take more than a few milliseconds.

Possible actions:

  • Migrate to solid state disks if you have not already
  • Enable and review the slow query log
  • Consider a separate database host, possibly a managed service
  • Find some of the many WordPress checklists and evaluate their suggestions
  • Do a capacity analysis and determine if it is time to scale out or up.
John Mahowald
  • 32,050
  • 2
  • 19
  • 34
  • Thanks for the answer! I think the drive that the OS and all the software is installed on is the major bottleneck. I am currently using a USB memory stick to run Ubuntu. I think I should definitely invest in an SSD upgrade. I do have a 40GB HDD (really old), do you think that it would be faster if I use the HDD while I source an SSD? – SidS Dec 07 '19 at 15:38
  • I wondered why there was a usb-storage thread in state D. Try everything you have, spindle and solid state. Typical USB storage sticks have miserable write performance. Although one spindle would be less than 100 IOPS and not amazing either. – John Mahowald Dec 07 '19 at 19:44
  • 1
    (As a stop gap measure) Do you have swap enabled? Try changing VM.swappiness to 5. – davidgo Dec 07 '19 at 20:31
  • Please post COMPLETE MySQLTuner.pl (perl) report after 24 hours of UPTIME so we get some idea of your use of MySQL. With a 2G server size, why would you need to use KHUGEPAGED? Disable anything HUGEPAGE, you do not have the RAM to support it. – Wilson Hauck Dec 08 '19 at 13:58
  • @davidgo I do have swap enabled, I will be moving to the 40GB HDD, that should make things faster, if it doesn't I might as well disable swap. – SidS Dec 08 '19 at 21:29
  • @WilsonHauck, Hi, I'm not quite sure what HUGEPAGE is, please could you elaborate. – SidS Dec 08 '19 at 21:31
  • @SidS if you have swap enabled on a standard Ubuntu 18.04 install you definately want to enable vm.swappiness. (Google it, its fairly easy to do, and has been covered to death). It won't solve your problem but it will mitigate it. You do not want to disable swap as setting vm.swappiness close to 0 has all the upsides with none virtually of the downsides of disabling swap. – davidgo Dec 08 '19 at 23:39
  • @sids On your TOP list posted, it is PID 29 - khugepaged. Google search for ubuntu disable hugepage for ideas on disabling the overhead. Please let me know when you have posted a complete MySQLTuner report, Thanks – Wilson Hauck Dec 08 '19 at 23:46
  • Please post TEXT results from Ubuntu Command Prompt of cat /proc/meminfo and we can tell what has been set up on your server for the feature. – Wilson Hauck Dec 09 '19 at 19:52
  • @WilsonHauck Hi, I've added both the complete MySQLTuner report and the output from the cat /proc/meminfo – SidS Dec 12 '19 at 22:35
  • @sids #1 get the USB device out of your operations ASAP - not a good idea to run an OS from USB - other than to prove it CAN can be done - but not well. #2 from meminfo, there are NO HugePages_Total in use, do not know why it is listed in TOP. #3 from MySqlTuner report detected Joins performed without indexes: 5996 in 5d 22h can be corrected with indexes. #4 I wonder why Aborted connections: 1,461 in 5d? Disclaimer: I am the content author of website mentioned in my profile, Network profile where we have downloadable FREE Utility Scripts, FAQ and contact information. Get in touch, please. – Wilson Hauck Dec 13 '19 at 02:18
  • @JohnMahowald - Moved everything from my USB stick to the 40gb HDD. Everything is much faster and the IO Wait times only peaks up to 40% max. Huge speed improvement, now I'm planning to move everything to a new HDD with a really fast RPM, or an SSD. Thanks! – SidS Dec 14 '19 at 16:27
  • @WilsonHauck, Might take a look at those free scripts. As of now, website performance has increased exceptionally after moving from a USB stick to the HDD. – SidS Dec 14 '19 at 16:29
  • @sids Wonderful news. HDD for OS, MySQL and other apps PLUS SSD for database storage would be best combo. Looking forward to your download of our Utility Scripts to assist with performance tuning. – Wilson Hauck Dec 14 '19 at 17:51