Slow to show import screen

Slow to show import screen

by Timothy Takemoto -
Number of replies: 25
Since uploading from 1.4.x to 1.5.2 one screen is very slow -- the screen that shows the import a (GIFT etc) file dialogue.
http://ds21.cc.yamaguchi-u.ac.jp/~eigo/moodle/mod/quiz/import.php
It takes about 45 seconds. Other pages are quite quick
Average of ratings: -
In reply to Timothy Takemoto

Re: Slow to show import screen

by Timothy Takemoto -
Today it is taking 42 seconds to find the import screen. It could be because I have two thousand categories of quiz questions (many of these are duplicates or contain only two questions)...
http://ds21.cc.yamaguchi-u.ac.jp/~eigo/moodle/mod/quiz/import.php?category=2134
If I purge some will that help?

Tim
In reply to Timothy Takemoto

Re: Slow to show import screen

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
is that 42 seconds between pressing the import link and *anything* appearing or for the page to be complete. The first thing the import page does is load the selected category from the database, however, its is indexing on the tables primary index so that shouldn't be slow.

Does your setup use MySql? If so, can you check if this process increments the slow query count - better yet, set up slow query logging if you have the time.
In reply to Howard Miller

Re: Slow to show import screen

by Timothy Takemoto -
Dear Howard,

Thank you for responding.

> is that 42 seconds between pressing the import link and *anything* appearing or for the page to be complete.

It is the time for anything to appear. I would be happy to let you have a login.

Yes, I am using Mysql but if mysql were generally slow then I think that the site would be slow but that is not the case.  It is faster than it was last term. The only page I am noticing problems with is the import screen.

I am not sure how to tell if the process increments the slow query count or to turn on slow query logging. I do not have access to the database surver, but I may be able to ask the administrator to do so, if I can translate the question into Japanese. What is a slow query count?

Is there anything diagnostic that I could hack into the page, to find out where it is slowing down?

Is the large number of categories likely to be the cause?

Timothy
In reply to Timothy Takemoto

Re: Slow to show import screen

by Timothy Takemoto -

I am also finding that the quiz module is slow (again about 40 seconds) to show quiz question edit screens such as
http://ds21.cc.yamaguchi-u.ac.jp/~eigo/moodle/mod/quiz/question.php?id=11290

Most things are quick (about 2 seconds). I am used to a quick moodle. Spoilt.

By the way, I would like to say how wonderful the new 1.5.x interface is. The ability to split pages and the way that they are arranged, the one click addition of random questions, the subcategories, the ability to preview and edit single questions, all make the interface a joy.

Timothy

In reply to Timothy Takemoto

Re: Slow to show import screen

by Timothy Takemoto -

This delay is a killer. This morning it is up to 1 minute 10 seconds, on the import and edit pages. 

I wondered if the "path do du" might help. But while that might concievable help the import screen (and even not that since the directory in question is in the client not the server), it would not help the edit screen.

I guess that the quiz is now doing some sort of check through all my questions, and since I have a lot of them, that is taking a long time.

Tim

In reply to Timothy Takemoto

Re: Slow to show import screen

by Timothy Takemoto -

But when I select a .gft file with 20 questions in it, they are imported in less than 2 seconds. Super fast. Does anyone know what happens on the import files and edit a question pages and not on other pages? 
Timothy

In reply to Timothy Takemoto

Re: Slow to show import screen GOTCHA

by Timothy Takemoto -

I put lines like
    echo "before the bit which says XYZ
";

in the code of import.php and found that the line that is taking about 80 seconds is this one...

$streditingquiz = get_string(isset($SESSION->modform->instance) ? "editingquiz" : "editquestions", "quiz");

I guess that a similar call happens when I try and edit a question too.

I wonder why this takes a long time. I will try moving the sub-call to isset($SESSION->modform->instance)  outside of the get_string call and see if it is that. It is probably the get (from the database) though.

Yes. With "isset" out side, it is still the get_string that is taking time. Incidentally $SESSION->modform->instance is not set. 

    print 'modforminstanceisset = ' . $modforminstanceisset . '<br/>';

yields a blank

modforminstanceisset =

Is this the sort of thing that should take time? Do I need a faster database server?

Tim

