Marginalia with request_id and job_id bloats PostgreSQLAdapter::StatementPool
keithpitt opened this issue · 5 comments
Hey! I just discovered that if you include the http request_id
or the ActiveJob
job id inside the marginalia annotation, it will bloat the the PostgreSQLAdapter::StatementPool cache.
Each unique SQL query will create a new prepared_statement entry, and because of the unique annotation, it won't get re-used, so it will just sit around in memory doing nothing. Here is the line inside Rails that generates the prepared statement:
Here is a screenshot of me listing all the entries in the statement pool, and you'll be able to see a query that could have been re-used, but wasn't because of the unique annotation.
So each unique combination of the annotation will result in a new prepared statement entry. I'm not sure how to fix this, or even if there is a possible fix? Maybe use of marginalia means that you can't use the prepared statement cache?
Is this still an issue?
@ACPK we actually turned off prepared statements in our app, so I'm not entirely sure!
Should comment be ignored when generating prepared_statement entries?
I've added a warning to the README:
https://github.com/basecamp/marginalia/blob/master/README.md#prepared-statements
Prepared statements can still be useful when using low cardinality components, so I don't think should be automatically disabled. But they're a pretty spikey caveat.