Need help optimizing Moodle install on shared server

Need help optimizing Moodle install on shared server

by Marcos Codas -
Number of replies: 31

Hello! 

I manage a Moodle installation for a local university. The installation is hosted on Hostgator shared hosting plan. It was working fine for the number of concurrent users we used to get (10 at most), but since COVID, they've moved most of their teaching to this platform. 

PLATFORM: http://avimed.medicinauni.edu.py

Now, they need to be able to provide service to 70 concurrent users (out of a total of 700 or so), and when they are trying to do exams, they overload the server. 

See video: 

Leaving aside the fact that this particular user was a bit heavy handed with clicking, the issue remains that not all 70 students can take exams at the same time without overloading the server. 

I'm running the out-of-the-box installation of Moodle 3.2.x.

I would really like to optimize the installation so that it does not need a hardware upgrade, which, considering it's a publicly funded university, would certainly mean that other areas would need a budget cut. 

Please note that due to it being a shared hosting environment, I cannot turn PHP accelerators on. 

Thank you in advance!

-Marcos. 

Average of ratings: -
In reply to Marcos Codas

Re: Need help optimizing Moodle install on shared server

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

In general, "hosted servers" are not adequate to run Moodle.  My guess is that this is why you have only Moodle 3.2, which is already three to four years old.  And my guess is that you will never be able to handle 70 concurrent users, either.

To begin your goal of optimizing your installation, try getting Hostgater to upgrade your Moodle to the current 3.9.  That's the first step that I would recommend.  Otherwise, what you might be trying to do is analogous to optimizing a Model-T Ford to compete with current Indy-500 race cars, and you can't put on better tires, either.

I am not an expert about this, these are just some ideas from my own experience and listening to others.  Others here on Moodle.org might be able to coach you better than I can.  I don't use Hostgater, so perhaps they have everything under control.  Asking them to upgrade your Moodle to 3.9 will let you see.  If they say you cannot, then abort.

In reply to Rick Jerz

Re: Need help optimizing Moodle install on shared server

by Marcos Codas -
Hello, Rick! Thank you for the suggestion. I'll proceed with the update and see where that lands me in terms of performance.
In reply to Marcos Codas

Re: Need help optimizing Moodle install on shared server

by Ken Task -
Picture of Particularly helpful Moodlers

Covid19 has changed many things ... think of this ... if site cannot do what needs to be done for online classes, your student enrollments will decrease ... fewer students equates to less $ for entity.    Run the risk of not surviving.

Since entity is online more than F-2-F, the cost of maintaining lecture halls/classrooms should be reduced ... those funds could go towards a more robust hosting situation.

You don't have to get top of the line hosting ... just enough ...  if your shared hosting isn't enough now can your entity afford not to invest more in hosting a VPS?

Shared hosting is limited ... and since resources on a shared host apply to all customers, providers are hesitant to do anything 'special' for one customer ... even if in an 'industry' such as education.

Shared hosting means you don't have access to config tweaks ... upwards.

Dunno if you have a choice in the matter.

My 2 cent thoughts!

'SoS', Ken


In reply to Ken Task

Re: Need help optimizing Moodle install on shared server

by Marcos Codas -
Hello Ken!

As I said, this is a public university, so they'll have the same amount of money and students regardless. But they do need to reallocate resource to make their online presence more robust. I've suggested VPS already, and waiting to hear back from the Dean. But I thought I could at least try a software solution and see if there was a chance of running this in our current environment without asking the school to spend more.

If this doesn't work, I think I will push for on-site hardware instead, but as I said, it would be best to hopefully get some kind of headway or upgrade in usability via software tricks

Example:
limiting PHP running times, perhaps? better CPU resource allocation? I think it's a CPU issue or RAM issue, so perhaps limiting those factors could ensure server resources are better split between student instances?

Just thinking of possible solutions that I've implemented in other software platforms that might work here.
In reply to Marcos Codas

Re: Need help optimizing Moodle install on shared server

by Ken Task -
Picture of Particularly helpful Moodlers

