« When weird stuff happens... look at your config | Main | Deploying Ruby »

MySQL + middlegen = Scaling Issue

Flashback to J2EE Dev times: During the development of an internal J2EE framework, I came across a scaling issue when using middlegen to generate my CMP beans when I hit a certain number of tables (60+ or so). From then on it started to become quite painful, as middlegen would appear to hang for minutes while it analysed the table structures. Looking at the mySQL log, it appeared the driver was requesting the create table syntax of every table in my database multiple times.

 

First I looked into the source of middlegen, to see if it was doing something wacky… It was using the DatabaseMetaData.getImportedKeys() method to determine what foreign keys refer to the table currently getting analysed. This seemed reasonable to me so I decided to look into the mysql driver’s implementation of this function to see what was going on. Turns out, the way the driver figures this out is by getting the create statement of every table in the db, checking to see if it contains a foreign key reference to the table getting tested. Because middlegen was doing this for every table, it would mean that for each table in the db, a “show create table” call was executed for every other table in the db (n * n)…. No wonder this didn’t scale all to well…

 

To get around this problem I hacked to driver apart to forcibly cache the results from the ‘show create’ statement, so next time DatabaseMetaData.getImportedKeys() was called, it would use locally cached information.. not the most elegant solution but it worked.

 

Unfortunately I don’t have the code anymore (which I cant believe.. very embarrassing… I believe I always thought I would clean it up before putting it under source control... well it was over a year ago…), but I still have a jar file of the hacked driver which I use when generating the middlegen beans. Needless to say, this is not production quality, hell, for all I know, the a more elegant solution has been rolled into the driver codebase… either way, I thought I would make the jar available here just in case…

 

Now back to today, quick update on what’s been happening: I’ve worked on buttonator.com for a couple of days adding accounts, and multilingual support (Chinese, Japanese and Arabic for now). Also added the concept of a hotlink template… During this I had to use the caching of ruby: gotta say its pretty darn cool. After coming from cocoon, it’s nice to be able to use something so easy and logical. We should be rolling of v2 beta of buttonator.com sometime this week.

Posted on Monday, July 24, 2006 at 05:09PM by Registered CommenterOvosuite Team | CommentsPost a Comment | References12 References

References (12)

References allow you to track sources for this article, as well as articles that were written in response to this article.
  • Response
    Response: Follow
    Surround yourself with only people who are going to lift you higher
  • Response
    Response: Readed
    He who does not know how to be silent will not know how to speak
  • Response
    Adult Dating Deluxe
  • Response
    Blog with Approach, Pick Up and Date Women Tips
  • Response
    Response: car insurance
    As the net continues to add christian online dating services web sites, we'll try to bring them to you.
  • Response
  • Response
    Cheap auto insurance for teenagers
  • Response
    Response: adult personals
    adult personals
  • Response
    big dick man, beautiful ebony woman, sexy black man, sexual intercourse, whoring sluts, webcam whores, internet sex, felatio, sexy transexual, lesbian sex, bisexual honey's cum on my face, fecal matter
  • Response
    Response: christian dating
    christian dating
  • Response
    Response: christian dating
    christian dating
  • Response
    Response: adult dating
    I have too many favorites. I can? t pick one all time favorite. As a child I kept rechecking out the different colors of fairy books- ? The Red Fairy? book etc. As an adult my favorites are even harder to pick. ? Good Omens? by Neil Gaiman and Terry...

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
All HTML will be escaped. Hyperlinks will be created for URLs automatically.