Change the prepared statement limit#256
Merged
Merged
Conversation
New approach! What could happen is that when multiple projects are
generating invoices at the same time, we generate a lot of prepared
statements, which causes the OOM.
I checked the work_mem of our pg:
select * from pg_settings where name='work_mem';
32768kB
We have sidekiq running with a concurrency of 20, the default prepared
statement limit of Rails is 1000, so that could quickly become 20000
prepared statements that we keep in cache, and thus we might overload
our pg and get the dreaded OOM message.
This would also explain that when running them at another time, we
don't run into it.
Questions remaining:
- Is this really the way to configure a DB on Heroku? (Looks like it)
- Do we also want to run it like this on the web-dyno's? I think we
can do a `Sidekiq.server?` like method to isolate the behavior.
- I matched the default Rails configuration but want to lower it to
something like 200. Which might make it slower but should make it
more dependable. It's hard to tell without more logs from Heroku.
Let's not break CI
Make test env use passed in keys or defaults
And let's pass in the host
And just to be sure the port as well
Move all DB pool size to database.yml
I've also added a small rake task to output the right number, normally
the SIDEKIQ_CONCURRENCY will always be higher than the amount of web
workers, so no need to set the DB_POOL, but just in case.
noop. Offer pearls to the linter gods
noop. Remove the copy/pasted dot
1e1b19c to
d1a7dff
Compare
Contributor
Author
So our statement_limit is coming through. But the pool size is 2 (because the sidekiq concurrency is set to 2 and that overrides the rails max threads) and that is wrong. |
Contributor
Author
|
And now it worked: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
New approach! What could happen is that when multiple projects are
generating invoices at the same time, we generate a lot of prepared
statements, which causes the OOM.
I checked the work_mem of our pg:
We have sidekiq running with a concurrency of 20, the default prepared
statement limit of Rails is 1000, so that could quickly become 20000
prepared statements that we keep in cache, and thus we might overload
our pg and get the dreaded OOM message.
This would also explain that when running them at another time, we
don't run into it.
Questions remaining:
Is this really the way to configure a DB on Heroku?(Looks like it)Do we also want to run it like this on the web-dyno's? I think weWe can change after the fact, doesn't look to do any immediate harm.can do a
Sidekiq.server?like method to isolate the behavior.I matched the default Rails configuration but want to lower it toIt's just an env variable, so easily changed an adapted.something like 200. Which might make it slower but should make it
more dependable. It's hard to tell without more logs from Heroku.
I ran the config.rake on production (by copy pasting into a repl):
Which makes sense, since we only change the pool size in the Sidekiq initializer. After this PR has been deployed I would expect the
ActiveRecord::Base.connection_pool.sizeto be20and theActiveRecord::Base.configurations[Rails.env]should contain our newly added settings.When we hit the PG OOM errors, we should run
select * from pg_prepared_statements, and this should normally show about sidekiq_workers*1000 items (thus eating our memory)