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

http2: adjust error emit in core, add tests #15586

Closed

Conversation

apapirovski
Copy link
Member

@apapirovski apapirovski commented Sep 24, 2017

This PR updates http2/core to need less bindings and closures when emitting various events, instead it uses the already existing ability of process.nextTick and setImmediate to pass through arguments. Despite having to use a rest parameter, this is actually faster than binding or creating a closure. My understanding is that with V8 6.2 this code will only get faster.

(Also there's a minor fix for the fact that incorrect headers passed to the various respond with file methods weren't correctly exiting after an error and instead continued to run the rest of the function.)

I adjusted the existing headers benchmark to use a few more of the affected functions and the benchmark result is below (this is over 250 iterations for each node version). Not a huge difference but probably still worthwhile. (The headers benchmark is the best for assessing these changes because it runs into these event emits on both the client and the server. I only used nheaders at 0 because the other variations stress the wrong parts of the system that we don't care about.)

http2/headers.js nheaders=0 n=1000       1.80 %        *** 6.068982e-12

I've also added tests to cover most of these emits throughout the code. There are a few spots left uncovered but I'll need to figure out a slightly different way of testing than just mocking the handle method to output error codes. I don't think that should hold up this PR though as they were already not covered by tests.

Thanks for reviewing!

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

http2, test

@nodejs-github-bot nodejs-github-bot added the http2 Issues or PRs related to the http2 subsystem. label Sep 24, 2017
break;
default:
// Some other unexpected error was reported.
if (ret < 0) {
err = new NghttpError(ret);
process.nextTick(() => this.emit('error', err));
process.nextTick(emit, stream, 'error', err);
Copy link
Member Author

Choose a reason for hiding this comment

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

I checked the C++ code and I checked nghttp2 documentation and I believe this is supposed to emit on stream. Let me know if I'm wrong.

break;
default:
// Some other unexpected error was reported.
if (ret < 0) {
err = new NghttpError(ret);
process.nextTick(() => this.emit('error', err));
process.nextTick(emit, stream, 'error', err);
Copy link
Member Author

Choose a reason for hiding this comment

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

Same as above.

I checked the C++ code and I checked nghttp2 documentation and I believe this is supposed to emit on stream. Let me know if I'm wrong.

Copy link
Member

@jasnell jasnell left a comment

Choose a reason for hiding this comment

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

LGTM.
btw, thank you for jumping in on the http2 work!

@apapirovski
Copy link
Member Author

apapirovski commented Sep 25, 2017

Thanks @jasnell! I appreciate the opportunity to help out.

Should have more commits flowing in over the week as I've been able to get express to run with http2 (more specifically their tests which are quite thorough) and am fixing quite a few h1 compatibility bugs/inconsistencies.

Copy link
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

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

Overall LGTM but I am pretty unhappy with the many code duplication in the tests (runTest). Is there any way to improve that? I can not think of anything good out of my head right now.

@apapirovski
Copy link
Member Author

@BridgeAR ya I know. I might revisit trying to group some of the http2 tests in a separate PR. I'm not sure that it's particularly easy for these ones though.

@apapirovski
Copy link
Member Author

Could we get a CI started for this, please? Thanks!

@jasnell
Copy link
Member

jasnell commented Sep 28, 2017

@apapirovski apapirovski force-pushed the patch-http2-closures-and-tests branch from 1e6316e to 25662fe Compare September 30, 2017 13:59
@apapirovski
Copy link
Member Author

apapirovski commented Sep 30, 2017

Looks like the CI was green. I've also rebased this and removed the --expose-http2 from the new tests. Let me know if anything else is needed to get this merged. Thanks!

Update: Copy & pasted the wrong commit message, force pushed again.

Use the ability of nextTick and setImmediate to pass arguments
instead of creating closures or binding. Add tests that cover
the vast majority of error emits.
@apapirovski apapirovski force-pushed the patch-http2-closures-and-tests branch from 25662fe to 1861beb Compare September 30, 2017 14:06
@jasnell
Copy link
Member

jasnell commented Oct 1, 2017

@BridgeAR
Copy link
Member

BridgeAR commented Oct 1, 2017

Landed in ccd3afc

@BridgeAR BridgeAR closed this Oct 1, 2017
BridgeAR pushed a commit that referenced this pull request Oct 1, 2017
Use the ability of nextTick and setImmediate to pass arguments
instead of creating closures or binding. Add tests that cover
the vast majority of error emits.

PR-URL: #15586
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
@apapirovski
Copy link
Member Author

Thanks Ruben!

MylesBorins pushed a commit that referenced this pull request Oct 3, 2017
Use the ability of nextTick and setImmediate to pass arguments
instead of creating closures or binding. Add tests that cover
the vast majority of error emits.

PR-URL: #15586
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
@MylesBorins MylesBorins mentioned this pull request Oct 3, 2017
MylesBorins pushed a commit that referenced this pull request Oct 3, 2017
Use the ability of nextTick and setImmediate to pass arguments
instead of creating closures or binding. Add tests that cover
the vast majority of error emits.

PR-URL: #15586
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
addaleax pushed a commit to addaleax/ayo that referenced this pull request Oct 4, 2017
Use the ability of nextTick and setImmediate to pass arguments
instead of creating closures or binding. Add tests that cover
the vast majority of error emits.

PR-URL: nodejs/node#15586
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
MylesBorins pushed a commit that referenced this pull request Oct 11, 2017
Use the ability of nextTick and setImmediate to pass arguments
instead of creating closures or binding. Add tests that cover
the vast majority of error emits.

PR-URL: #15586
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
@apapirovski apapirovski deleted the patch-http2-closures-and-tests branch October 14, 2017 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
http2 Issues or PRs related to the http2 subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants