Jump to content

Cache "Active Users"

Guest Luke

Recommended Posts

One of the biggest things I've noticed about very popular forums is that they turn off the active users list in topics and posts. Where this feature might be very handy and imformative, it can cause load when you dont want it. On the other hand, not having the feature at all can be a little anoying because you dont know if anyone even cares about your topic unless you used the "Last Click" option on the board index (which, with a lot of users can be anoying to say the least).

So the idea is to cache these results. You may ask, what purpose could that possibly serve? Well lets put this into more perspective. Let's say you had 1000 users on your forum constantly (like neowin). When a user is visiting your forum, what are they doing 98% of the time? They're either looking at a forum or topic. When they look at a forum or topic (with feature on) it's hitting the sessions table for information. Many users go in and out of topics and posts, so each user may hit 10 different pages with the active users list per minute. If you have 1000 users doing this, you have 10,000 requests per minute. And that doesnt even include the php loops for each active users list. There may be 10 users in some forums/topics. PHP loops pretty fast, but it all adds up.

So how would you cut off those requests, and keep the feature? The answer is somewhat simple, but like all improvements has a draw-back. The idea is to use a cron job that either runs 1 time per minute or 1 time every other minute (user selectable). This cron job would parse through the sessions table and do two things:

#1) Go through the sessions table and pull out sessions where a user is either looking at a topic or forum.
#2) Load a snap shot of these results from the previous run.
#3) Take a snap-shot of the results from #1 and store it for the next run.
#4) Store an active users list (html) in the topic/forum as a cache, using results from #1.
#5) Go through results in #2 (snapshot) and clear the cache if, and only if, that forum or topic was NOT processed in #4. We do this because we want to clear old results where the topic or forum isnt even being looked at.

This way the sessions table is only being accessed 1 time per minute, as opposed to 10,000 times.

The draw-back, as I mentioned earlier is, the active users list is only accurate up to a minute (or every other minute. What ever you choose it to be). However, it gives you a good enough idea of what's going on instead of being totally blind. I did something similar on my forum with a "Forum Title (# Viewing)" and 99% of the time it's completly accurate.

You could also do the same thing with the Board Index list as well. Just store the list in a cache. If you had 1000 users online and each one accessed the board once, that means it would look 1000 times for each of the 1000 users (in php) (1000 * 1000 = 1,000,000 php loops) . If you cache it, it's loads the list (text) for each user once.

Comments Appreciated :)

Link to comment
Share on other sites

It certainly sounds like a good idea, however as i am on a par with a dried prune as far as technical knowledge is concerned, i have no idea whether it is feasable.

I am voting Yes for this as i approve of all ways to help cut down on server/database strain and (ultimately) ways to speed up the board :)

Link to comment
Share on other sites

  • Management

The only problem with storing the board index in a cache is that it won't keep the permission settings.

The forums that you see are different from the forums that I see. :)

Link to comment
Share on other sites

Hmmmm.... There has to be a good way of doing this though :ermm:

Wait... it's only for anonomous users right? And only root admins can see anonomous users right?

Well, just cache the list for normal users. Then you have several options for root admin :)....

1) Have it load normally for root admins IF an anonomous user is online. (not the best idea)
2) Save the anonomous users in a cachied array with a position marker. Use that marker to insert each name using substr.
3) Load the cachied list, have anonomous users seperate, and just tack them on the end or beginning of the list (beginning the best)
4) Dont load anonomous users at all, and make the number on "# Anonomouse Users" clickable that allows the root admin to view it in a small window. This would include bots as well (I like this idea the best).

(When I mean by "options" I mean by what could be done to do the cache, and solve the problem)

Link to comment
Share on other sites

What about "Staff" forums, or private forums?

User A is in Group A.

There is a forum only Group A can see. User A is viewing this forum.

User B is in Group B. Group B doesn't have access to this forum. They click the online list.

That would cause a problem.

We arnt talking about the profile page, we're talking about the list of users in the board index and under topics and posts. The only thing that is different from user to user is member vs root admin.

The member profile page, or the last clicked page, isnt as frequently visited, so it would have to remain the way it is.

You would want to cache the active users list on the board index, under topics and forums because they are the most frequently visited areas on the forum. The user profile page would pull a single record from the sessions table, whereas the users list would pull several things.
Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...