In reply to Timothy Takemoto

Re: Slow to show import screen GOTCHA

by Timothy Takemoto -

No... it is the header that is taking the time. I did not think to put an echo tag before that part of the code.

It is the header that is taking forever to print.

   echo "before printing header
";
    print_header_simple("$strimportquestions", "$strimportquestions",
                 "wwwroot/mod/quiz/index.php?id=$course->id\">$strquizzes".
                  " -> TIMS SAYS PHOEY -> $strimportquestions");
    echo "finished printing header";  

The "TIM SAYS PHOEY" is just where the $streditingquiz used to be. It makes no difference. 

Incidentally, it seems I was wrong above, modforminstanceisset = 1

Tim

In reply to Timothy Takemoto

Re: Slow to show import screen GOTCHA

by Timothy Takemoto -
But then again perhaps not...It almost seems as if there is a dual process going on.

Using my theme, the long pauses is after the 
   echo "before printing header";

In the Wood theme, the header is printed down to and including the breadcrumbs but it takes ages before the 
   echo "finished printing header";  
happens.

In the standard theme, nothing is displayed for about one minute before the whole page is displayed at once. So it is not as simple as looking to see where the program is getting to in a linear fashion by putting comments in the php.

Timothy
In reply to Timothy Takemoto

Re: Slow to show import screen

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
...if it was me.....

I would 'breakpoint' the code in mod/question/import.php. Put something like..

echo "*** I GOT HERE ***"; die();

in various different places until you deduce the line that is causing the delay.
In reply to Howard Miller

Re: Slow to show import screen

by Timothy Takemoto -
Thanks a lot howard. I will try that.

Timothy
In reply to Timothy Takemoto

Re: Slow to show import screen

by Timothy Takemoto -
I have not had time to put the die commands in but instead I am creating quizes on my desktop moodle before uploading them. This works. The import screen is not slow to upload. Which suggests that this is a problem with the large number of questions (duplicated between courses) and categories that I have. I have quite a few. A typical weeks categories (yet to upload questions) looks like this

categories galore

Tim
In reply to Timothy Takemoto

Re: Slow to show import screen

by Timothy Takemoto -

My editing and import pages now take 3 minutes and 30 seconds to appear. It will not be long before it times out.

The categories screen takes 20 seconds to appear.

In reply to Timothy Takemoto

Re: Slow to show import screen

by John Rodgers -
Tim:

I have had questions in the back of my mind about this myself, as I too am generating some rather large banks of questions.  I'm quite sure I haven't reached your volume, but I can't see your picture from the last post.

I was just a little curious as to whether I should seriously think about my question bank production to avoid any problems.  I was running on the assumption that indexing was going to save my soul.

In reply to John Rodgers

Re: Slow to show import screen

by Timothy Takemoto -

sorry, my picture does not seem to have come out. The gif is of size zero on the server.

A lot of this is because of the way that I am handling multiple courses. I have 22 courses on now using the same tests with about 100 tests, with less than 2000 questions. There are a lot of categories since, based on a suggestion from Ger ages ago, I create a variation of each question and include one of these two variations at random in the test, so that students are less able to share answers.

The biggest problem is that each courses is a restored backup, so the categories and questions are multiplied 20 times. Next term I may be using groups, I think, to handle classes on the same day so then there will only be 3 classes as opposed to 22. But then teachers will not be able to create their own activities (since all activities are shared between groups).

In reply to Timothy Takemoto

Re: Slow to show import screen

by Timothy Takemoto -

I got together with my system administrator and found that the import.php import and question edit screens (mod/quiz/question.php) are using 97% of the server's php time for about 3 minutes 30 seconds. This means that students can not  take tests while the quizes are being edited and that soon the php will time out when I attempt to import or edit questions.

As Howard suggested, using lines like


die("here");

we found that the the problem is the number of categories. The slow calling import.php is

    if (!$categories = quiz_get_category_menu($course->id, false)) {
        error("No categories!");
    }

And it is probably the like a bit like

While $categories for each $category

in locallib.php that is using the processor power.

The problem arises becuase I have lots of categories. My categories are being used as questions in a sense, (upon a suggestion from Ger about 2 years ago) when writing reading comprehension questions, I usually make one or two variations of each question, store these in a category and insert one of the two variations into the test at random. This means that there are about 6727 categories, even after having deleted all non active coures.

Tim

In reply to Timothy Takemoto

Re: Slow to show import screen

by John Rodgers -
Hi Timothy:

I was a little suspicious lots of categories was the biggest part of the issue.

Random questions have been driving category creation as well.  I haven't hit the 6000 mark, but the category creep is there.

I'm wondering if its a reasonable feature reuest to change the way random questions are selected (I'm not sure).

What if it was possible to choose the group of questions you want to select from using the check boxes in the question manager, rather than the category  (this would allow the use of select all).  Once the questions are selected,  then "with selected" you would add x random questions.

This would allow larger categories and finer control over the selection of questions.

Is it a doable request?
In reply to Timothy Takemoto

Re: Slow to show import screen

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

Timothy,

Can you try something for me? Can you make a small modification to your database - I would like to add an index to the 'publish' field in the quiz_categories table. As part of the query involves this (currently unindexed) field, I wonder if it is causing the long search time.

The sql command would be...

alter table mdl_quiz_categories add index (publish); 

...although, you will be able to do it through phpmyadmin.

In reply to Howard Miller

Re: Slow to show import screen

by Timothy Takemoto -

Thanks very much Howard,

Alas however it did not seem to make much if any difference. On my production server (after testing on my desktop and a smaller production server) it too 2 minutes 45 seconds to pull up a question edit page.

By the way, if it were something to do with there not being an index, wouldn't that show up as load on the database server? The database and httpd servers are seperate and it is that latter that goes into overload when I try and edit a question.

I believe that both this and the import screen creates a menu of categories, perhaps by looking through all the categories.

Tim

In reply to Timothy Takemoto

Re: Slow to show import screen

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

Ok, I agree.... it's not the database query then. Oh well sad

The code for quiz_get_category_menu() (in mod/quiz/locallib.php) looks like this...

    if (!isadmin()) {
        $categories = get_records_select("quiz_categories", "course = '$courseid' $publish", 'parent, sortorder, name ASC');
    } else {
        $categories = get_records_select("quiz_categories", '', 'parent, sortorder, name ASC');
    }
    if (!$categories) {
        return false;
    }
    $categories = add_indented_names($categories);

    foreach ($categories as $category) {
       if ($catcourse = get_record("course", "id", $category->course)) {
           if ($category->publish && ($category->course != $courseid)) {
               $category->indentedname .= " ($catcourse->shortname)";
           }
           $catmenu[$category->id] = $category->indentedname;
       }
    }                

Could I ask you to keep going with the die("HERE") statements to establish if the delay is before or after the foreach loop - I am guessing now that the foreach loop is the culprit as it does a further database lookup for each category. On the other hand this would/could/should show on the db server too.

EDIT: If it's not that... can you eliminate the $categories = add_indented_ names($categories) line too, as that involves a recursive call.

In reply to Howard Miller

Re: Slow to show import screen

by Timothy Takemoto -

Sorry I have been over a week to get back to this. I have been busy making questions and dealing with students with popup blockers and stuff. My server administrator suggested that I did the same. I will add those dies. But the use of the catgories slows the sever to a standstill so I can't do it when students are on site. And that is a lot of the time. 

Tim

In reply to Howard Miller

Re: Slow to show import screen

by Juan David Martínez Pavony -

Hello Howard.

I think I am suffering of this same issue. I have Moodle 1.5.3+ (2005060230) with quiz module (2005060302).

I have posted here (http://moodle.org/mod/forum/discuss.php?d=43406) an screen shot.

While I was reading this thread, I thought this is the solution, but I was left away sad Can you continue, please?

I tried your die technique in locallib.php file, but I get the same blank content.

Thanks a lot.

In reply to Juan David Martínez Pavony

Re: Slow to show import screen

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
No, these problems are unrelated. Timothy's problems were entirely due to him having literally hundreds of quiz categories. The quiz code was never tested or optimised for this eventuality. Version 1.6, now handles large numbers of categories much more efficiently.
In reply to Howard Miller

Re: Slow to show import screen

by Timothy Takemoto -
Yes, I can vouch for that. It all runs much more quickly. Thank you Howard.
Tim