Wednesday, February 9, 2011

FractusServer Database

Recently I encountered my old FractusServer ("fractusd") database code.  This was entirely written before I had real database application programming experience and it made me cringe.

Possibly the most appalling part is that it works for a small number of users.  Yet if a single user had one hundred contacts, each with on average .5 valid connections, my implementation of the database abstraction would cause an unfortunate 52 connections from fractusd to the database upon sign on: one to authenticate the user, one to retrieve his contacts, and 1 to retrieves his contacts' (about 50) locations.

I have coded stored procedures for all necessary database operations in MySQL (checked into the "fractusd" repository on my Github).  For instance, there was one that returned either 1 or 0 if a set of credentials could authenticate or not.  There was one that returned a set of contacts' usernames.  I actually found the learning curve of SQL (except for tricky optimizations) much shallower than a complex ORM framework like Hibernate.

The tricky part is the connection pooling, as hinted above.  I don't mind repeating a bunch of boilerplate code, but the way I see this, a single thread should lease one of maybe 32 connections and release it when done and after a timeout.  I'm working on the simplest way to do this without J2EE.

Update:  It's definitely BoneCP -- this does all the connection pooling (and configuration) without any of the overhead of ORM which I don't need for such a simple application.

No comments:

Post a Comment