More posts about: Uncategorized // Add Comment »
Checking on one of my projects (a Ruby on Rails survey site), I realized that it was running painfully slowly, taking 30 seconds to render a page.
The first thing I checked was memory. I was on a 256MB slice at Rackspace Cloud. Was the server running out of memory and swapping to disk? I put in the recommended settings for Apache+Passenger+Rails on 256MB:
RailsSpawnMethod smart PassengerUseGlobalQueue on PassengerMaxPoolSize 2 PassengerPoolIdleTime 0 PassengerMaxRequests 1000 RailsAppSpawnerIdleTime 0 PassengerStatThrottleRate 5
The website was still crawling. I reviewed the logs and found that ActiveRecord was taking a while. The Internet had a few performance optimization tips, so I checked out the survey controller to see if I could improve performance by preloading information.
As it turned out, I was already preloading information. So I tried turning off preloading by removing the :include directives for my queries.
The system went back to a decent speed.
You see, I’d been working with lots of associations, and eager loading had probably resulted in a gazillion rows in my result set.
Moral lesson: Test your system before and after you put in something to improve the performance, because you just might be making your performance worse. ;)
Oh well. Live and learn!