Monday, June 23, 2008

Can you find the exclusive lock?

Here's the quiz of the day: Can you find the exclusive lock in this code?

Mysql#query

(hint: it begins on line 2, and ends on line 36)

It seemed reasonable that ActiveRecord.allow_currency would make my application be able to run concurrent queries. Well, that's what I thought :) Until I had discovered my 6 threads (which properly formed 6 new connections to the database) were still executing queries serially, instead of in parallel! When investigating what the hold up was, I found my culprit: Ruby 1.8's green threads lose control when you run native C functions, well at least Mysql#query anyways.

So, note to self and world: any time you run a native function that takes a long time, look forward to a big, exclusive lock down.

All the more reason I'm excited for Ruby 1.9's native threads

So, web, do you know if there's a way to "poll" ruby's thread scheduler while in a native C function while waiting for some other task to finish?

Saturday, June 14, 2008

Quiz of the day:

What does this wrecking ball and a developer who neglects to create and maintain an automated test suite have in common?

Thursday, June 12, 2008

Garbage collect every git repository on your machine

One of the things I really like about git is that it doesn't automatically garbage collect and compact repositories. It's kind of like how you don't clean your room and take out the garbage (or at least I don't) every time you make a mess or throw something away. If you accidently throw something away, you can pull it out of the trash before it goes to the dump. You don't have to be slowed down by a clean up operation when you're focusing on getting things done.

However, there is a draw back to this. Git repositories DO start to slow down after a while if you aren't "cleaning your room". And, they won't be as efficient in disk space utilization.

Lucky for us, since we are working with computers here, we don't have to clean our rooms by hand. The following little bash script will crawl your whole hard drive, look for any git repositories, and then garbage collect, prune, and pack them, regaining your disk space and making your repositories operate faster:

#!/bin/sh
find . -type d -name .git | while read dir; do pushd "$dir"; git gc --prune; popd; done

PS: ref logs keep objects from being pruned. More on ref logs in a future post.

Tuesday, June 3, 2008