'Counter example': concurrent users.  One of the **major** tweaks involves database server.  Database servers run best when they can occupy 80% of available memory (according to Percona ... experts in MySQL ... Google that bit of info.)

One tool that will help determine settings for DB is MySQLTuner.pl.   But ... even if you could install it on shared hosting (it's perl and shared hosting generally has perl) one cannot run Tuner as the super user of the DB server.   Thus cannot look at important metrics and recommended settings ...

Here's one: InnoDB buffer pool / data size - buffer pool needs to be larger than data size.   If data size is larger then pool ... poor performane is a result.

Another ... DB max connections ... relates to concurrent connections ... default is normally 151 ... heck your server is struggling with 70!

Since, on shared host, you cannot change global parameters of the DB server by editing my.cnf.   You get what you get.   Can't squeeze any more juice from the lemon.

Another 'counter example' ... the running of cron which optimizes the DB tables.   Recommendation is to run cron job every minute ... that's once per minute.   Typical of shared hosting setups allow running of a cron job only once per hour.

Again ... You get what you get.   Can't squeeze any more juice from the lemon.

BTW, upgrading to 3.9.0 .... is a bad idea ... for one it's a .0 ... right out the shrink wrap ... even if declared to be 'stable' ... every version I've ever worked with declared stable had bugs/regressions, etc. at .0.   Fixes to those isn't going backwards but upwards ... a .1 and a .1+ is coming soon for 3.9.0.   On shared hosting updates and upgrades sucks!  And asking technical persons who have been told to draw the line at internals to customer apps to do it for you?

Bottom line ... squeeze all you like ... not gonna get one more drop of juice ... period.

'SoS', Ken

Average of ratings: Useful (1)
In reply to Ken Task

Re: Need help optimizing Moodle install on shared server

by Marcos Codas -
Thank you so much for that fantastic bit of info, Ken! So, you think the error that they're getting is related to DB and RAM? I thought it might more likely be related to CPU. I've had experiences before where an excess of concurrent PHP requests send the CPU into a frenzy. That's why I thought that it might be worth optimizing the PHP behavior so that they are either more spaced out, or limiting the resources each request has access to, etc.

What are your thoughts on those scenarios? Is it unlikely to be a CPU issue?
In reply to Marcos Codas

Re: Need help optimizing Moodle install on shared server

by Ken Task -
Picture of Particularly helpful Moodlers

Have you shared the error they are getting?   Didn't see it!

Concurrent is 2 fold ... obviously hit to web service running php script .. but behind that ... queries to DB.  Evidence could be in web server error logs - clips of which you also have not shared.  Quiz is a heavy hitter ... both in terms of php scripts and DB queries.

Now cron job you should be able to see and should speak for itself.

Have you set the cron job to execute once every minute?   Will system allow that?

Have you mentioned where this site is hosted?  What provider?  What shared hosting package they have?  What specs there are to server?

All scenarios ... any  scenario - can't get blood out of turnip!

Dunno what analogy to use ... cause we ain't seen any real info from ya.

We can talk this to death .... or you can ... cause I've said my piece and offered 'free' advice - for whatever that's worth.

'SoS', Ken


In reply to Ken Task

Re: Need help optimizing Moodle install on shared server

by Ken Task -
Picture of Particularly helpful Moodlers

https://www.hostgator.com/vps-hosting

VPS hosting
$19.95 2 Gig RAM/2 Cores CPU 120GB disk 1.5 TB bandwidth
$29.95 4 GB, 2 Core, 165 DB space 2 TB band
$39.95 8 GB 4 cores 240 Gig 3 TB

Whomever is running the show is greedy!

In reply to Ken Task

Re: Need help optimizing Moodle install on shared server

by Marcos Codas -
As for pricing, let me put forth some information:
1. The $39.99 pricing is when you pay upfront for 3 years, so really, you need to fork out $1439,64 out of the gate if you want that monthly rate.
2. If you want to pay-per-month, the rate jumps to almost $90/month.
3. $90 pays almost 1 week's salary for a nurse here in Paraguay
4. $90 pays for all EPP for at least 5 nurses for 1 month here in Paraguay
5. $1439,64 pays a doctor's salary for 1 month here in Paraguay.

While I really, really appreciate the price/performance comparison, I'm aware of how it looks to people in other countries. It might be an easy choice to make. But it falls to me to recommend whether we upgrade a server, or pay a doctor. And nobody is greedy. We're all trying to make this work while understanding that we're in the middle of a pandemic, in a developing country, with already dwindling resources.

I wouldn't be able to sleep with my conscience if my first reaction to a problem was to put more money into it, knowing that it might cost a doctor or a nurse vital, life-saving resources.
In reply to Marcos Codas

Re: Need help optimizing Moodle install on shared server

by Ken Task -
Picture of Particularly helpful Moodlers

Servers are machines ... they have no way of considering the financial situation of the entity leasing.   Although, you might ask provider to 'step up' - anyone tried that?   All provider can do is say no.

Ya don't have to remind me about pandemic ... wouldn't say that USA is in good shape there at all.

Still though ... the trade off ... getting a server to handle might be equal to the salary of one doctor/nurse, but in training 100+ doctors/nurses that will have a direct impact upon *thousands* of patients ... justifies the cost.

Now let's talk what's possible with shared hosting that can't handle more than 70 (your number) taking a test at a time .... create groups and groupings ... divide students into group A, B, and C - no larger than what server can handle on test day (70?  we really don't know ... I certainly don't know ... just going with that number cause that's the number you mentioned).  More groups as needed ... D an E.  No group more than 'the number'.

Create test and duplicate ... first test for group A only.  B and C cannot enter.  Second test for B only.  Third test for C only.  If need be ditto D and E.

To assure enough resources, schedule the test per group ... Group A takes test on Mon.  Group B takes test on Tues.  Group C takes test on Wed.  Don't have to worry about cheating as test have questions shuffled.

In Tx, when high stakes testing days were scheduled, students/teachers not taking the test were restricted from using Internet ... you might also have to ask all other Groups not taking a test, to refrain from accessing the site.

'SoS', Ken


In reply to Marcos Codas

Re: Need help optimizing Moodle install on shared server

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers
Yep, Marcos, this is how hosting companies price their products. The numbers that I gave you are less than HostGater, but yes, your $1439.64 is on target with other companies. But that $1439 is still for three years. I actually pay a bit less than this every three years, somewhere around $1,300, and I pay for this with my own funds. My school uses Canvas, which would be free to me. So I too had to adjust my priorities.

So, let's review where you are at. Your experiment with a cheap server seems over -- it doesn't work.  You have proved that it will not meet the school's requirements.  Your school does not have the funds to host Moodle on a VPS that might work.  MoodleCloud is also too expensive.  I also doubt that you will be able to afford a Moodle Partner, but you can probe on your own.  And not to be too judgemental, you probably don't have the resources to run your own server with Moodle.

I would say that you only have a few alternatives left.
1) Tell your school's administrators that you are not a magician.  You can't make something out of nothing.  Abort.
2) Look at some of the other low-cost of free learning systems (not the major ones, they are too expensive.)
3) Suggest to your school's administrator that they need to hire a Moodle Partner.  Explore so that you can give them a price.

I am out of ideas for you, but will still be watching for an opportunity to help.
Average of ratings: Useful (1)
In reply to Rick Jerz

Re: Need help optimizing Moodle install on shared server

by Marcos Codas -
Hi Rick!

I actually run a server for other stuff, so I'm looking into that as an alternative. No judgement felt, though! I'm sure I still have much to learn.

I suggested staggered tests before I ever posted this, but professors seem to be running into issues, either with time to do them, or with students copying, or a combination.

I've passed along recommendations based on my own experience and what I saw in this thread. At any rate, a good opportunity to still optimize the platform (upgrading to a stable, recent build, cleaning, establishing proper cron, double checking PHP caching, etc).

Thank you all.
In reply to Marcos Codas

Re: Need help optimizing Moodle install on shared server

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers
Ah, if you are comfortable running your own server, then see if you can get another one running. I am not comfortable running my own server, but I have seen what appears to be some great docs about it.  For example: 

Step-by-step Installation Guide for Ubuntu

In reply to Ken Task

Re: Need help optimizing Moodle install on shared server

by Marcos Codas -
Hi, Ken!

I shared the error in the video in my OP. All shared hosting plans on Hostgator have the same specs (a 32-core Opteron shared among all clients, no more info than that). I also included Moodle version and PHP version. Unsure what other info you'd need?
In reply to Marcos Codas

Re: Need help optimizing Moodle install on shared server

by Ken Task -
Picture of Particularly helpful Moodlers

@Marcos ...

I don't need any other info ... took a quick look at the video ... didn't understand the audio ... don't have to ... as even the 'top of the line' shared hosting isn't good enough for what you are wanting to do .... I've all ready told ya, move to a VPS ... even bolded the one I thought best.    Am done ... can do no more for you.

Good luck!


In reply to Ken Task

Re: Need help optimizing Moodle install on shared server

by Marcos Codas -
Thank you for your kind help, Ken. I appreciate it.
In reply to Marcos Codas

Re: Need help optimizing Moodle install on shared server

by Usman Asar -
Picture of Plugin developers Picture of Testers
Marcos, shared hostings can be used for staging servers or when starting new, but definitely not in scenario where it's being hammed with concurrent users and even them taking quizzes (quiz is real test of moodle's ability to handle users - in my opinion).

moodle 3.2 required PHP 5.6.x, since PHP 7.x came out there was tremendous performance uplift in any application making use of PHP, and on top you'll definitely will be given access to PHP extensions. Make use of OpCache as it comes as recommended in moodle server requirements, you may be able to support thrice the numbers of concurrent users, definitely not still 70 taking quizzes, you'll be looking into VPS/VDS ideally, or at least an Entreprise/Business Shared hosting accounts (they come with extra resources)
In reply to Usman Asar

Re: Need help optimizing Moodle install on shared server

by Marcos Codas -
Thank you for your reply!

I'm already running PHP 7.0 so I don't know how much of a performance uplift I'll get. It's the newest version of PHP that's compatible with everything that's needed at the Uni.

I'll double check OpCache though.
In reply to Marcos Codas

Re: Need help optimizing Moodle install on shared server

by Usman Asar -
Picture of Plugin developers Picture of Testers
Marcos, it wont be possible that you're running PHP 7, as moodle started supporting PHP 7 since version 3.4.x and you're on 3.2.x (your site wont open if you're on PHP 7 with 3.2.x), just double check in your moodle which version of PHP you're running
In reply to Usman Asar

Re: Need help optimizing Moodle install on shared server

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
In reply to Visvanath Ratnaweera

Re: Need help optimizing Moodle install on shared server

by Usman Asar -
Picture of Plugin developers Picture of Testers
Cheers for updated information, I remember testing moodle 7.0 on Moodle 3.0.x as when it was launched but as it was past so I am reliant on core requirements for versions from downloads section, which still enlists 5.6.x as required.
In reply to Marcos Codas

Re: Need help optimizing Moodle install on shared server

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers
Okay, you seem knowledgable, and understanding of some of what has been shared with you.

Moodle specs for Moodle 3.2 were PHP 5.6.x. Since you think you are running PHP 7 with Moodle 3.2, maybe Hostgater was able to somehow get this working. This would raise a red flag to me. Do you know if Hostgater installed your Moodle with a one-step script product? If so, another big "red flag."

To learn a little more about Moodle, do you have a "sandbox." If not, consider getting one going. A sandbox running Moodle 3.9 might do you a lot more good at "optimizing" your school's Moodle than experimenting with Moodle 3.2 on a hosted server. Yet, any work with Moodle will be beneficial. The problem with Moodle 3.2 is that you are not going to get as much help here, since we gave up Moodle 3.2 around 4 years ago and might not remember. It's just not worth it for some of us (not all) to go back in history trying to help a person who we know, if they still with Moodle, will see the need to be current.

Relative to Opcache, I seem to recall some success running Opcache back on Moodle 3.2. Oops, but this was on my VPS, not a hosted server.

When I first began using Moodle around 10 years ago, I did it on a hosted server, just as you are trying to do. Within two year, But things changed around 6 years or so ago when it was still possible to run Moodle on a hosted server.

So here is another idea for you. Consider getting a VPS with a company, maybe Hostgator, that allows you to buy one or two months. On a per month basis, this might see a bit more expensive, but only commit yourself for one or two months of experimenting. Work with the latest version of Moodle, Moodle 3.9. Then, if you feel good, you can buy a longer-term VPS at a more attractive per month cost.

We don't know what your skill level is. Are you already proficient in Linux and servers? If so, you might be able to get a barebones VPS at a lower cost. If not, you might need to purchase an additional utility, like cPanel.

I don't work for any server company and am not doing an endorsement. In my own case, I use GoDaddy. In the U.S., you can buy a reasonable VPS, wth cPanel, for around $45. Times 2, $90. Consider asking your school for $90 out of its office supplies budget (or other budgets) for your two months of experimenting.  This could be a small cost for the knowledge that you will gain.  I don't know what you might eventually need (horsepower), but Ken, Usman, and others here can guide you much better than I.  I run a small Moodle.  This summer, I have only a total of 200 students in five courses.  This is "teenie-weenie" compared to what Ken and Usman, for example, do. 

Hope some of this is making sense to you.
Average of ratings: Useful (1)
In reply to Rick Jerz

Re: Need help optimizing Moodle install on shared server

by Marcos Codas -
All help is good help, Rick! I'm really appreciative of the time you're taking out of your day to reply. The biggest issue to try and get a VPS environment to test is that I also need to replicate the real-world conditions for the test to be valid, and that'll involve getting faculty to help out. They are already not getting any sleep (they are all practicing doctors as well as professors... this is a Med school in a developing country).

I think this one will most likely fall to me to sort out.
In reply to Marcos Codas

Re: Need help optimizing Moodle install on shared server

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

You can always move your experimental data to a real production server at any point in time. This is called migration.

In reply to Marcos Codas

Re: Need help optimizing Moodle install on shared server

by AL Rachels -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
I just scanned the rest of the posts, so I may have missed this if someone else mentioned my recommendation. Due to a very limited classroom budget, I used to run Moodle for my classroom on a REALLY under powered server which could only handle about 6 concurrent users, so I understand about the lack of funding. But the concurrent problem for us was ONLY when starting a quiz. The rest of the time the server could handle all 16 students in the class. The trick to taking a quiz was to stagger the start time for the students! I would only let 4 at a time start a quiz. I also experimented with using long quiz passwords with symbols in them, which would sort of automatically stagger the start times due to typing skill/speed of the students. So, maybe if you are mainly having problems with exams, you could implement something similar, and continue with the installation you currently have.
Average of ratings: Useful (2)
In reply to AL Rachels

Re: Need help optimizing Moodle install on shared server

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

Your ballpark figure of 6 tallies with OP's 10. But the OP wants to raise it to 70! So the simple answer is conduct the exam in seven batches of 10 candidates each?
Average of ratings: Useful (1)
In reply to Visvanath Ratnaweera

Re: Need help optimizing Moodle install on shared server

by AL Rachels -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

Hi Visvanath,

You said it so much better than I did. Your "batch" suggestion was what I was trying to say, just worded poorly.

In reply to AL Rachels

Re: Need help optimizing Moodle install on shared server

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

"Batch" is a common word in my environment. The full intake to a stream of study in a university in a given year is a batch and then they become batch mates - for the whole life!

Back to the topic. I think Ken convinced the OP that he needs more raw power. No "optimizing" will bring 700% improvement. Here is a quiz for the benefit of others: If an exam is of 60 min duration, how long will it take for seven batches? The answer is 90 min. Because you can send the batches in 5 min intervals. The server gets peak loads right at the beginning and the end of the exam. It idles in between.