Tag: agile

Handling errors

Posted by on 24-Nov-2005

In the development environment, evebody sees the debugging screen when something goes wrong. In the production environment, you only get a debugging screen, when operating from localhost.

But because of the memory leak in the current rails implementation, almost everybody now using production environment, even during the development. Action Controller have a protected method called local_request? to determine if the request is comming from a local host. Add your development machine(s) to it:

def local_request?
  [ "127.0.0.1", "192.168.1.123" ].include?(request.remote_ip)
end

Apache and FastCGI

Posted by on 24-Nov-2005

An example config:

<IfModule mod_fastcgi.c>
  FastCgiIpcDir /tmp/fcgi_ipc
  FastCgiServer /path/to/myapp/dispatch.fcgi \
    -initial_env RAILS_ENV=production \
    -processes 15 -idle-timeout 60
</IfModule>

The important part is FastCgiServer . It creating static server definition – 15 fastcgi servers are started right after the server is launched and running until the server is stopped. That whay is faster that to relay on Apache to start the servers when the first time .fcgi page is accessed (dynamic server definition).

idle-timeout also is critical value. If any request takes longer than the limit, Apache will assume the FastCGI process crashed and return an error 500. If the application talks to remote servers (process requests slower) increase the idle-timeout from the default 30 to 60 seconds.

Clearing ActiveRecord-saved sessions

Posted by on 24-Nov-2005

AWDwR book is full with wizdom. Will try to post here from time to time a small gems from it, suitable for our Rails production environment. So the first gem, something like an extension to the previous Storing sessions in your database post.

Sessions accumulate and are never removed. We need to do cleaning ourselves. To delete files, that haven’t been touched in the last 12 hours, with the file-based session handler we can do (possible invoked by cron):

find /tmp/ -name 'ruby_sess*' -ctime +12h -delete

Interesting is however how to clean database saved sessions. Enter AWDwR:

cd myapp && RAILS_ENV=production ./script/runner \
'ActiveRecord::Base.connection.delete
    "DELETE from sessions WHERE updated_at < now() - 12*3600"'