Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+4 votes
in Q2A Core by
edited by

I have a few questions on my site which have many answers, spanning 8+ pages. These pages take many seconds to load. It seems worse on questions with a lot of hidden answers. I'm talking about raw server load time, not front end time. Here are some examples from my site:

http://pokemondb.net/pokebase/23/what-are-some-of-the-best-move-combos-in-pokemon-you-have-found - takes over 6 seconds for the server to respond.

http://pokemondb.net/pokebase/meta/8996/ban-report-do-your-part-to-help-the-site-be-idiot-free - takes over 11 seconds for me as an admin to load it. If I load it logged out then it's a lot faster. To be clear: this page will not be slow for you because you can't see the hidden posts. Gideon if you see this let me know and I can temporarily make you a mod on my site to see it.

I can also see a noticeable delay on this site too, e.g. http://question2answer.org/qa/19647/question2answer-1-6-progress 
Not as bad as my site but still around 2 seconds just for the response to start from the server. Perhaps to do with the number of MySQL queries?

Q2A version: 1.5.4
Hi Scott, first link took me 1 sec to load. But I have to say that I am on fibreglass now. Second link 1 sec as well... A total fresh load of the first link in Chrome says 2.6 seconds in the network profiler (1.21 sec only for the page itself which is quite much, 'normal' is around 0.7s at my server).

UTC +2:00 (guess where ;) )
You can't see the hidden posts on the second link so it will not be as slow. Also I have deleted most of those hidden posts and it's faster. So having all the hidden posts on pages 2-8 somehow makes page 1 slower.

And it's nothing to do with your connection speed, I'm talking purely about server response time, aka "Time To First Byte".

4 Answers

+1 vote
Best answer

I spoke to Gideon a little while back about this and done some more research myself so I'll post my findings.

The basic reason that the pages take so long to load is because ALL answers and comments for a question are loaded from the database, even if they will not be displayed. Not only that, but ALL these posts are processed in PHP as if they are all going to be displayed.

The database queries themselves are actually not very slow, the biggest time sink is processing every post. This is done in qa-page-question.php around line 70ish, specifically these two blocks of code:

foreach ($answers as $key => $answer) {
  $answers[$key]=$answer+qa_page_q_post_rules($answer, $question, $answers, $achildposts);

foreach ($commentsfollows as $key => $commentfollow) {
  $parent=($commentfollow['parentid']==$questionid) ? $question : @$answers[$commentfollow['parentid']];
  $commentsfollows[$key]=$commentfollow+qa_page_q_post_rules($commentfollow, $parent, $commentsfollows, null);

So the solution would seem to be substituting $answers and $commentsfollows for just the ones appearing on the current page. For a regular Q&A with answers sorted by votes, this is not really possible here because the $answers array is not ordered until much later.

For posts ordered by time this does appear to be possible as we can get the start parameter in the URL and grab a portion of the $answers array easily. Then skip any comments not attached to one of those answers.

So I just wanted to put this information out there. Maybe it will help anyone else understand/mitigate the problem if they hit it.

Now I have run into the same issue. 34 answers, xxx comments, 150.000 views, and the loading time is >2 sec only for the html. Page: http://www.gute-mathe-fragen.de/53920/ratsel-mit-tieren-und-ihre-fusse

Have you found a solution, Scott?
0 votes

Hi Scott.

My environment:

Time: Saturday 11:12 (GMT+9:00) => Japan is about noon now. It is the time when line becomes vacant.
Internet: Optical shared line (Down speed : 200MB)
Localnet: 1GB
Browser: Chrome V27

Performance of your pages that I just watched isn't bad so that you say. It is 1 => 3 seconds.

  1. Did you add any cache parts?
  2. Web server and database server exist on the same hardware? Or is it different?
  3. You may find bottleneck if you compare PHP history with Q2A debug panel.
Actually 3 seconds for just generating the page (Time To First Byte) is very bad.
0 votes
edited by

Same here: Both sample pages do load almost instantly. Would say less than a second.

Friday, 23:47 pm

GMT / UTC -5:00

like Houston / Dallas


The 1.6 progress page shows a small delay, lets say less than 2 seconds.


You can use http://www.webpagetest.org to check performance from different locations...


Here is a result from webpagetest - http://www.webpagetest.org/result/130713_PA_108T/ - notice the huge Time To First Byte.
At night it looked better.

Besides I tested my best question with 207 answers all on one page and the result for First Byte is as well very bad. about 1.7 s.

In comparison a question with 5 answers only shows First Byte Time of .357 s

I dont know how many actions are processed with the question result array but I can imagine that especially when You have hidden posts additional processing time is needed.

However, from a users point of view I see Your mentioned pages very well performing.

I see them responding very fast, I wouldnt leave them because of speed.
0 votes
In the Netherlands (daytime), all sites load fast, around 1 second... i'm using Chrome.