[POOR CODE]: Long Topics Taking Ages To Load...

Sort:
Avatar of TheGrobe

I don't presume to know what's going on under the hood, but I agree that if designed a page of a one-post thread shouldn't take any longer to load than a page of a 10,000 post thread.

Avatar of Benzodiazepine

Each post has an, actual, numeric, ID.

Try clicking these links (and observe the editor while you do so):

Suggesting they have just over 22 million posts/comments in their post/comment table.

Avatar of TheGrobe

OK, good observation.

Avatar of TheGrobe

So I'm actually beginning to think this is a recently introduced bug.  These threads weren't this slow just a few days ago.

Avatar of Benzodiazepine

No, they were. I don't think they're doing anything "in V2 anymore" or so.
They don't seem to really care either. It only happens in long topics anyway.

Would be cool if we could establish some time-posts correlation, like:

  • 70 pages ~ 8 seconds
  • 550 pages ~ 25 seconds

Though, I just had some funny results as well:

  • 160 pages ~ 2 seconds
  • 230 pages ~ 27 seconds

This topic here: http://www.chess.com/forum/view/general/sht-non-chess-players-say

Which has just 230 pages loads slower than the 550 pages one.

Avatar of Benzodiazepine

Based on my training and experience (that's what an FBI agent would say anyway).
I'm coming to this conclusion:

  • They're actually pulling all the posts (including text data) from the DB into PHP
  • They run a PHP loop on the posts to get the 20 posts on the desired page

Hence the crazy short time for the 160 page topic - it contains barely any text.

LOLOLOLOLOLLOLOLOLOLOLLOLOLOLOLOLLOLOLOLOLOLLOLOLOLOLOL

Avatar of Senior-Lazarus_Long

Benzodiazepine wrote:

M4g1c14n wrote:

This is probably because your internet speed sucks.

25 seconds is a problem? Does the President know about this situstion? Hahaha

Really? How would you know!?

Have you tried opening the mentioned topic?!

www.chess.com/forum/view/off-topic/youre-banned-forum-game

It takes 25 (!) seconds to display anything. Doing nothing. Nothing but waiting.

Avatar of mosai

Seems like the number of comments per page varies with the length of the comments. Maybe chess.com doesn't store the page breaks in the database and needs to figure it out when loading. After all what if someone deletes a comment near the beginning?

Avatar of mosai

Hmmm nevermind, I guess every page always has exactly twenty posts, never noticed that before.

In that case this doesn't make any sense

Avatar of Benzodiazepine
mosai wrote:

I guess every page always has exactly twenty posts, never noticed that before.

That's pagination basics.

If every page had different amount of posts based on their length? What!?

 

mosai wrote:

Maybe chess.com doesn't store the page breaks in the database and needs to figure it out when loading.

Storing "page breaks" in the database? What? Really?

All you need to store is posts/comments/whateverthehellyoucallthem.

 

mosai wrote:

After all what if someone deletes a comment near the beginning?

It doesn't matter. You can delete a comment on the begin, end, in the middle.

Databases don't work like arrays in your favourite programming language (if you have any, that is). Not like a vector, stack, queue, deque, set, multiset, map, multimap either.

Though: unsorted_map<int, <array<string, COLUMNS>> often, comes, pretty, close.
Where COLUMNS is the number of columns you want to store.

They really work like a linked list of tuples, though.

Avatar of mosai

I suppose making a set number of comments per page is convenient, but wouldn't it make more sense to make page breaks after a set length? Like paragraphs in word

Avatar of mosai

If they did do it that way, I could see why it might take them longer to load a page on a larger thread

Avatar of TheGrobe
Benzodiazepine wrote:

Based on my training and experience (that's what an FBI agent would say anyway).
I'm coming to this conclusion:

They're actually pulling all the posts (including text data) from the DB into PHP They run a PHP loop on the posts to get the 20 posts on the desired page

Hence the crazy short time for the 160 page topic - it contains barely any text.

LOLOLOLOLOLLOLOLOLOLOLLOLOLOLOLOLLOLOLOLOLOLLOLOLOLOLOL

I'd envisioned something similar based on what I was observing.  Yikes, what an unncessary burden on your servers.

Avatar of TheGrobe
mosai wrote:

I suppose making a set number of comments per page is convenient, but wouldn't it make more sense to make page breaks after a set length? Like paragraphs in word

Well, the goal would be to make pagination more efficient, not less....

Avatar of Benzodiazepine
TheGrobe wrote:

I'd envisioned something similar based on what I was observing.  Yikes, what an unncessary burden on your servers.

There's no other way to explain a 230 page topic loading slower than a 550 page one, with both over 25 seconds.

And then a 160 page topic loading in 2 seconds while a 70 page one needs 8 seconds.

Clearly, they're pulling all the posts from a topic from the database. Which explains the huge time differences based on how much text (on average) a topic contains. And then skip through them with a loop, 20 at a time, to get to the requested page and only display the next 20 or however much are left.

I wonder who made that, because, only a noob would do it that way.

That said, if you find a topic with a serious discussion in it (possibly with large quotes too), you should soon find that the topic gets unusable, perhaps, even after just 50 pages.

Avatar of Benzodiazepine

But, I agree. What a waste of server resources.

Avatar of DiogenesDue

This would be quite common among web developers...many do not know how to handle result sets, and grab individual database records...sometimes they even index the records by hand afterwards ;)...completely missing the point of having a database in the first place and treating data storage like a pez dispenser.

Avatar of CrazyJae

C.O.D.E.

Confuse

Or

Disorient

Enemies

Chess.com just don't like u...

Avatar of Benzodiazepine
btickler wrote:

This would be quite common among web developers...many do not know how to handle result sets, and grab individual database records...

Excellent wording "result sets"! That's exactly what we're talking about here.

Much respect from my side!

I've seen a retarded colleague build a site navigation (site had over 100 navigation items).
In a table with a nested-set structure: http://en.wikipedia.org/wiki/Nested_set_model

Guess how he did it?! He made a separate DB query for each of the navigation items, querying them by ID.

When I confronted him about why the page is loading so slow, he acted all innocent. Then he started building some PHP code to measure certain loading time aspects of the site (navigation, content, database access)...

He still didn't figure it out. Then I told him that he's using 100 fucking queries to build just the site navigation. He didn't believe it. So I had to show him his retarded code doing the queries hidden like 10 layers under some of his arbitrary abstraction layers.

Needless to say, the guy nearly ruined the company. My "boss" still thought very highly of him all the time.

Oh yeah, he also thought the page was getting "DDOS'ed by search engine spiders".

Because, why? The slow downs (server cpu spikes) didn't occurr all the time. Nope, they only occured when someone visited the site. And when 3 users started browsing the site simultaneously, it would start taking 1 minute (upwards) to load.

 

btickler wrote:

sometimes they even index the records by hand afterwards ;)...completely missing the point of having a database in the first place and treating data storage like a pez dispenser.

