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

feat: dispatch #300

Merged
merged 2 commits into from
Aug 8, 2020
Merged

feat: dispatch #300

merged 2 commits into from
Aug 8, 2020

Conversation

ronag
Copy link
Member

@ronag ronag commented Aug 4, 2020

Makes our internal API public. This is the API which our public API is implemented on top.

There is need for some internal cleanup and refactor post this PR. I've tried to keep the changes as small as possible for easy of review.

I am not 100% satisfied with the API. However, I believe it does fullfil functional and performance requirements. Would appreciate some feedback and maybe ideas. I suspect this API might evolve/improve over time and be less stable than the other ones.

Some problems that might or might not need to be resolved:

  • There is now two AsyncResources, the handler object and Request object. Depending on whether the implementation needs to asynchronously propagate async scope.

  • It's a bit weird that _onConnect takes a resume function.

  • Not sure about naming for _onConnect.

  • It's a bit weird that _onData should return null to indicate an aborted message.

Refs: #293

_onUpgrade(statusCode, headers, socker): Void
_onHeaders(statusCode, headers, resume): Void
_onData(chunk): Boolean|Null
_onComplete(trailers): Void
_onErrror(err): Void

@ronag ronag marked this pull request as ready for review August 4, 2020 20:15
@ronag
Copy link
Member Author

ronag commented Aug 4, 2020

@szmarczak

README.md Outdated
undici - request x 11,949 ops/sec ±0.99% (85 runs sampled)
undici - stream x 12,223 ops/sec ±0.76% (85 runs sampled)
http - keepalive x 5,392 ops/sec ±6.66% (68 runs sampled)
undici - pipeline x 7,055 ops/sec ±3.54% (79 runs sampled)
Copy link
Member Author

Choose a reason for hiding this comment

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

pipeline performance regression is from a previous commit. Haven't bisected yet.

@szmarczak
Copy link
Member

szmarczak commented Aug 4, 2020

The new API looks good IMO.

Instead of returning true / false / null I think it would be clearer to return a constant e.g.

  • undici.RESUME
  • undici.PAUSE
  • undici.ABORT

Just an idea.

@ronag
Copy link
Member Author

ronag commented Aug 4, 2020

Just an idea.

That's kind of nice. Less magical.

@ronag ronag force-pushed the dispatch2 branch 2 times, most recently from 35c1454 to 62c2ac4 Compare August 4, 2020 20:39
@ronag
Copy link
Member Author

ronag commented Aug 4, 2020

Another alternative is something like:

_onConnect(controller)

Where controller has the following methods:

pause()
resume()
abort()
runInAsyncScope()

Which would resolve the async resource issue as well... at the cost of an extra object allocation.

EDIT: the runInAsyncScope won't work since we would need it before _onConnect.

README.md Outdated Show resolved Hide resolved
lib/client-connect.js Outdated Show resolved Hide resolved
lib/client-upgrade.js Outdated Show resolved Hide resolved
@ronag
Copy link
Member Author

ronag commented Aug 7, 2020

@mcollina I think perf diff is within margin of error now...

@ronag ronag force-pushed the dispatch2 branch 2 times, most recently from 077bf58 to 36de249 Compare August 8, 2020 10:08
@ronag
Copy link
Member Author

ronag commented Aug 8, 2020

master:

undici - pipeline x 7,225 ops/sec ±1.49% (273 runs sampled)
undici - request x 11,760 ops/sec ±0.90% (277 runs sampled)
undici - stream x 12,568 ops/sec ±0.79% (280 runs sampled)
undici - simple x 12,949 ops/sec ±0.59% (278 runs sampled)
undici - noop x 19,087 ops/sec ±1.19% (259 runs sampled)

dispatch2:

undici - pipeline x 7,281 ops/sec ±1.68% (273 runs sampled)
undici - request x 11,700 ops/sec ±0.56% (278 runs sampled)
undici - stream x 12,684 ops/sec ±0.72% (280 runs sampled)
undici - dispatch x 13,446 ops/sec ±0.37% (276 runs sampled)
undici - noop x 19,590 ops/sec ±1.06% (255 runs sampled)

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@ronag ronag merged commit 1c961cf into master Aug 8, 2020
@ronag ronag deleted the dispatch2 branch August 8, 2020 11:48
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.

3 participants