This post originated from an RSS feed registered with Ruby Buzz
by Matt Williams.
Original Post: ActiveRecordJDBC Database Speed Comparison
Feed Title: Subverting the Paradigm
Feed URL: http://subvertingtheparadigm.ottercat.net/feed/rss.xml
Feed Description: Which Paradigm? Pretty much all of them. It's about programming, exploring, management theory, development, and other radical notions. One day I'll talk about Ruby. The next day Rails. Javascript will be thrown in for good measure. Maybe even (gasp!) some Java. Thoughts about management style, too. A little bit of this, a little bit of that, all thrown together in a subversive attempt to change the world, but in a good way.
So... You're wanting to connect to databases with JRuby and Rails. Which one is the fastest? Here's a comparison between Mysql, hsqldb, and Derby.
All the tests were run on an Acer Aspire 5112, AMD Turion X2 TL-50 (1.6Ghz), Dual Core 64 bit processor running Ubuntu Feisty Fawn in 32 bit mode, with 2GB of ram. Other apps were running, but they were consistant across the board.
The test was to run a series of 17 migrations where tables were created, populated, and columns added. No columns were modified or removed from tables due to limitations of driver support.
Comparison
Database
Wall Clock
User
Sys
Create Tables
Preload Tables
mysql with MRI
0m4.000s
0m3.160s
0m0.588s
0m0.1663s
0m0.3670s
mysql with JRuby
0m29.202s
0m46.383s
0m1.352s
0m0.278s
0m1.1740s
Derby (networked)
0m33.320s
0m48.787s
0m1.560s
0m1.152s
0m2.7500s
hsqldb (networked with default storage)
0m32.830s
0m46.659s
0m1.416s
0m0.277s
0m1.5160s
hsqldb (embedded with default storage (memory))
0m30.261s
0m47.619s
0m1.360s
0m0.196s
0m1.4020s
hsqldb (embedded with cached storage for all tables)
0m32.866s
0m51.423s
0m1.804s
0m0.306s
0m1.3890s
Conclusions
Well, it's pretty clear that MRI blows them all out of the water due to the cost of starting the jvm. However, beyond that, you can see the hsqldb performs roughly the same as mysql -- a little slower perhaps in general, but in one case faster. Derby, however, is quite a bit slower.
I'll definitely be switching from Derby to hsqldb in my current application, and embedding the database. I'll use a mixture of cached and memory resident tables. Cached tables will be for data I definitely don't want to lose and which will change regularly, and memory resident for data which is preloaded and/or static.
Next comes the mongrel cluster in the jvm instance..... and a monitoring thread and the load balancer. Pack it in!