WeBWorK Problems

Slow load times with PGgraphmacros.pl

Slow load times with PGgraphmacros.pl

by Danny Glin -
Number of replies: 1
We've been using a question which creates dynamic graphs as part of a gateway quiz here, and it's been causing all sorts of problems. It takes a long long time to generate the png image, to the point where it sometimes times out and creates an empty png file. The system then sees that the file has already been created, and serves the empty file every time the question is accessed.
The problem in question is from the NPL: Library/Rochester/setLimitsRates1_5Graphs/ur_lr_1-5_1.pg

There was mention of a problem with PGgraphmacros.pl that had been recently fixed in an earlier thread, so I upgraded my copy of PGgraphmacros.pl to the newest version from cvs, which didn't seem to solve the problem. Rolling back to an earlier version (the one which does not use mathobjects) causes a huge performance increase (the page now loads in under a second as opposed to 10 seconds or more with the new version).

I was wondering if anyone else can reproduce this (note that this behaviour only occurs the first time the problem is accessed for a given user, since after that the image has already been generated), or whether the solution involves upgrading more than just PGgraphmacros.pl (we are running rel-2-4-patches of pg current as of mid-September).

Any help would be appreciated.
In reply to Danny Glin

Re: Slow load times with PGgraphmacros.pl

by Davide Cervone -
I've looked into the issue, and the problem seems to be cause by the fact that the new MathObject-based graphing routine uses the Formula's eval() method rather than a compiled perl expression. The eval() method interprets the formula "by hand" from the parse tree, and so will always be slower than a native Perl expression.

Fortunately, MathObject Formula objects can produce compiled versions of their formulas, and switching to that makes the graphing macros work again at their original speeds.

The only problem was the graph macros expect the function to return an undefined value when an error occurs, while the MathObjects perl function throws an error instead. I had to work a little bit to trap the errors, but that is taken care of now, so you should be able to get the speeds you are used to again.

Update your pg/macros/PGgraphmacros.pl and pg/lib/Value/WeBWorK.pm files, then restart the server, and you should be in business. Please let us know if this takes care of the problem for you.