[Opensource] DBObject Creation Time
Michael Rimov
rimovm at centercomp.com
Sat Jun 8 00:20:03 PDT 2002
Hey All,
That one gentleman's post about DBObject creation time had be thinking. So
I did a quick test that simply created DBObjects.
Straight SecuredDBObjects [I specifically tested with new MimeTypes() ] did
200 creations in 15 ms. So that obviously wasn't the problem.
It turns out that the problem was Secured DBObjects with String
constructors. like so:
new MimeTypes("Admin");
The reason that this took so long is that SecuredDBObject did a record
search to the database to lookup the "Admin" string.
Now, the disclaimer here is that this constructor is very deprecated as of
version 4.0, and if you can get around using this constructor you'll be far
better off. For example, using ControllerRequest.getUid() to get the UID
is preferable.
However, if you can't, I've added a patch to SecuredDBObject. This patch
requires Apache Common's Collection 2.0. This jar will be included in the
next ea release of Expresso 4.1 and is in CVS already.
It uses a LRUHashMap of size 20. It stores the most recently used Username
to userid pairs and looks there first before attempting to do a retrieve
from the underlying database. This cut creation time from 10ms each to:
200 in 45 ms.
As you can see, this is still three times slower than using the integer
constructor, but it is still < .25ms per construction, so it should be
within an acceptable range if you cannot get around this constructor.
If you want the patch, it's pretty simple and can be backpatched to your
Expresso 4.0 distribution if you're interested. Write me offlist if you
would like to get your hands on it.
HTH!
-Mike
More information about the Opensource
mailing list