thiagopradi / octopus

Database Sharding for ActiveRecord
2.53k stars 505 forks source link

ActiveRecord runtime not shown in log #186

Closed arr-dev closed 10 years ago

arr-dev commented 11 years ago

When Octopus is enabled, no ActiveRecord runtime is shown in logs.

Completed 200 OK in 1263ms (Views: 693.4ms) 

Without Octopus, it works fine.

Completed 200 OK in 1873ms (Views: 1115.3ms | ActiveRecord: 126.5ms)

Some quick workaround would be good also

arr-dev commented 11 years ago

I have seem to found the issue.

It happens only when used with Unicorn.

Workaround is to use

after_fork do |server, worker|
    ActiveRecord::Base.connection.initialize_shards(Octopus.config)
end

as suggested by @LongMan in #59.

I have also added a before fork

before_fork do |server, worker|
  ActiveRecord::Base.connection_proxy.instance_variable_get(:@shards).each do |shard, connection_pool|
    connection_pool.disconnect!
  end
end

but even without it, it works fine, with after_fork, of course.

Is this correct, will it cause some issues I am not aware of?

thiagopradi commented 10 years ago

Hi @soul-rebel ,

I don't see any side effects of your fix. I'm closing your issue, if you need more help, please reopen.

Best,

Thaigo