Archive for the 'rails' Category

rails fixtures with models using set_table_name

Sunday, April 22nd, 2007

If you have a model that uses set_table_name you may hit a snag when trying to use fixtures and unit tests. The solution is twofold: name the fixture file using the legacy table name, and use the set_fixture_class method in your unit test. I coudn’t find this method mentioned in Agile Web Development with Rails, and there’s only a brief mention on the rubyonrails.com site. Still, some web searches turned up the answers.

Here is a simple example:

(more…)

Latest on Rails Performance

Sunday, April 1st, 2007

Updated Rails 1.2 performance numbers have been released. While these number look pretty good it is hard to get a good idea of exactly what the performance of Rails is. A couple of other benchmarks that include Rails such as performance tests for 6 frameworks and Grails vs Rails benchmarks show a different picture. Both of these come up with much worse performance than the first. Maybe the issue is that the second two benchmarks are using Apache ab but the first uses a new version of rails bench. Of course most people probably aren’t that worried about the benchmarks that much because you can find ways to make anything fast as shown with Rails doing 4000 requests a second.

Cleaning Up Rails Sessions, Revisited

Saturday, September 16th, 2006

In an earlier post, we detailed a method for removing stale Rails session files. In more recent version of Rails, there is a Rake task built in for this administration task.

rake tmp:sessions:clear # Clears all files in tmp/sessions

Cleaning up stale rails sessions (removing ruby_sess files)

Thursday, June 8th, 2006

I’m not sure if something isn’t set up correctly of if this is just a fact of life with rails but the sessions it creates never seem to go away. I think before rails 1.1 the sessions where stored in /tmp and now they are stored in the apps directory along with everything else so they is probably no internal mechanism to delete them. I only noticed because after about a month of an certain app running the disk on the machine started to fill up. After digging a little I found 50K ruby_sess.* files hanging out in the rails session directory.

Anyway it was easy enough to clean up the stale ruby_sess files by going into the rails webapp/session directory and then running the following command:

find -type f -name "ruby_sess*" -exec rm -f {} \\;

I’m not sure why the app is creating sessions but it isn’t something that stores state so I didn’t have to worry about killing active sessions here. If you do need to worry about that you will probably want to toss a time on the find command.

After looking a little more I found a post about this that has a ruby way of cleaning up the sessions.