Haha, so agree with that!

Some people are just so stupid, it's hard to believe...

Avatar of ParadoxOfNone
Benzodiazepine wrote:

Hello there,

Long topics, with 500 pages are taking looong to load.

Example: http://www.chess.com/forum/view/off-topic/youre-banned-forum-game

Why is this? It doesn't matter which page you open. They all load constantly slow.

My guess: your SQL query to get the posts is pish poor.

It appears you're joining 500 pages * 20 posts per page = 10,000 posts with all sorts of user data from other tables.

Which is completely unnecessary. Either your SQL query is written in a retarded way or the query optimizer of your MySQL/PgSQL/whatever server sucks.

I've seen this happen before.

An easy and good solution to this is to select your results of the posts you want to display into a temporary table, like:

CREATE TEMPORARY TABLE posts_to_display AS
(
    SELECT * FROM posts
    WHERE thread_id = $thread_id
    ORDER BY id ASC
    LIMIT $offset, 20
)

This effectively STOPS the database to doing the stupid unnecessary joining and other operations on the other 9980 rows you will not be displaying anyway.

Now do the JOINs and other stuff you need to do on just the 20 rows from above:

SELECT * FROM posts_to_display p JOIN users u ON p.user_id = u.id ...

Which should take a mere fraction of the time it is taking now, regardless on how many posts the thread has - it will never be slower. Sometimes you have to use 2 queries to get what you want - it isn't bad.

If you need help with this, I'm here. :)

Greetings,

The tactics trainer and the game explorer are doing it too and it is beginning to pish me off. I will solve a problem and it just sits, frozen. i go to the home screen, no change in my rating. I miss a question and it freezes, go to my home screen, the points are deducted. Nice touch, thanks Chess.com.

When I go into the game explorer and examine a line several moves deep, it begins to lag and freeze, sometimes the move on the board will change but, the database information associated with the move, will lag and freeze, sometimes I have to reset it.