Archive for October, 2007
Bookie currently checks prices at 9 shops. When you view a new book or refresh the pricing, it checks each of those shops in sequence. A nice little optimisation is to check the shops in parallel. Threading in rails appears to be pretty straight forward — provided you clean up before the request-response cycle is complete.
Here’s the sequential version:
for shop in Shop.find(:all)
And the threaded version:
for shop in Shop.find(:all)
threads << Thread.new(shop) do |lookup|
By default ActiveRecord doesn’t allow multiple threads to access its mysql connection, so you need to allow concurrency by adding the following line to your environment.rb file:
config.active_record.allow_concurrency = true
That last line in the example is used to close database connections which are no longer attached to a thread. You’d have thought that joining the thread would have closed it’s database connection, but there you go. Without this you’ll eventually exhaust your database connections.
Check it — Keith made the Age. In Nangiloc, it’s on page 4 — but I didn’t find it in the edition we’ve got at work.
I’ve updated Bookie by adding another online Australian retailer, Fishpond. They seem to have good pricing on some books, and as a big plus, they have an Affiliate program which I’ve signed up for. I’ll get a cut on any books purchased via Fishpond, Amazon UK & Amazon US.
Adding Fishpond wasn’t as straight forward as the other stores. When searching for an ISBN, you can get multiple results, with different product ids and different prices. (According to their support guys, it’s because they give different product ids to books provided by different suppliers.) Just to make life difficult, the product id needed to generate Associate Links isn’t simply the ISBN. After a little bit of Hpricot work, I figured out how to grab all the data required to select the cheapest book ( if there’s multiple results ) and to generate Associate Links.
Lots of you have been noticing that “Bookie” craps out pretty frequently — turns out it’s due to SQLite3:
ActiveRecord::StatementInvalid (SQLite3::BusyException: database is locked: SELECT * FROM books WHERE (books.”isbn10” = ‘978-0596005696’) LIMIT 1):
Session data ( stored in the DB ) was a major culprit, but it looks like more than one concurrent user ( It happens! ) can cause this problem. SQLite’s homepage states that write operations lock the whole table, but since this should only take milliseconds, it shouldn’t be a problem.
I’ve migrated over to MySQL and performance feels much snappier. Maybe that’s just because I was hoping it’d be faster. With luck, bookie should be far more stable now.
Well, not quite yet. Currently my folks are on 16% of their water allocation. They normally require the full 100%. Avocados use a disproportionate amount of water, so they’re gone — bulldozed a few weeks ago. The Victorian government has known since at least 2001 that they’d over allocated the Murray’s water. They promised that it didn’t matter and that they’d manage the water so that they never ran out. Typical politicians.
So what can be done? In the short term, farmers with annual crops ( grasses and grain ) could be paid by the government to go without using their allocation, whilst permanent plantations citrus, avocados and vineyards receive their allocation. A year or two without water will do no harm to annual crops, but will kill off permanent plantations which take around 5 years after replanting to become productive.
Longer term solutions include government purchasing water rights ( at market rates ) from willing sellers. Replacing channels with pipes to reduce water wastage. Building dams.
Non of these solutions will be any help to the farmers who’ve relied on the Murray for water for the last 100 years.
Here we have some lovely green leafy avocado trees.
Here we have some dirt.
I saw this and thought it was funny:
Then I saw this, and also thought it was funny:
Such a cool song.
We’re going to have some interesting ways to watch telly in the next few years. Video content is popping up everywhere now — the iPhone, Sony PS2, iPod Touch and iPod Video are pushing slowing into the mainstream — watching TV on the train on the way to work is not unusual now, and much more practical than whipping out your laptop. MythTV, Windows Media Centre and TiVO are growing slowly, bringing timeshifting into the mainstream. AppleTV brings ( or will bring ) shopping for TV shows and movies to the Telly.
And of course, BitTorrent is helping to sharing TV around.