Wednesday, January 28, 2009

MySql has gone away error using daemon generator.

I've been working with daemon generator in my last rails application, everything works fine but there's just a little issue I had to fix when using ActiveRecord tasks inside the daemon, when the daemon went to sleep for a time greather than the MySql variable wait_timeout, the next time the daemon awakes an error will appear killing the daemon, the full error output can be found in the daemong.rb.log: 




There are many ways to fix this, first you can set the monitor option to true in your daemons config file(daemons.yml file), the only bad thing about this is that it consumes additional memory, in my case memory is a resource I can't spend since my slice server just has 256mb.

What I did to fix this was, everytime Im gonna make a query the database connection is checked, if it's down the daemon has to reconnect it by using:

ActiveRecord::Base.connection.reconnect!

Another thing you can do is set a bigger value in the wait_timeout variable in the MySql config file, depending on what you have to do and your available resources, you should try one of these ways.

2 comments:

aaroncrunch said...

Thanks for this - simple fix to at least one of my problems.

Did you run into any problems with multiple PIDs starting from your Daemon? My resource usage is pretty heavy and I get # sometimes...

Cheers,
Aaron

Peter said...

Pc games free
gta 4 free download