CyberPanel Community

High CPU Usage, 4CPU 8GB RAM

SH
Sirajul Huq #1

Hi, My Website is on WordPress, But when I edit/publish posts, CPU usage goes 100%. Multiple users can’t think about editing or publishing posts on my Website. I was checking server stats using CyberPanel>Server Status>Top Processes and I just noticed that only 1 processor is running and 3 sleeping. Screenshot = Screenshot-2022-10-31-001049 hosted at ImgBB — ImgBB

Server & Hosting info
OS: Cent OS 7
Hosted on Linode (4CPU, 8GB RAM)
Panel: CyberPanel
Website Platform: WordPress
Woocommerce: No
PHP: 7.4
Memcached Extension: Disabled
Redis Extension: Enabled
Too many posts/pages: Yes, 2000/2000+
Cache Plugin: Lightspeed Cache
Installed Plugins: 16 (only useful)

Can someone please help me?

56 replies
jo
josephgodwinke #2

Hello @SuperPSX Happy you are here

Considering you are using PHP I believe this is a PHP sessions issue. Just run as sudo user:

# deletes php 7.4 session folders and recreates them
$ rm -rf /var/lib/lsphp/session/lsphp74; mkdir -p /var/lib/lsphp/session/lsphp74; chmod 1733 /var/lib/lsphp/session/lsphp74
SH
Sirajul Huq #3

Hi Jose, Thank you for your reply. I have a question, Only my 1 Processor working also 3 sleeping? What does sleeping mean?

jo
josephgodwinke #4

Well wrong wording. Processors cannot go to sleep. 3 cores are inactive or isolated through cpuset or VPS setting by your provider. Consult your provider.

Or do you mean you have a bunch of processes that are asleep?

SH
Sirajul Huq #5

Hi, sorry for my bad wording. I’ve attached screenshot where you can see only 1 processor is running and 3 sleeping (inactive). I don’t know how to activate them. I’m facing 100% CPU usage issue when I edit/publish/update posts. I don’t know much about server status I mean how to check and fix it. Please guide

SH
Sirajul Huq #9

Where to put these commands? Putty/SSH?

  1. $ rm -rf /var/lib/lsphp/session/lsphp74
  2. mkdir -p /var/lib/lsphp/session/lsphp74
  3. chmod 1733 /var/lib/lsphp/session/lsphp74

Can I just copy-paste and enter them one by one?

jo
josephgodwinke #10
  1. Open SSH terminal using any client
  2. log in as a sudo user or root
  3. copy this command as is:
rm -rf /var/lib/lsphp/session/lsphp74 && mkdir -p /var/lib/lsphp/session/lsphp74 && chmod 1733 /var/lib/lsphp/session/lsphp74
SH
Sirajul Huq #11

jo
josephgodwinke #12

Test by trying to edit several bog posts or have one wp website updating multiple plugins and another try to upload an image

SH
Sirajul Huq #13

Still same, No changes, I’m gonna upload a video on YouTube for you.

jo
josephgodwinke #14

This might be a reason. I missed it ! sorry am multi-tasking

Am convinced becuase here High CPU Usage, 4CPU 8GB RAM - #7 by SuperPSX you are consuming 5gb of RAM in buffer/cache. This must be some technology hogging the system via caching. Try this

$ systemctl status redis.service
$ systemctl stop redis.service
$ systemctl restart lscpd

Then test your server and take a screenshot of your server stats from cyberpanel

jo
josephgodwinke #16

Just did.

Now post a screenshot of the result of running this command ls /var/lib/lsphp/session/lsphp74

jo
josephgodwinke #19

Well we can rule out the php sessions issue unless you are running multiple php versions. To be sure try this:

