Optimize a small vps server

Optimize a small vps server

by محمد نبيل -
Number of replies: 27
Picture of Plugin developers
What optimization can I do via cpanel for a small ,(4gb ram ) vps server ,I have a very little knowledge about servers and databases ,? 

Is there is a general recommendation ,?

Average of ratings: -
In reply to محمد نبيل

Re: Optimize a small vps server

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers

Visvanath's post is good.

Typically, cPanel provides you a "Terminal" tool, a tool that you will need to make optimization improvements.  The two areas that come to mind are 1) Enabling opcache, and 2) fine-tuning your database via my.cnf.  Sorry, I don't have any videos to help you, but the Moodle docs that Visvanath point you to are a good place to start.

There are probably some server-side settings, but I don't know enough about these to guide you.

Average of ratings: Useful (1)
In reply to Rick Jerz

Re: Optimize a small vps server

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
Thanks Rick! One thing I purposely omitted is to study past discussions in this forum - they are scattered in all corners of the performance and scalability area.

The original question brings me an idea. How about starting a competition? There are many hosting providers who offer VPS free for testing. Select one, and select a small VPS, say 1-2 (dedicated) vCPUs and 2-4 GB RAM. The candidate who gets the maximum out of it wins a prize. The "maximum" could be the max. number of users logging in or opening a given quiz, say within 10 sec.

Won't it be fun?
Average of ratings: Useful (1)
In reply to Visvanath Ratnaweera

Re: Optimize a small vps server

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers
Maybe so, Visvanath. But I don't know how to simulate many students logging in and taking an exam.

I have used this "perspective.php" file, which I got many years ago here on Moodle.org, as a way to get some server statistics.  Put this file into your moodle folder and then go to www.yourdomain.com/yourmoodle/perspective.php.

For example, on my local MAMP Moodle, I get:

Speed test

In one second you can do...

  • 10512000 function calls
  • 59000 16KB files read from disk (cache)
  • 33600 regular expression replaces over 1KB of text
  • 6600 16KB files written to disk (cache)
  • 10110 get_record calls on the course table
  • 8750 insert_record calls on the course table
  • 8350 update_record calls on the course table
  • 1.12 seconds to delete 8750 entries
Script took " . number_format($time,2) . " seconds to execute.

"; ?>

On my VPS, I get:

Speed test

In one second you can do...

  • 18532000 function calls
  • 80800 16KB files read from disk (cache)
  • 33100 regular expression replaces over 1KB of text
  • 4100 16KB files written to disk (cache)
  • 12690 get_record calls on the course table
  • 5070 insert_record calls on the course table
  • 8990 update_record calls on the course table
  • 0.98 seconds to delete 5070 entries

Script took 14.52 seconds to execute.

My VPS appears to be, in general, faster!
In reply to Rick Jerz

Re: Optimize a small vps server

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
Hi Rick, there are all sorts of tools for controlled (simulated) multi-user load szenaries for web servers resp. Moodle. See https://en.wikipedia.org/wiki/Load_testing. JMeter has "native" support on Moodle: https://docs.moodle.org/dev/JMeter.

About the perspective comparison: What is the (virtual) hard- and software on your desktop and VPS?
In reply to Visvanath Ratnaweera

Re: Optimize a small vps server

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers
On my desktop, I have MAMP installed on my Mac, and using Apache in MAMP. Also, this is mySQL.  SSD drive.

On my VPS, it's CentOS 6 (yep, need to upgrade soon) and MariaDB.  My VPS is not using an SSD drive.  (My next VPS will have SSD.)

Both places have the exact same Moodle, Moodle 3.9.1+ (Build: 20200814). (I manually mirror these.)
In reply to Rick Jerz

Re: Optimize a small vps server

by محمد نبيل -
Picture of Plugin developers
Speed test
In one second you can do...

16513000 function calls
68700 16KB files read from disk (cache)
27100 regular expression replaces over 1KB of text
2300 16KB files written to disk (cache)
11240 get_record calls on the course table
2830 insert_record calls on the course table
7430 update_record calls on the course table
1.07 seconds to delete 2830 entries

Script took 14.93 seconds to execute.
--------------------------------------
is this results good ? (good for 20 concurrnt users, 1000 non concurrent)
In reply to محمد نبيل

Re: Optimize a small vps server

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers
Your results are similar to mine. In a typical semester, I might have up to 200 students in my Moodle. My courses are asynchronous, so I cannot say how many of them are taking a quiz (for example) at the exact same time.

A while ago, there was some discussions where people had compared their results from perspective.php. Even the person who created this utility. I can't recall results trying to be correlated with number of users. So this perspective.php scipt is only a guide to the many ways that people might optimize their VPS.
Average of ratings: Useful (1)
In reply to Visvanath Ratnaweera

Re: Optimize a small vps server

by James Steerpike -
Picture of Particularly helpful Moodlers

Does sound interesting. Perhaps restrict it to a single spec say 1 vCPU, 1 Gb of Ram. Might help to settle some questions ie Debian vs Centos, Apache/Nginx/whatever, MySql/Postgresql etc

In reply to James Steerpike

