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

perf(NODE-5771): improve new connection #3948

Merged
merged 12 commits into from
Dec 19, 2023
Merged

Conversation

nbbeeken
Copy link
Contributor

@nbbeeken nbbeeken commented Dec 13, 2023

Description

What is changing?

  • Adds our own version of data event emitter -> asyncIterator helper
    • Notably changes from the standard library, removal of watermark functionality
    • Reduced the generic-ness to only work for data events and remove the need to destructure the value returned by the iterator
  • Removes re-creating a AbortController per command
  • Moves I/O helpers to class methods (to get Typescript privacy functionality)
  • Creates promisified socketWrite helper once at the Connection construction
  • Connects a transform stream to socket that buffers until message size is received
  • Reworks abortable helper to not create a "done" signal, instead simplify the promise wrapping and abort listener removal to lower performance cost
Is there new documentation needed for these changes?

No.

What is the motivation for this change?

Improves the performance of the new connection layer to be on par with our existing connection layer. The major cost was constructing many AbortSignals, however, going back to using a stream to just collect chunks gets us within a margin of error of the old performance.

Double check the following

  • Ran npm run check:lint script
  • Self-review completed using the steps outlined here
  • PR title follows the correct format: type(NODE-xxxx)[!]: description
    • Example: feat(NODE-1234)!: rewriting everything in coffeescript
  • Changes are covered by tests
  • New TODOs have a related JIRA ticket

@nbbeeken nbbeeken force-pushed the NODE-5771-perf-new-connection branch from 70d6ef8 to bb83edb Compare December 14, 2023 22:09
@nbbeeken nbbeeken marked this pull request as ready for review December 15, 2023 16:41
@nbbeeken nbbeeken changed the title chore(NODE-5771): benchmark new connection perf(NODE-5771): improve new connection Dec 15, 2023
@durran durran self-assigned this Dec 18, 2023
@durran durran added the Primary Review In Review with primary reviewer, not yet ready for team's eyes label Dec 18, 2023
Copy link
Contributor

@baileympearson baileympearson left a comment

Choose a reason for hiding this comment

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

nothing blocking since I'm OOO starting tomorrow, just some comments

src/cmap/connection.ts Show resolved Hide resolved
src/cmap/connection.ts Show resolved Hide resolved
src/utils.ts Show resolved Hide resolved
src/utils.ts Show resolved Hide resolved
src/cmap/connection.ts Show resolved Hide resolved
src/cmap/connection.ts Show resolved Hide resolved
Copy link
Member

@durran durran left a comment

Choose a reason for hiding this comment

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

One question - did we also profile memory consumption?

src/cmap/wire_protocol/on_data.ts Show resolved Hide resolved
@durran durran added Team Review Needs review from team and removed Primary Review In Review with primary reviewer, not yet ready for team's eyes labels Dec 19, 2023
@andreialecu
Copy link

Hey @nbbeeken @durran - not sure how to easily bring this to attention, but we discovered this issue: Automattic/mongoose#14877 and it seems to pin down to mongodb 6.4.0

6.3.0 is unaffected. There's a repro in the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team Review Needs review from team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants