Hardware and performance

VPS, too high CPU usage with just one request

 
Picture of Oscar Martin Martinez
VPS, too high CPU usage with just one request
 
I have installed moodle for max 50 non-concurrent users, and I have started with an VPS with 1vcore, 512MB ram.

Just an admin request brings CPU to 100% usage, and the page is served 15secs later. ¿Is this a normal behaviour? I want to know if moodle can eat whole vps cpu in just and admin request (just requesting login screen), or this could be a tunning issue.

(Moodle 3.4 php7)

Apache settings tunned up:

MaxClients = 5
MaxRequestsPerChild = 30
KeepAlive Timeout = 2 (Probar KeepAlive = off)
Timeout = 30

Apache loaded modules:
Loaded Modules:
 core_module (static)
 so_module (static)
 watchdog_module (static)
 http_module (static)
 log_config_module (static)
 logio_module (static)
 version_module (static)
 unixd_module (static)
 alias_module (shared)
 authz_core_module (shared)
 authz_host_module (shared)
 autoindex_module (shared)
 dir_module (shared)
 mime_module (shared)
 mpm_prefork_module (shared)
 php7_module (shared)
What do you think? Any help will be appreciated.

Thanks in advance.

 
Average of ratings: -
Picture of Ken Task
Re: VPS, too high CPU usage with just one request
Particularly helpful Moodlers

512 M is not enough - don't forget the DB server resides on this same instance and even though you say 50 non-current users you can't prevent all 50 users from logging on at one time.  DB server itself should be tweaked to use as much memory as it can and still reserve enough memory for apache **and** the other daemons that run in the OS.

So, am guessing, what you are really asking, is what is the very minimal - judging from what apache mods you are loading.

Minimum of 2Gig ... and that still might peg the CPU in many Admin areas and predict you won't be happy with performance.

Obviously, 4G better ... better yet 8G.

With more memory you can almost run the entire DB in memory - if My/SQL tuned.

'spirit of sharing', Ken


 
Average of ratings: -
Picture of Oscar Martin Martinez
Re: VPS, too high CPU usage with just one request
 

Hi Ken, thanks for your answer

Note that for the momment I do not have a memory issue, but a CPU one.

Even if I increase the memory, CPU will still reaching 100% usage, I will solve memory issues later.

My question it is normal in moodle that just requesting login screen consume the whole CPU of a basic VPS, and take 15 secs to serve the page.

Because if it is normal, I will focus on finding more powerful hardware for my previous tests, and if it isn't I will focus on tunning Apache/PHP/MySQL

Thanks!


 
Average of ratings: -
Picture of Ken Task
Re: VPS, too high CPU usage with just one request
Particularly helpful Moodlers

Know this might sound like avoiding answering your specific question concerning CPU's, but maybe not.

Moodle, as you know, is backended by DB ... even a login process makes queries of the DB ...so maybe you meed to investigate what the hardware/CPU requirements would be for the DB server.

Let that be your guide. smile

'spirit of sharing', Ken

 
Average of ratings: -
Picture of Rick Jerz
Re: VPS, too high CPU usage with just one request
Particularly helpful Moodlers

I have been running my Moodle on a VPS for probably six years or so.  I started with 2GB, which seemed fine.  Then moved up to 3GB, which seemed a little better, and now have 4GB.  I upgrade to 4GB at the same time that I moved to php7 and MariaDB.  My Moodle seems quite responsive now.  In fact, it feels faster, maybe 20%-30%, than my University's server and their LMS (Canvas).

Some of this might depend on the company you buy your VPS from, and I do tune my database.

 
Average of ratings: Useful (2)
Picture of S Moodle
Re: VPS, too high CPU usage with just one request
 

I have been running my Moodle on a VPS for probably six years or so.  I started with 2GB, which seemed fine.  Then moved up to 3GB, which seemed a little better, and now have 4GB.  I upgrade to 4GB at the same time that I moved to php7 and MariaDB.  My Moodle seems quite responsive now.  In fact, it feels faster, maybe 20%-30%, than my University's server and their LMS (Canvas).

Some of this might depend on the company you buy your VPS from, and I do tune my database

Goddaddy offeres 1GB RAM for $30/mo for VPS.  I was wondering if this would be enough for 30 concurrent users (i.e. a typical classroom).


 
Average of ratings: -
Picture of Rick Jerz
Re: VPS, too high CPU usage with just one request
Particularly helpful Moodlers

I would personally be concerned about the only 1GB of memory.  These companies, like GoDaddy, provide discounted pricing, often if you buy more than one year.

What I see right now (today) is that GoDaddy's 1GB VPS is $239US for one year, their 2GB VPS  is $299 for one year, and 4GB is $419.

You can always start with 1GB, see how it goes, and the upgrade.  But it is usually cheaper to buy the product that you really think you need.  I bought the 3-year 4GB product, which ended up costing around $27/month.

(I am not affiliated with GoDaddy, and do own any stock.)

 
Average of ratings: -
Picture of Ken Task
Re: VPS, too high CPU usage with just one request
Particularly helpful Moodlers

Watch out for 'catch 22's'!

No one can define 'typical class of 30'.  Concurrent connections ... mysql (if that's the DB) ... has a default of 151 max connections.   But the thing that might bite is in the actual performance of the DB server as your Moodle content grows.  A VPS I think means the DB server is on the same server as Apache/Webservice and Moodle code.

DB server runs best if it can use a large % of available memory - most of db (if not all) is in memory ... no disk IO or SWAP.

There's the catch 22 .... no one can give numbers for ya.   I maintain a couple of K12 entities and several corps - users anywhere from 11,000 to as low as 5,000.   While all of those servers might run 8Gig or 16Gig and have the same PHP version, the same MySQL version, the same version of Moodle code, usage is very different.   And thus config of MySQL server is different on every one of them.

Example of InnoDB metric:

[OK] InnoDB buffer pool / data size: 4.0G/3.4G

Data is 3.4G ... buffer pools - 4 - 1G per.

[OK] Maximum reached memory usage: 4.0G (26.12% of installed RAM)
[OK] Maximum possible memory usage: 4.2G (27.14% of installed RAM)
[OK] Overall possible memory usage with other process is compatible with memory available

Ok, know we are talking $'s, but ... the bottom line ... better to have enough ... than not enough.   When you discover the 'not enough' is always at a time that causes disruption (no one happy).

On a VPS (standalone) it's a balancing act between web service (Apache/Nginx/whatever) and DB server ... remember that Moodle *is* DB driven.

My 2 cents!

'spirit of sharing', Ken


 
Average of ratings: Useful (1)
Picture of Rick Jerz
Re: VPS, too high CPU usage with just one request
Particularly helpful Moodlers

Very good point, Ken.

Also, I noted that you mentioned some database parameter tuning.  I do tune my database server as best I can, and this is an important step.

(I need to make my video showing what I have done, so that others can try some of the settings and see if they work well for them.)

 
Average of ratings: -
Picture of Visvanath Ratnaweera
Is 1 GB RAM enough for typical 30 user classroom?
Particularly helpful Moodlers
Mr S Moodle

Your question is:
> Goddaddy offeres 1GB RAM for $30/mo for VPS. I was wondering if this would be enough for 30 concurrent users (i.e. a typical classroom).

As others have pointed out 1 GB is considered too low for any "typical" Moodle site.

BTW, this question has nothing to do with the original question, "VPS, too high CPU usage with just one request".
 
Average of ratings: -
Picture of Howard Miller
Re: Is 1 GB RAM enough for typical 30 user classroom?
Core developersDocumentation writersParticularly helpful MoodlersPlugin developers

...it's not even, really, a sensible question. 

1GB is probably enough to run Moodle (as long as you don't want to do backups or anything) but you don't have 1GB. There's other stuff on a server taking up memory. So the answer is "maybe" but you are making life incredibly difficult. If your VPS is of the variety where the database and so on is located elsewhere then I guess it's possible. 

 
Average of ratings: -
Picture of Ken Task
Re: VPS, too high CPU usage with just one request
Particularly helpful Moodlers

@Rick

In the case of DB tweaking, guessing (trial and error) etc. is NOT the way to go.   This is one of those areas where 'one size does not fit all' and a guess at something could result in diminishing returns if not more issues.   That's one of the reasons, I think, that very few have shared their db config here in these forums.

Video?

Why re-invent the wheel?

'spirit of sharing', Ken


 
Average of ratings: Useful (1)
Picture of Rick Jerz
Re: VPS, too high CPU usage with just one request
Particularly helpful Moodlers

Thanks for sharing, Ken.  (Somehow, the first video didn't play for me.  It says that it was disabled by the owner.)

By you sharing these, I assume that you like what you heard.  

 
Average of ratings: -
Picture of Ken Task
Re: VPS, too high CPU usage with just one request
Particularly helpful Moodlers

The llnks were found as an illustration about tweaking DB's.   Yes, I was aware of the first video's issue in viewing and an example of any videos shared by any author.

"like what I heard" ... as long as one is aware of date the videos were made and the versions of MySQL they covered, ***some*** of the information ***might*** be useful.

Would I blindly just copy and paste a setting into a my.cnf file to 'see what happens' ... ***ONLY ON A TINKER BOX*** ... but most of the time what is seen/heard/read is researched further using 'official' MySQL docs for the version of MySQL the server is riunning.

Take the mysqldump command (***note versions***):

https://dev.mysql.com/doc/refman/5.5/en/mysqldump.html

https://dev.mysql.com/doc/refman/5.6/en/mysqldump.html

https://dev.mysql.com/doc/refman/5.7/en/mysqldump.html

https://dev.mysql.com/doc/refman/8.0/en/mysqldump.html

If one just clicks the above links in order, one will see there are changes to the docs between versions.

Note: 8.0.   Am I suggesting one should be running 8.0 .... NO!

As of recent, it has been discovered that MariaDB highest 10.x version is no longer a drop in replacement for MySQL and does require some fixes in Moodle code to be used.

I'll say it again ... one size does not fit all ... each  server is different ... while one can give hints/suggestions about DB tweaking, it's still up to the OP to run whatever on their own DB server to see what *might* be tweaked or could be tweaked.

When you make your videos of 'Rick's Way', keep in mind, they probably should be revisited often as you might be sending 'trusting' Moodlers down a rabbit hole.

That's one of the reasons I hate to document ... in short time frame, the info shared/documented could be out of date and require changes/notes/catch  22's listed, etc., etc..

However, you are free to do as you wish. ;)

'spirit of sharing', Ken



 
Average of ratings: -
Picture of Rick Jerz
Re: VPS, too high CPU usage with just one request
Particularly helpful Moodlers

Good points, Ken.

"As of recent, it has been discovered that MariaDB highest 10.x version is no longer a drop in replacement for MySQL and does require some fixes in Moodle code to be used."

So far, I have been successful running MariaDB 10.1.30 on my production server.  I have also been able to backup this database, and import it into MySQL 5.6.35.  But I will note your comment and be careful in the future.

"When you make your videos of 'Rick's Way', keep in mind, they probably should be revisited often as you might be sending 'trusting' Moodlers down a rabbit hole."

Keeping videos current is always challenging when technology is involved!

Thanks.

 
Average of ratings: -
Picture of Visvanath Ratnaweera
Re: VPS, too high CPU usage with just one request
Particularly helpful Moodlers
Hi Oscar

Others have told you how it is with Moodle.

I'm just curious. Is your purpose is academic, like finding the smallest Moodle VPS? If that is the case, Apache is simply too big. You need to follow the reverse proxy + PHP-FPM line of Nginx, for example, for the web server. On the database side you need to get the data in to RAM, the file system access of low end VPS is too slow (even if they are branded as SSD)! Well, where is the RAM for that?
;-(

Otherwise, do a small calculation of the upgrade price for a 2 GB VPS in the order of USD 200 p.a. against the time you will spend in "tuning" the system and the suffering of the users (provided that the server will have users other than the 'admin').

Questions. You said:
> Note that for the momment I do not have a memory issue, but a CPU one.
>
> Even if I increase the memory, CPU will still reaching 100% usage,

What is the evidence?

If you have increased the memory (to how much?) have you come down again?

You have gone through the most obvious mistakes, right? For example, theme designer mode, admin against normal user, caching mechanisms, .. Also you ran the built-in performance and site info reports? They are all in the forum documentation. I mention them because I noticed that you've just registered on this forum.
 
Average of ratings: Useful (1)
Picture of James Steerpike
Re: VPS, too high CPU usage with just one request
Particularly helpful Moodlers

Maybe I am just a cheapskate but I have found 2GB VPS around  $5 a month - and lower. They do run my Moodle even with 40 logged on and stay up.

At this price you are getting an OpenVZ server which shares the kernel and you need to be comfortable with using only SSL and text commands but I find that satisfactory. Makes me wonder why people use shared hosting - or an underpowered VPS.

 
Average of ratings: Useful (1)
Picture of Visvanath Ratnaweera
Re: VPS, too high CPU usage with just one request
Particularly helpful Moodlers
It is the GUI, imagine people have gone back to Windows as web server(!), and of course the advertising and lobby.

P.S. You meant SSH (Secure Shell), not SSL (Secure Sockets Layer), right?
 
Average of ratings: -
Picture of James Steerpike
Re: VPS, too high CPU usage with just one request
Particularly helpful Moodlers

SSH.....I should know as I did a  very useful course on Coursera on bash programming and it introduced me to the bash shell on Windows 10 so I use a ssh user@address to get to my servers.

Windows for the desktop, Linux for the server!

 
Average of ratings: Useful (1)
Picture of Oscar Martin Martinez
Re: VPS, too high CPU usage with just one request
 

Great James!

That is a success case of my own requeriments!

smile

Thanks a lot!

 
Average of ratings: -
Picture of Oscar Martin Martinez
Re: VPS, too high CPU usage with just one request
 

Most obvious mistakes, Episdode I: Theme designer mode big grin. Thanks a lot for your help, I had just missed that.

Now it works ok, not starving the CPU. I will check which hardware I need further, when we have created the course, and so we can do load tests.

Meanwhile, I will be checking everything that you helped me with.

Can you give me a bit more information about "admin against normal user"? I did not find this or similar topic in docs.

I will run the tests, also.

Thanks a lot!

 
Average of ratings: -
Picture of Visvanath Ratnaweera
Re: VPS, too high CPU usage with just one request
Particularly helpful Moodlers
Glad that it was so easy!
smile

The second of the most obvious mistakes, "admin against normal user", is the fact that the super user 'admin' consumes much more power than a non-privileged user. Create a new "normal" user and see whether you notice a difference.

After all that, don't expect wonders. (Listen to Ken ;))

BTW, I notice that you've avoided some of my questions. As you wish!
;-\
 
Average of ratings: -