Re: Optimize a small vps server

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
I was only half serious as I suggested this competition. Now I think it could become an informative exercise. What do the others think?

Yes, we need to come up with one, reproducible, server. I don't know how uniform the "cloud" servers of the same hosting are. That is why I said "dedicated vCPU" - whatever that means. Yes 1 vCPU / 1 GB RAM is possibly the lowest end VPS. I am not sure how relevant they are for Moodle. I was wondering between 1 vCPU / 2 GB RAM and 2 vCPU / 4 GB. Although some won't call the latter a "small VPS".

If we need something more geeky, a Raspberry Pi could be the server. Has the advantage that we are not limited to the usual 1 week testing time of hosting providers - and the hardware is consistent. (A 3 B is a 3 B - no versions and generations.) The down side is, since based on ARM architecture, the results may not be valid for x86.

Oh yes, the benchmarks. Here's a standard example: https://tjhunt.blogspot.com/2013/05/performance-testing-moodle.html.
In reply to Visvanath Ratnaweera

Re: Optimize a small vps server

by James Steerpike -
Picture of Particularly helpful Moodlers
It would be interesting to see what can be done in setting up a small VPS. I have seen claims some software is better than others and I would love to see what can be accomplished.
I think the original idea was to compare hosts. That wouldn't be a fair comparison unless the software setup was identical.
I think the 1:1 setup is the minimum requirement for Moodle.  It would also be the most economical to run. My preference would be a Digitalocean VM as the hourly rate could suit an afternoon setting up and running, then snapshotting and deleting the server until a new configuration was required.
In reply to James Steerpike

Re: Optimize a small vps server

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers

I had used that "perspective.php" technique to fine-tune my database (my.cnf).  And I recall using it before and after enabling opcache.  It was my non-technical solution.

Over the next several months, my plan is to experiment with a Digitaalocean VM and another GoDaddy VPS.  I do have Moodle on a Raspberry Pi, too, and maybe I can do some teesting.

I seem to recall discussion about Moodle adding a tool to do a server performance test.  Might this happen when one "shows statistics."  Maybe something already exists?

In reply to Rick Jerz

Re: Optimize a small vps server

by محمد نبيل -
Picture of Plugin developers
unfortunately
all these topic is so advanced to me , i asked the a2hosring.com tech support about opcache , they tell me it is already enabled, " my.cnf" i even do not know what is this
the reason for my question is , on facebook group some one say that he can run concureently 1000 users do exam on a 16 gb ram , i asked him how , he say : with optimization
so i asked for any general optimzation that do require server adminstration knowledge
another thing i remember ,few months ago i need to increse the upload file limit , and did some modifcation
now i do not need that high limit
this is my cureent setting , should i modify some thing ?
now about 500 users , at most 10 concurrently , may increase to 20

In reply to محمد نبيل

Re: Optimize a small vps server

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers
Mohammad, these are general php settings that do not affect performance, but rather affect "capacity," as far as I know. The Moodle docs (Visvanath's link) provides the correct information.
Average of ratings: Useful (1)
In reply to محمد نبيل

Re: Optimize a small vps server

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
OK this is a different question, or a whole set of new questions:
- Opcache: Visit Site administration> Server > PHP info and search for "opcache". You should see something like this:


- "he can run concurrently 1000 users do exam on a 16 gb ram , i asked him how , he say : with optimization" People like to show-off, specially on social media. Just look at this statement and realize how vague it is: No number of CPUs mentioned, no mention of the disk storage systems (spinning disks, what technology, SSD, RAM disk,..), no mention of the stack (LAMP, LEMP), no mention of caching (memcached, Redis, ...) The size of the quiz not mentioned, how staggered the students are when they fetch the exam (all at the same second, or spread in a duration of 10 min).

In short forget it. Or even better, ask the Facebook hero to join our competition (mentioned in my prev. post). wink

If you have a specific need from a synchronous exam, formulate it carefully and ask in this forum for an estimation of the resources.

- About the file upload limit. It has no (direct) connection to server performance. What is the question: You need a higher limit?
Average of ratings: Useful (1)
In reply to محمد نبيل

Re: Optimize a small vps server

by محمد نبيل -
Picture of Plugin developers
Rick Jerz ,Visvanath Ratnaweera -
thank you so much
In reply to محمد نبيل

Re: Optimize a small vps server

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers
Just to reinforce what Visvanath said, yes, I do enable Opcache.
In reply to محمد نبيل

Re: Optimize a small vps server

by Guillermo Dova -
An easy way to improve performance on a WHM/Cpanel installation is adding Litespeed.
Litespeed is a webserver that replaces Apache, and in my experience has added 4x performance (some cases 10x) with the same hardware. Its paid software, price is based on the number of accounts on the WHM. My opinion, worth trying.
In reply to Guillermo Dova

Re: Optimize a small vps server

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
Hi

I saw that you said it elsewhere:
- https://moodle.org/mod/forum/discuss.php?d=409707#p1653601
- https://moodle.org/mod/forum/discuss.php?d=409409#p1653236

Soon you'll get the chance to prove it. Get the same VPS as the others and show that Moodle can pull four times more!
wink
In reply to Visvanath Ratnaweera

Re: Optimize a small vps server

by Guillermo Dova -
Yes! I know, sorry for repeating myself, just sharing my experience.
If you can try it you'll get amazed.
In reply to Guillermo Dova

Re: Optimize a small vps server

by محمد نبيل -
Picture of Plugin developers
if the same cost , buy additional 4gb ram to my 4gb ram , or Litespeed. ?
In reply to محمد نبيل

Re: Optimize a small vps server

by Guillermo Dova -
I'll definitely enable Litespeed. You know what +4gb can do but litespeed improves all the process, so your gains can be higher.
Also if your not satisfied with the results you can just disable it and add more Ram.
I'm sharing some graphics below.
Would be great if you can share some before/after resource usage pics. 
Hope it helps!
Guillermo



This is when covid hit schools and they closed. 
At that time there were 600 active users.




Same Moodle, now ~1200 active users, just added 512k of RAM.
So far works great.





This moodle is installed on a shared hosting account that has CPanel, Cloudlinux and Litespeed enabled.


Average of ratings: Useful (2)
In reply to Guillermo Dova

Re: Optimize a small vps server

by Luz Rodriguez -
Hello, Guillermo!
I've read this thread a couple of times but most of it is beyond me and my non existing knowledge about servers and databases. I'm just a secondary school teacher who's trying to find a not-so-expensive hosting service to take my classes online. A couple of colleagues and I have 1000 students and we believe that the highest number of concurrent users could be 300 when taking a quizz. Someone recommended planethoster so I've taken a look at their hosting plans, however I'm not sure if it's enough to meet our needs. Would you be so kind to help and point me in the right direction towards if the following specs are enough (or close) to what we need?
It's a shared hosting "The World" plan:
32 CPU
64 GB RAM
64 MB/s DISK I/O
and it includes LITESPEED+LSCACHE (I still don't understand how Litespeed works, but since you've tried and recommended it I thought it might be a good idea to mention it)
In reply to Luz Rodriguez

Re: Optimize a small vps server

by Guillermo Dova -
Hi Luz!

  • A couple of colleagues and I have 1000 students 
  • and we believe that the highest number of concurrent users could be 300
I have a few moodle installations with similar numbers (my previous post is one example).
For this requirements I use a shared hosting plan in greengeeks.com (pro or premium plan), and so far the experience has been great.
Don't have experience with planethoster, but of course you can use any provider as long as it works with moodle.
This is what I would suggest to have in mind when choosing a hosting provider:

Some extra notes:
-choose a server location near you ie greengeeks has datacenter in USA and Europe.
-shared hosting that offer unlimited space limits max number of files. If you expect to use assignments this may be an issue.
-shared hosting limits the number of emails sent per hour, moodle can send many emails so this can be an issue.

Hope it helps!

Guillermo

Average of ratings: Useful (1)
In reply to Guillermo Dova

Re: Optimize a small vps server

by Luz Rodriguez -
Thanks, Guillermo.
It really helps a lot since I'm a total newbie and have only had experience with one hosting provider who's already fallen short. I sincerely thank you for taking the time to even list some hosting providers.
Would you mind telling me how the assingments might be an issue when hoster providers limit the max number of files? Does that limit refer to hosted number of files? And knowing this is too much to ask for (only if you happen to have some spare time)but would you please give me your opinion about planethoster's "world plans"? Because you mentioned the hybrid plans but they start at $60.5 a month which is way off my budget (about $32/month). I understand this is not some kind of customer support, but I'm just afraid of making a wrong decision and not being able to afford a way to correct it.
Anyway, You've been great help. I have no words to express my gratitude...maybe some day I'll be able to help someone like the way you're doing it.

In reply to Luz Rodriguez

Re: Optimize a small vps server

by Guillermo Dova -
Glad it helps!

>>Would you mind telling me how the assingments might be an issue when hoster providers limit the max number of files?
In general assignments require users to upload a file to complete the task. Then when the teacher sends feedback it can add annotations over the file, which will generate a new file. So basically for every user participating you can have at least 2 files.

>>Does that limit refer to hosted number of files?
Yes, hosting providers who offer "unlimited space" limit the number of files on the account, they call it "inodes limit". Based on the plan it can be 300k, etc.

>>opinion about planethoster's "world plans"?
I understand you are referring to this https://www.planethoster.com/en/World-Hosting
The specs indicate very good amount of resources, if they are guaranteed to your account it should work ok with moodle.
Anyway I would ask support directly if the plan is compatible with moodle, also would ask about the "inodes" limit on the unlimited space offer.

Choosing a good hosting provider is not an easy task, what I would recommend is do all the questions you need before deciding and once you do, have a daily backup, even more than a daily backup, stored outside the hosting account, just in case you need to move to a new hosting.
good luck!
Average of ratings: Useful (2)
In reply to Guillermo Dova

Re: Optimize a small vps server

by Luz Rodriguez -
Once again, thank you so much! I will follow your advice and ask about the inodes limit and also about Moodle compatibility. If those anwers are positive I think I'll be ready to take the next step in my quest...huge deal for me! I'll also keep in mind the daily backups outside the hosting account.