I have just upgrade my site from drupal 5.17 to drupal 6.11 and upgrade User Stats from 5.x-1.0-beta4 to 6.x-1.0-rc1

Forum topic loading about 20-30 seconds

I have core quad for one site, and site is offline

I have 1300000+ comments and 150000+ nodes and devel show me next:

Executed 354 queries in 27519.63 milliseconds

4 top slow Queries maded by User stats:

6872.76 ms - user_stats_post_count_update - SELECT COUNT(*) FROM comments c INNER JOIN node n ON c.nid = n.nid WHERE c.uid = 22486 AND c.status = 0 AND n.status = 1 AND n.type IN ('blog','poll','forum','bio','game','konkurs','photolist','photolist_man','story')

6866.51 ms - user_stats_post_count_update - SELECT COUNT(*) FROM comments c INNER JOIN node n ON c.nid = n.nid WHERE c.uid = 15047 AND c.status = 0 AND n.status = 1 AND n.type IN ('blog','poll','forum','bio','game','konkurs','photolist','photolist_man','story')

etc..

I dont have this problem in drupal 5 and User Stats 5.x

Comments

liam mcdermott’s picture

Priority: Critical » Normal

This is a difficult one. But I am very willing to optimise User Stats for larger sites. Here are some questions and things to consider:

  1. What is the speed like when you load the thread a second time? After User Stats determines the number of post counts for a user, the value is stored. When the user creates a new node/comment we increment the stored number, instead of running the expensive SELECT COUNT(*) ... again. Basically, when the post counts for every user are stored, you shouldn't see this problem again.
  2. User Stats will also pre-generate post counts on a cron run -- you may set how many records it updates per cron run in Administer -> Site configuration -> User stats settings, the default is 25 -- so it is possible to point your browser at http://example.com/cron.php and set the page to refresh every second; or just set cron to run every minute, until all post counts are stored.
  3. I am interested in making the update query faster, but don't have many ideas, if you do then let me know! Things we could do:
    • provide a batch update facility in the admin screen;
    • use SELECT COUNT(cid) ... instead of SELECT COUNT(*) ..., this might be faster, in many cases, since the database could use the key cache already held in memory, instead of doing a table scan, it might be conceptually incorrect though, since we're counting the number of rows, not values of cid (see: http://www.mysqlperformanceblog.com/2008/09/20/a-common-problem-when-opt... and http://www.mysqlperformanceblog.com/2007/04/10/count-vs-countcol/);
    • seven seconds per-query is a long time, we might get better performance using a temporary table and many small steps in lieu of a JOIN, this would be particularly effective when storing the post counts of multiple users, during a cron run, or batch update for example;
    • check the query is using indexes and whether it could be sped up with any simple optimisations;
  4. You wouldn't have seen this issue in Drupal 5 as the post counts would have been stored for all your users. We moved to a different database schema for the Drupal 6 version, meaning post counts need to be regenerated.
liam mcdermott’s picture

Status: Active » Postponed (maintainer needs more info)
off’s picture

1. Yes! Load the thread a second time going fast, but first time very.. very slow.. I dont understand what changed in module from 5.x that lead this slow effect.

when the post counts for every user are stored, you shouldn't see this problem again

Good news.. i tried

off’s picture

2. I set cron run every minute.. Where I can see how much users left to be counted?

off’s picture

3. How about User titles (http://drupal.org/project/user_titles)?

I dont have a problem with this module and them coun posts to..

For a long time I ask a question. Whether it is impossible to unite somehow efforts of these two modules for calculation of quantity of posts.

And how User titles does this?

How can I do check the query is using indexes?

off’s picture

4. Probably, but when I have started to use User stats I have already many of visitors on a site, but had no powerful server and did not see a difference in productivity of a site with the included module and with switched off.

Now the topic is loading less than for a second with the switched off module and more than 20 seconds with the included.

liam mcdermott’s picture

Status: Postponed (maintainer needs more info) » Active

This is enough information for me to investigate, thanks.

I've done some testing and the query is about as fast as it can be, although it might be sped up by an extra index on nid, uid, status on the {comment} table. The problem is that messing around with core tables is a no-no (as some other module may come along and try to make similar changes, leading to incompatibilities), so I'm going to have to think of another way around the problem.

I dont understand what changed in module from 5.x that lead this slow effect.

Literally nothing has changed in the way posts are counted, check the queries, they are exactly the same. Not saying you're wrong, just that I don't know either.

2. I set cron run every minute.. Where I can see how much users left to be counted?

Currently there's nothing in the admin interface which shows how many users there are to be counted. I probably won't add such a feature for some time (unless someone pays me to do so).

Here's a query that will tell you roughly how many people are left to count:
select (select count(*) from users)-(select count(distinct uid) from user_stats_values);
(Note: you'll need to add any table prefixes, and this doesn't take into account people who've been banned and whatnot)

3. How about User titles (http://drupal.org/project/user_titles)?

I will check User Titles, thanks. :)

Am not holding out much hope though, I expect User Titles counts posts during cron, or when a new post is inserted. The key problem here is User Stats needs to show post counts in forum threads, on-demand, User Titles can do everything behind the scenes. :)

Now the topic is loading less than for a second with the switched off module and more than 20 seconds with the included.

I'm not sure I understand this. Are forum topics loading slowly, even after the post count has been stored? This is quite important, as I may need to improve the performance of other parts of User Stats!

off’s picture

Thanks for help!

I use User stats and my site running fast, but i remove

<?php print user_stats_get_stats('post_count', $node->uid); ?>

from any comments and put this on profile page.

I will watch for the development of the module.

Thanks for work!

soelver’s picture

I think I have the same problem. I crash the site every time I try to load IP or other userstat information.
Not sure what to do about it, but will ask a more technical friend, to read up on this issue - I'm sure he'll understand better than me.

We have our own dedicated server, and everything else usually runs smoothly, but this module seems to have some loading issues.
Using same version as described here.

off’s picture

On my site at the moment good performance