Skip to content
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

[wip] sdk perf investigation #208

Merged
merged 1 commit into from
Dec 18, 2023
Merged

Conversation

igalshilman
Copy link
Contributor

No description provided.

@slinkydeveloper slinkydeveloper self-requested a review December 15, 2023 10:28
Copy link
Contributor

@slinkydeveloper slinkydeveloper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me :)

@@ -32,7 +33,11 @@ export function encodeMessage(msg: Message): Uint8Array {
}

export function encodeMessages(messages: Message[]): Uint8Array {
const chunks: Buffer[] = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why Buffer allocates so much then

const headers = [];
let off = 0;

const writer = _m0.Writer.create();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In both the rust and java apis for protobuf there's a way to estimate the size of the message, so you can directly allocate a buffer of message_size + 8. Is it possible here?

// BUT we must wait for the previous flush to end.
this.flushing = this.flushing.then(() => this.scheduleFlush());
}
// tag along to the previously scheduled flush.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe change this comment in something more explicative, e.g.:

  // we don't need to reschedule the `flush` here, 
  // because the flush happens anyway at the end of the current event loop iteration.

this.sdkOutput = rawStream;

this.outputBuffer = new BufferedConnection((buffer) => {
const hasMoreCapacity = rawStream.write(buffer);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this hasMoreCapacity something we need for correctness? could we just get rid of this and simply do rawStream.write?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to keep the current semantics which is also guarded by the tests.
I think these layers need some attention whatever time permits.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But technically you are right

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok then maybe let's track this in a separate issue.

@@ -201,23 +207,16 @@ export class RestateHttp2Connection implements Connection {
* capacity again, so that at least the operations that await results will respect backpressure.
*/
public send(msg: Message): Promise<void> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this promise is never used, can we change the send signature here to be void?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather to keep it as is for now, keep the change minimal.

@igalshilman igalshilman force-pushed the sdk_perf branch 2 times, most recently from e0b3ac1 to d8778e0 Compare December 18, 2023 14:45
This commit overall improves the performances of sending journal entries
to the runtime by 4x, by reducing the number of temporary buffer
allocations, promises, and intermediate serialization.
@igalshilman igalshilman merged commit a18b44c into restatedev:main Dec 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants