Max
Max

Reputation: 15955

ActiveRecord appears to leak memory when connecting to multiple databases

I have a Rails app that downloads a SQLite database on request, saves it a a TempFile and connects to it using ActiveRecord::Base.establish_connection. All the app does is return the entire database as JSON (database is about 10 MB in size). After each request, I explicitly call ActiveRecord::Base.connection.disconnect!. After each request to my app (on my dev box) I noticed that the amount of memory used by the app appears to be ever increasing. How can I stop this from happining?

Just for some numbers:

When I started my app, each worker was using about 100-200m of memory. After less than 100 requests (each request pulls the same DB), each worker is using 500m. I've seen this grow to about 700m each, at which point I have to kill the server because my desktop lags too much.

Upvotes: 3

Views: 613

Answers (1)

Fivell
Fivell

Reputation: 11929

If it is really ActiveRecord cache problem ,try to remove it (it is middleware)

In application.rb:

config.middleware.delete "ActiveRecord::QueryCache"

Upvotes: 1

Related Questions