In part 1, I described how I located leaky Sets in MongoMapper by diffing the Ruby ObjectSpace with GDB. Today, I’m going to show you how to solve the problems that those sorts of diffs can reveal. In today’s example, we’re tracking leaky sets. In particular, a set is holding onto class references. We are [...]
Category Archives: Ruby
MongoMapper, Development Mode, and Memory Leaks
If you’ve worked with MongoMapper for a while, you’ve probably noticed that in complex apps, there are horrific memory leaks in development that magically disappear in production mode. While this is all well and good, and it’s rather handy that things Just Work in production, don’t you wish you didn’t have to restart your app [...]
WillPaginate and custom paging.
will_paginate is the de facto Rails paging plugin, and with good reason – it’s solid, fast, and reliable. Everyone I know uses it, but a lot of people don’t use it to its full power. I recently discovered some very cool functionality it includes – the WillPaginate::Collection class can be used as a custom paginator [...]
Eight tips for getting the most out of your Rails app
Rails does an awful lot to optimize page generation, but there are a number of hacks, tweaks, and usage patterns you should be using to get the most out of your app. Configuration tweaks There’s a lot of the Rails stack that’s written in Ruby, which is great – it’s portable, it’s flexible, it works [...]
When you have to store user passwords…
Today we got word of yet-another-database-hack-with-plaintext-passwords. This time, it’s RockYou, purveyor of many of those Facebook and Myspace apps you use. Oops. Every time this comes up, everyone says “How naive! They should have been using salted hashed passwords!” This is true in any case where you don’t need to use the password again on [...]
Fine tuning your garbage collector
If you’re familiar with Ruby at all, you know that it can be a little wacky when it comes to memory usage. Most of us have observed a Mongrel/Passenger instance that starts out small and then grows by leaps and bounds, eventually settling on some uncomfortably high number. We’re going to fix that with Ruby [...]
Monitoring Rails: Getting instant monitoring alerts
Monitoring is big. Having an automated daemon watch your stuff and make sure it’s running properly can let you sleep at night, knowing that if something blows up, there’s an ever-watchful guardian ready to wake you up so you can fix it. There are a number of monitoring solutions that are popular these days, such [...]
Syntactic sugar will occassionally kick your puppies.
Ruby’s awesome. It has sweet, concise syntax that makes for clean, readable code. One of these constructs is the trailing condition. In most languages where you might have to write something like: if foo then do_stuff end Ruby will let you clean that up with: do_stuff if foo This works just nearly all the time, [...]
Mass inserting data in Rails without killing your performance
Mass inserting is one of those operations that isn’t really well-supported by ActiveRecord, but which has to be done nonethless. You might say, “Well hey, I’ll just run a loop and create a bunch of AR objects, no sweat”. That’ll work, but if speed is a factor, it might not be your best option. ActiveRecord [...]