# start here copy line bleow me
rm -f /var/lib/lsphp/session/lsphp71/* && rm -f /var/lib/lsphp/session/lsphp72/* && rm -f /var/lib/lsphp/session/lsphp73/* 
# then copy line below me
rm -f /var/lib/lsphp/session/lsphp74/* && rm -f /var/lib/lsphp/session/lsphp80/* && rm -f /var/lib/lsphp/session/lsphp81/*
jo
josephgodwinke #21

Now to address this cancerous component issue that craps a systemd service out: Unable to register authentication agent: GDBus.Error:org.freedesktop.PolicyKit1.Error.Failed: Cannot determine user of subject

Run the commands line by line:

# add user to the group
$ groupadd -g 23 nohidproc
$ usermod -a -G nohidproc polkitd
$ mount -o remount,rw,hidepid=2,gid=nohidproc /proc
$ systemctl restart polkit
# nano /etc/fstab or run it directly
$ echo "proc /proc proc defaults,hidepid=2,gid=nohidproc 0 0" >> /etc/fstab
# add new mount
$ mount -a
$ systemctl restart polkit
tb
tbaldur #23

Can you repeat the actions on the websites, but have a putty window side-by-side running this command, please?

htop

If you don’t have it, you can safely install it with:

apt install -y htop || yum install -y htop || dnf install -y htop

A short video doing this:

  • Putting google chrome and putty side-by-side
  • Running htop on putty
  • Waiting for 15 seconds
  • Do 3/4 actions on the website like update a page and such
  • Wait for 15 seconds

No need to check it the CPU % on cyberpanel, we will trust in htop for that.

tb
tbaldur #26

Exchange Redis with Memcached.
Memcached should help alleviate the database in this case.

After doing so, restart lsws and repeat the video, please.

systemctl restart lsws

Also:
How many users are accessing your website currently?
Do you have any proxy in front, like cloudflare?

tb
tbaldur #30

Install it on the extension you showed above
You should also need to start the service at cyberpanel, but can’t access a panel right now to proper guide you, only in a few minutes

SH
Sirajul Huq #31

I can wait, I need a proper guide. Also, can I keep both PHP extensions Redis and Memcache?

tb
tbaldur #32

What is your OS, ubuntu or centos?

tb
tbaldur #34

Run these commands on the server as root. I don’t know if you have it or not when you first installed cyberpanel, so this is to make sure. In case “groupinstall” command fails, safely ignore and continue with the other commands.

yum install -y lsphp74-memcached lsphp74-pecl-memcached
yum groupinstall "Development Tools" -y
yum install autoconf automake zlib-devel openssl-devel expat-devel pcre-devel libmemcached-devel cyrus-sasl* -y
wget -O lsmcd-master.zip https://codeload.github.com/litespeedtech/lsmcd/zip/master
unzip lsmcd-master.zip
cd lsmcd-master
chmod +x fixtimestamp.sh
./fixtimestamp.sh
./configure CFLAGS=" -O3" CXXFLAGS=" -O3"
make -j
make -j install
systemctl enable --now lsmcd
SH
Sirajul Huq #35

I run all commands and sent you request on Discord (DiezoGaming)

tb
tbaldur #36
  • Mysql optimizations like those suggested by @josephgodwinke
  • Memcached
  • LiteSpeed crawler setup + minor tweaks

Let’s see if it helped when crawler completes (it’s a big website)

tb
tbaldur #38

Will check these with you in a few hours, at work currently

SH
Sirajul Huq #40

Is there anyone gonna help me?

SH
Sirajul Huq #42

I’m using lightspeed cache

jo
josephgodwinke #43

For some reason your wordpress installation is comlaining that it cannot read these headers

X-LiteSpeed-Cache: miss
X-LiteSpeed-Cache-Control:public,max-age=1800
X-LiteSpeed-Tag:B1_F,B1_ 

Can you confirm the homepage is cacheable. maybe your homepage is a non-cacheable page. To confirm use developer tools in your browser or better yet use https://check.lscache.io/.

Post a screenshot here

jo
josephgodwinke #45

No issue here maybe wordpress false positive. Ignore for now unless you can confirm from normal use that caching doesnt work

SH
Sirajul Huq #46

This error keeps showing on Site Health. I had to restart my server because few minutes ago my website was down. I don’t understand what’s going on.

jo
josephgodwinke #47

Ignoring that issue. Post your main log file here when you restart your server I see what is causing your website to crash.

Plus I dont recommend my clients to use LSMCD with LSCACHE I have never made it work but normal memcached works perfectly. That is from experience. Plus you can simple optimize your site using this tutorial forget the extras https://www.cyberhosting.org/how-to-optimize-wordpress-site-using-lscache-plugin/

This is same tutorial I give all my users

SH
Sirajul Huq #48

Thank you for the tutorial. This is something wrong with LightSpeed Cache Plugin settings. Also, I’ve no idea why LightSpeed Cache plugin generates avatars


so many avatar images “wp-content/litespeed/avatar”

jo
josephgodwinke #49

Those are cached avatars. That is what caching plugins do. Generate cached files and store them in a CDN or on your server

jo
josephgodwinke #50

Do a clean install of that plugin

Clear cache first

Go to plugin page → click “deactivate” then “remove ”

You can verify by content /wp-content/plugins/ you should no longer see litespeed-cache directory , and if you do , manually delete it

SH
Sirajul Huq #52

Maybe cache issue from my OpenLight Speed. Can you guide how to setup, Server Configuration “OpenLight Speed”?

jo
josephgodwinke #53

Wrong place buddy check this tutorial Enable LSCache through rewrite rules when LiteSpeed Cache Plugin not available – OpenLiteSpeed

Simple .htaccess would look like:

<IfModule LiteSpeed>
RewriteEngine On
RewriteRule (.*\.php)?$ - [E=cache-control:max-age=120]
</IfModule>

Then setup a way to purge the cache:

$ crontab -e
$ */10 * * * * root find /virtualhost/cache/root/directory/ -type f -mmin +8 -delete 2>/dev/null

This cron job deletes cached files that are more than 8 minutes old every 10 minutes. Since the cache TTL is set at 120 seconds (2 minutes), it is safe to delete these files as they are way past their TTL.

am
amrishhpuri #54

I can install PHP extension (Memcache and Redis), Should I uninstall Redis extension and install Memcache?

jo
josephgodwinke #55

Use one so install what you need only. Personally i prefer redis.

am
amrishhpuri #56

I can wait, I need a proper guide. Also, can I keep both PHP extensions Redis and Memcache?.

.

jo
josephgodwinke #57

Yes ofcourse you can install both memcached and redis

Sign in to reply