-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return early from allow list when possible #515
Conversation
542466d
to
19bd6b9
Compare
19bd6b9
to
fdcdcab
Compare
167bd53
to
86b2878
Compare
86b2878
to
8e73b3d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hah, clever change 😄 I have a couple small nits, mostly on the comments. I'd also personally opt to drop the benchmark -- not sure it needs to get merged to the test suite, IMHO documenting it in this PR should and mentioning the optimization in an inline comment should suffice.
Typos Co-authored-by: Adrianna Chang <adrianna.chang@shopify.com>
Co-authored-by: Adrianna Chang <adrianna.chang@shopify.com>
Only reason to keep it is because I suspect an artificial case bench that is a very short query, say As it stands now there is a realistic fixture of a real world query. I don't feel strongly tho. Something else would be to add a Another discussion point but that is larger and should probably live in its own issue is the actual real life effectiveness of the bypass, the need for it, and wether or not AR could just tell us (or is already telling us?) that a query is a COMMIT/ROLLBACK/SAVEPOINT RELEASE in that case we would not have to mess with the raw queries. |
What is this?
Behaviour change:
Savepoints that don't follow the activerecord pattern
active_record_savepoint_#{nesting_level}
or that are nested more than two levels are not going to bypass the circuit anymore.I think this is okay because in the end this is a best effort scenario on an overloaded database and this IS an active record adapter.
In the trilogy adapter.
We look at every single query to see wether or not it should be allowed to pass thru the circuit if it happens to be a transaction control statement, (COMMIT/ROLLBACK/RELEASE SAVEPOINT) because we want to try our hardest to make sure we don't pile open transactions onto MySQL even if the underlying database is overloaded.
Large queries, including queries with long comments (often the case when using marginalia to pass metadata around) will in aggregate use quite a bit of CPU just running regular expressions.
We can exploit the fact that active record trilogy uses a set pattern for savepoint names (`active_record_#{nesting_level}" ) and uses ROLLBACK and COMMIT without any extra characters in the end of the statement to simply return early in most queries by inspecting the last few characters.
FWIW