-
-
Notifications
You must be signed in to change notification settings - Fork 89
Boost performance by batching Rows #153
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
Conversation
| case forwardRow([PSQLData], to: EventLoopPromise<StateMachineStreamNextResult>) | ||
| case forwardCommandComplete(CircularBuffer<[PSQLData]>, commandTag: String, to: EventLoopPromise<StateMachineStreamNextResult>) | ||
| case forwardStreamError(PSQLError, to: EventLoopPromise<StateMachineStreamNextResult>, cleanupContext: CleanUpContext?) | ||
| // actions if query has not asked for next row but are pushing the final bytes to it | ||
| case forwardStreamErrorToCurrentQuery(PSQLError, read: Bool, cleanupContext: CleanUpContext?) | ||
| case forwardStreamCompletedToCurrentQuery(CircularBuffer<[PSQLData]>, commandTag: String, read: Bool) | ||
| case forwardRows(CircularBuffer<PSQLBackendMessage.DataRow>) | ||
| case forwardStreamComplete(CircularBuffer<PSQLBackendMessage.DataRow>, commandTag: String, read: Bool) | ||
| case forwardStreamError(PSQLError, read: Bool, cleanupContext: CleanUpContext?) |
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.
Reduction in Actions 🥳
| let promise = self.eventLoop.makePromise(of: Row?.self) | ||
| self.downstreamState = .waitingForNext(promise) | ||
| self.upstreamState = .streaming(buffer: buffer, dataSource: dataSource) | ||
| dataSource.request() |
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.
@weissi This is the invocation, where the PSQLRowStream asks for more rows. We could change this to:
context.channel.triggerUserOutboundEvent(PSQLRowStreamEvent.requestMoreRows, promise: nil)d8b1e1b to
468a648
Compare
Adding some performance numbers... (Swift main on focal in docker)Running a query
this branch: While the speed bump is nice. Even more important: The query doesn't use 100% cpu anymore. |
468a648 to
0840cbb
Compare
0840cbb to
e20f441
Compare
|
This is really enticing, any chance we can port this easily to MySQL as well? 👀 |
|
Ah, I see |
2fe77c2 to
65200ab
Compare
@jdmcd FWIW this is something I've already got on my list to look into for MySQL 🙂 |
65200ab to
bdd2ce4
Compare
|
Just applied another fix. Will push shortly. On Swift 5.5 nightly: |
f399384 to
a693d81
Compare
Sources/PostgresNIO/New/Connection State Machine/ExtendedQueryStateMachine.swift
Outdated
Show resolved
Hide resolved
a693d81 to
ab4d9e6
Compare
e6dd752 to
250249e
Compare
250249e to
eb29f7a
Compare
Co-authored-by: Gwynne Raskind <gwynne@darkrainfall.org>
eb29f7a to
6525241
Compare
In #135 a connection state machine was introduced. To keep this simple at first, the state machine operates on single
PostgresBackendMessages. This is very inefficient for queries that result in a lot of rows. This PR improves query performance by badging Postgres data row messages at theDecoderand operating on those batches from there on.Open ends: