-
Notifications
You must be signed in to change notification settings - Fork 343
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
SQLite: Don't bill for internal queries. #3605
base: main
Are you sure you want to change the base?
Conversation
We bill for: - SQL queries issued via the JavaScript SQL API. - DO old-style key/value storage operations. Anything else, we assume is an internal query, and not billed.
LGTM |
@@ -15,6 +15,11 @@ namespace workerd { | |||
// of KJ exceptions which become internal errors. | |||
class SqliteKvRegulator: public SqliteDatabase::Regulator { | |||
void onError(kj::Maybe<int> sqliteErrorCode, kj::StringPtr message) const override; | |||
|
|||
// We bill for KV operations as rows read/written. | |||
virtual bool shouldAddQueryStats() const override { |
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.
(I guess the stmtCountKeys
prepared statement doesn't use this regulator yet, so would be excluded from stats, but not sure if that query represents notable overhead.)
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.
Ah good catch, probably should fix that.
Nice... When I was thinking about how to implement something similar, I was considering adding a "reportingId" value to queries, which could then be passed as an additional parameter to I guess I also don't know enough about the query stats recording to know if running "ROLLBACK" as a system query -- after running some user queries -- results in significant overhead that we'd want included in user metrics. But maybe that's not a big deal, as long as the stats of the initial execution get recorded and are roughly proportional to what the rollback metrics would be. |
The overhead of ROLLBACK is pretty minimal, the WAL just gets truncated back to an earlier point. In fact, any writes that end up rolled back never even leave the local machine, so you could argue a rollback should actually roll back the billing counters! But that would be complicated to implement and awkward to explain. |
We bill for:
Anything else, we assume is an internal query, and not billed.