Download & Extend

performance hit in nodevote_display_vote()

Project:Node Vote
Version:4.6.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

I see a performance hit in the code in function nodevote_display_vote($nid). The critical line is near 194, where the code store the average of the scores:

$result = db_fetch_array(db_query('SELECT COUNT(*) AS votes, AVG(vote) AS score FROM {nodevote} WHERE nid = ' . $nid));

A wiser solution for the average count is to store the number of votes and the sum scores. The implementation above is only useful when you want to show statistics ("number of people who voted with 4") for the admins like the banner.module does.

Comments

#1

Perhaps it is an issue in theory. But did you run any benchmarks or enable the dev module to see how much time does this really take?

I know it can be an issue on a large site where there are many votes per node. But what I am after is: in practice, how much of a problem is this?

#2

Sorry, I'm not a developer guru now, I don't know what "dev module" is. Here's my test environment:

Machine: P4 2.0GHz with 512MB RAM, FreeBSD 4.9, MySQL 4.1.12 .
nodevote table's parameters:

  • nid: 1-200
  • uid: 1-3000

Stress test with 2335 votes:

mysql> SELECT BENCHMARK(10000000,'SELECT COUNT(*) AS votes, AVG(vote) AS score FROM nodevote WHERE nid=10');
+-----------------------------------------------------------------------------------------------+
| BENCHMARK(10000000,'SELECT COUNT(*) AS votes, AVG(vote) AS score FROM nodevote WHERE nid=10') |
+-----------------------------------------------------------------------------------------------+
|                                                                                             0 |
+-----------------------------------------------------------------------------------------------+
1 row in set (0.23 sec)

Stress test with 23942 votes:
mysql> SELECT BENCHMARK(10000000,'SELECT COUNT(*) AS votes, AVG(vote) AS score FROM nodevote WHERE nid=10');
+-----------------------------------------------------------------------------------------------+
| BENCHMARK(10000000,'SELECT COUNT(*) AS votes, AVG(vote) AS score FROM nodevote WHERE nid=10') |
+-----------------------------------------------------------------------------------------------+
|                                                                                             0 |
+-----------------------------------------------------------------------------------------------+
1 row in set (0.22 sec)

So, it seems faster than small no. of votes. :D

I don't know how really a performance hit, but if you don't planning to give detailed statistics for the admin users then it's a wasting of (little?) resources.

#3

Actually, what you did is good news so far, which tells us there is no performance hit.

However, to be sure, install the devel module and check how much time the query takes with 20, 2,000 and 20,000 votes.

nobody click here