You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Tom Anderson <ta...@infonow.com> on 2003/02/04 22:39:35 UTC

[PATCH] JDBCStore.keys() doesn't scale well

As currently written, JDBCStore pulls session IDs from the database 
using a query of the form:
	SELECT COUNT(s.id), c.id FROM tomcat_sessions s, tomcat_sessions c 
GROUP BY c.id;

While this query is a clever way to get the count back as part of the 
query, it does not scale well to larger numbers of sessions.   I had 
about 5000 sessions in a moderately loaded system with a MySQL database 
and this query would take about 80 seconds to run by hand because of 
the N-squared nature of joining the table with itself.

This much simpler query is not as clever but gets the job done much 
more efficiently (it only takes 0.00 seconds according to mysql):
	SELECT id FROM tomcat_sessions;

It means a little more work determining the number of IDs after the 
query runs but it's more than worth it.

Attached is the patch file.

~Tom