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

refactor(ext/http) refer to HttpRecord directly using v8::External #20770

Merged
merged 11 commits into from
Nov 13, 2023

Conversation

lrowe
Copy link
Contributor

@lrowe lrowe commented Oct 3, 2023

Makes the JavaScript Request use a v8:External opaque pointer to directly refer to the Rust HttpRecord.

The HttpRecord is now reference counted. To avoid leaks the strong count is checked at request completion.

Performance seems unchanged on the minimal benchmark. 118614 req/s this branch vs 118564 req/s on main, but variance between runs on my laptop is pretty high.

@lrowe
Copy link
Contributor Author

lrowe commented Oct 3, 2023

@mmastrac I believe this is ready for review, let me know if anything else is needed.

I recommend reviewing commit by commit since the renaming to remove the slab terminology is quite noisy.

Log of serve_test with __http_tracing enabled: https://gist.github.com/lrowe/c91d41898156ddbb529a525027f29cf4

@ry
Copy link
Member

ry commented Oct 3, 2023

nice!

ext/http/http_next.rs Outdated Show resolved Hide resolved
@mmastrac
Copy link
Contributor

mmastrac commented Oct 3, 2023

Great work! This looks exactly like we discussed. Good job on the additional optimizations as well.

I looked over it once and didn't see anything that looked out of place, but I'll take another pass.

ext/http/00_serve.js Show resolved Hide resolved
ext/http/00_serve.js Show resolved Hide resolved
@lrowe
Copy link
Contributor Author

lrowe commented Oct 3, 2023

I may be able to eke out another half a percent or so of performance by pooling Rc<HttpRecord>. Needs a bit more work and can probably be a follow up: lrowe@3502a2c

Ideally I'd like to get to the point where the HttpRecord lives on the service future and those futures are pooled, but I'm not sure that's quite possible without async drop since the service future might be dropped midway (e.g. on TCP connection closed) but the HttpRecord must live until the JS serve handler completes.

Copy link
Contributor

@mmastrac mmastrac left a comment

Choose a reason for hiding this comment

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

I think this is good to go. Great simplifications. We'll need to run our benchmarks after landing this but I'm very positive.

ext/http/http_next.rs Show resolved Hide resolved
@mmastrac mmastrac force-pushed the lrowe-http-external branch 3 times, most recently from 064e87f to 393d48b Compare November 7, 2023 20:46
@mmastrac mmastrac self-assigned this Nov 7, 2023
@mmastrac mmastrac dismissed lucacasonato’s stale review November 12, 2023 19:49

Addressed via deno_core type-checked externals

@mmastrac mmastrac merged commit 542314a into denoland:main Nov 13, 2023
13 checks passed
@mmastrac
Copy link
Contributor

/bench http[minimal,realistic]

@denobot
Copy link
Collaborator

denobot commented Nov 13, 2023

http[minimal]

rps latency bytes relative
node 90,249 109.46 µs σ=34.61 767,812 kB -71.1%
bun 312,028 32.02 µs σ=14.79 1,533,203 kB best
deno 165,739 58.48 µs σ=16.89 1,357,421 kB -46.9%
deno-baseline 165,115 58.7 µs σ=17.2 1,357,421 kB -47.1%

http[realistic]

rps latency bytes relative
node 85,506 116.39 µs σ=40.57 917,968 kB -56.6%
bun 196,957 58.41 µs σ=131.56 1,845,703 kB best
deno 137,385 71.33 µs σ=22.79 1,455,078 kB -30.2%
deno-baseline 138,979 70.79 µs σ=24.16 1,474,609 kB -29.4%

start: Mon, 13 Nov 2023 14:09:38 GMT

id: f4504aa3-eafc-432b-b66f-34993f537d0f

server: b68c4a9b-f978-4d6f-9902-2cc24976581d

mmastrac added a commit that referenced this pull request Nov 13, 2023
Reuse existing existing allocations for HttpRecord and response
HeaderMap where possible.

At request end used allocations are returned to the pool and the pool
and the pool sized to 1/8th the current number of inflight requests.

For http1 hyper will reuse the response HeaderMap for the following
request on the connection.

Builds upon #20770

---------

Co-authored-by: Matt Mastracci <[email protected]>
mmastrac added a commit that referenced this pull request Nov 13, 2023
…dy completion (#20822)

Use HttpRecord as response body so requests can be tracked all the way
to response body completion.

This allows Request properties to be accessed while the response body is
streaming.

Graceful shutdown now awaits a future instead of async spinning waiting
for requests to finish.

On the minimal benchmark this refactor improves performance an
additional 2% over pooling alone for a net 3% increase over the previous
deno main branch.

Builds upon #20809 and
#20770.

---------

Co-authored-by: Matt Mastracci <[email protected]>
kt3k pushed a commit that referenced this pull request Nov 17, 2023
…20770)

Makes the JavaScript Request use a v8:External opaque pointer to
directly refer to the Rust HttpRecord.

The HttpRecord is now reference counted. To avoid leaks the strong count
is checked at request completion.

Performance seems unchanged on the minimal benchmark. 118614 req/s this
branch vs 118564 req/s on main, but variance between runs on my laptop
is pretty high.

---------

Co-authored-by: Matt Mastracci <[email protected]>
kt3k pushed a commit that referenced this pull request Nov 17, 2023
Reuse existing existing allocations for HttpRecord and response
HeaderMap where possible.

At request end used allocations are returned to the pool and the pool
and the pool sized to 1/8th the current number of inflight requests.

For http1 hyper will reuse the response HeaderMap for the following
request on the connection.

Builds upon #20770

---------

Co-authored-by: Matt Mastracci <[email protected]>
kt3k pushed a commit that referenced this pull request Nov 17, 2023
…dy completion (#20822)

Use HttpRecord as response body so requests can be tracked all the way
to response body completion.

This allows Request properties to be accessed while the response body is
streaming.

Graceful shutdown now awaits a future instead of async spinning waiting
for requests to finish.

On the minimal benchmark this refactor improves performance an
additional 2% over pooling alone for a net 3% increase over the previous
deno main branch.

Builds upon #20809 and
#20770.

---------

Co-authored-by: Matt Mastracci <[email protected]>
zifeo pushed a commit to metatypedev/deno that referenced this pull request Nov 22, 2023
…enoland#20770)

Makes the JavaScript Request use a v8:External opaque pointer to
directly refer to the Rust HttpRecord.

The HttpRecord is now reference counted. To avoid leaks the strong count
is checked at request completion.

Performance seems unchanged on the minimal benchmark. 118614 req/s this
branch vs 118564 req/s on main, but variance between runs on my laptop
is pretty high.

---------

Co-authored-by: Matt Mastracci <[email protected]>
zifeo pushed a commit to metatypedev/deno that referenced this pull request Nov 22, 2023
…#20809)

Reuse existing existing allocations for HttpRecord and response
HeaderMap where possible.

At request end used allocations are returned to the pool and the pool
and the pool sized to 1/8th the current number of inflight requests.

For http1 hyper will reuse the response HeaderMap for the following
request on the connection.

Builds upon denoland#20770

---------

Co-authored-by: Matt Mastracci <[email protected]>
zifeo pushed a commit to metatypedev/deno that referenced this pull request Nov 22, 2023
…dy completion (denoland#20822)

Use HttpRecord as response body so requests can be tracked all the way
to response body completion.

This allows Request properties to be accessed while the response body is
streaming.

Graceful shutdown now awaits a future instead of async spinning waiting
for requests to finish.

On the minimal benchmark this refactor improves performance an
additional 2% over pooling alone for a net 3% increase over the previous
deno main branch.

Builds upon denoland#20809 and
denoland#20770.

---------

Co-authored-by: Matt Mastracci <[email protected]>
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.

None yet

7 participants