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

[DENO] optimization on write to just queue up #534

Merged
merged 1 commit into from
Jun 9, 2023
Merged

[DENO] optimization on write to just queue up #534

merged 1 commit into from
Jun 9, 2023

Conversation

aricart
Copy link
Member

@aricart aricart commented Jun 8, 2023

@caspervonb this is effectively your simplification, including the changes to support debug and the closing promise.

@aricart aricart requested a review from caspervonb June 8, 2023 15:01
}
this.pendingWrite = writeAll(this.conn, frame).then(() => {
this.pendingWrite = null;
queueMicrotask(() => {
Copy link
Collaborator

@caspervonb caspervonb Jun 8, 2023

Choose a reason for hiding this comment

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

This didn't have an observable effect so unsure if we should be keeping it. Was trying it to see if the stack would empty which it did not seem to. Promises effectively schedules a micro task.

Suggested change
queueMicrotask(() => {
queueMicrotask(() => {

@aricart aricart temporarily deployed to CI June 8, 2023 16:07 — with GitHub Actions Inactive
@caspervonb caspervonb self-requested a review June 9, 2023 14:28
Copy link
Collaborator

@caspervonb caspervonb left a comment

Choose a reason for hiding this comment

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

Benched a bit, definitively faster than main (this is on deno 1.33.x as 1.4 has major issues).

Repositories/nats.deno (on branch 'main') $ deno run --reload -A examples/bench.js --subject a --pub --payload 3500 --count 1000000  --pendingLimit 1024
pub 96,089 msgs/sec - [10.41 secs] ~ 320.73 MB/sec 10407/10407

Repositories/nats.deno (on branch 'write-perf') $ deno run --reload -A examples/bench.js --subject a --pub --payload 3500 --count 1000000  --pendingLimit 1024
pub 421,322 msgs/sec - [2.37 secs] ~ 1.37 GB/sec 2373.4810420000003/2373.4810420000003

await this.enqueue(TE.encode(""));
this.frames.push(Empty);
const d = deferred<void>();
this.maybeWriteFrame(d);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could just await this.pendingWrite here?

@aricart aricart closed this Jun 9, 2023
@aricart aricart temporarily deployed to CI June 9, 2023 16:36 — with GitHub Actions Inactive
@aricart aricart reopened this Jun 9, 2023
@aricart aricart merged commit 5ba20d1 into dev Jun 9, 2023
@aricart aricart deleted the write-perf branch June 9, 2023 17:11
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