Slow course/quiz load when one course has few thousands of quizzes

Slow course/quiz load when one course has few thousands of quizzes

by Ping Cheng -
Number of replies: 3

Hi all,

Our Moodle (3.1.3 on PHP 5.6) is facing a slow loading situation.

One of courses contains few thousands quizzes, and when users get into this course or any quiz under this course, the loading speed is much longer.

I put a bit of codes in the the moodle_database class for the sql counter, and found this course and its related page would run 5000+ queries (looping for getting context). For the quiz part, the sql almost half came navigation, another half came from the filter? (Not quite sure by now)

However, if I go to another course with much less quiz, it loads fast.


It seems like Moodle will loop all the course_modules to apply each active filters and find the active nodes for the nav.

Is there any way make the loading speed much faster? We do not much using the filters from the 3rd party plugin, we will develop our own question type for quiz.

Many thanks

Average of ratings: -
In reply to Ping Cheng

Re: Slow course/quiz load when one course has few thousands of quizzes

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I'm going to cautiously move this to the Quiz forum as the issue sounds like it might be specific to the way quiz is organised. 

Tim - do feel free to send it back wink

In reply to Howard Miller

Re: Slow course/quiz load when one course has few thousands of quizzes

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Howard, your caution was correct. As the original poster says, this is about time taken to display the course page, and is mostly caused by filtering. It is a general Moodle issue that would be the same if you had a course containing about 5,000 Page resources instead of quizzes.

The best suggestion I could think of would be to use a different course format, which prints different course sections on different pages, so it does not try to print 5,000 activity links on the same page.

In reply to Ping Cheng

Re: Slow course/quiz load when one course has few thousands of quizzes

by Ping Cheng -
Hi all, 


Just found a solution for our own Moodle project, it reduced a lot of sql pressure on server. This is not suitable for every Moodle since we highly modified some functions. Just post here for your all references.

The three main reasons caused the large amounts of queries:


1. course_modinfo

The class constructor would check each course modules under a course, and try to rebuild the course cache when any module is missing. It uses a foreach loop for the cms.  I pre-defined the sql with a IN condition. and fetch all them at once. This change would run a heavier sql rather than run a simple sql few thousands times.


2. navigation section

Since we do not use the navigation block, I will simply return an empty array for this function.


3. Activity name auto-link filter

This filter would look at all the contexts of course activities under a course. We do not require this function, and then we turned it off.

Average of ratings: Useful (2)