Skip to content

net/http: unfurl persistConnWriter's underlying writer #30390

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

Closed
wants to merge 1 commit into from
Closed

net/http: unfurl persistConnWriter's underlying writer #30390

wants to merge 1 commit into from

Conversation

vancluever
Copy link
Contributor

@vancluever vancluever commented Feb 25, 2019

Make persistConnWriter implement io.ReaderFrom, via an io.Copy on the
underlying net.Conn. This in turn enables it to use OS level
optimizations such as sendfile.

This has been observed giving performance gains even in the absence
of ReaderFrom, more than likely due to the difference in io's default
buffer (32 KB) versus bufio's (4 KB).

Speedups on linux/amd64:
benchmark old MB/s new MB/s speedup
BenchmarkFileAndServer_16MB/NoTLS-4 662.96 2703.74 4.08x
BenchmarkFileAndServer_16MB/TLS-4 552.76 1420.72 2.57x

Speedups on darwin/amd64:
benchmark old MB/s new MB/s speedup
BenchmarkFileAndServer_16MB/NoTLS-8 357.58 1972.86 5.52x
BenchmarkFileAndServer_16MB/TLS-8 346.20 1067.41 3.08x

Updates #30377.

@googlebot googlebot added the cla: yes Used by googlebot to label PRs as having a valid CLA. The text of this label should not change. label Feb 25, 2019
@gopherbot
Copy link
Contributor

This PR (HEAD: a2bdd12) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/go/+/163737 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link
Contributor

Message from Chris Marchesi:

Patch Set 1:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/163737.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Emmanuel Odeke:

Patch Set 1:

(15 comments)

Thank you for this work Chris!

I've added some suggestions, PTAL.


Please don’t reply on this GitHub thread. Visit golang.org/cl/163737.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Emmanuel Odeke:

Patch Set 1:

Let's also add some benchmark results for FileAndServer to this CL, if they make sense before the follow-up CL.


Please don’t reply on this GitHub thread. Visit golang.org/cl/163737.
After addressing review feedback, remember to publish your drafts!

@vancluever vancluever changed the title net/http: implement ReaderFrom in persistConnWriter net/http: unfurl persistConnWriter's underlying writer Mar 7, 2019
@gopherbot
Copy link
Contributor

This PR (HEAD: a444ccf) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/go/+/163737 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link
Contributor

Message from Emmanuel Odeke:

Patch Set 3:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/163737.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Chris Marchesi:

Patch Set 1:

(15 comments)

Hey Emmanuel, all done (will follow up on the latest patchset too)

I also have benchmarks and it may be worth posting them. I'll reply on that comment.


Please don’t reply on this GitHub thread. Visit golang.org/cl/163737.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Chris Marchesi:

Patch Set 3:

Patch Set 1:

Let's also add some benchmark results for FileAndServer to this CL, if they make sense before the follow-up CL.

Here are benchmarks for both Linux and Darwin again but just using this CL. Looks like a lot of the gains are just from the implementation alone. #30377 has benchmarks for both CLs that were updated last night after the changes to the actual benchmark code itself.

linux/amd64:

benchmark old ns/op new ns/op delta
BenchmarkFileAndServer_1KB/NoTLS-4 55978 54956 -1.83%
BenchmarkFileAndServer_1KB/TLS-4 64086 63447 -1.00%
BenchmarkFileAndServer_16MB/NoTLS-4 25306601 6205199 -75.48%
BenchmarkFileAndServer_16MB/TLS-4 30351667 11808948 -61.09%
BenchmarkFileAndServer_64MB/NoTLS-4 98800534 24389194 -75.31%
BenchmarkFileAndServer_64MB/TLS-4 117994601 47776165 -59.51%

benchmark old MB/s new MB/s speedup
BenchmarkFileAndServer_1KB/NoTLS-4 18.29 18.63 1.02x
BenchmarkFileAndServer_1KB/TLS-4 15.98 16.14 1.01x
BenchmarkFileAndServer_16MB/NoTLS-4 662.96 2703.74 4.08x
BenchmarkFileAndServer_16MB/TLS-4 552.76 1420.72 2.57x
BenchmarkFileAndServer_64MB/NoTLS-4 679.24 2751.58 4.05x
BenchmarkFileAndServer_64MB/TLS-4 568.75 1404.65 2.47x

benchmark old allocs new allocs delta
BenchmarkFileAndServer_1KB/NoTLS-4 66 69 +4.55%
BenchmarkFileAndServer_1KB/TLS-4 70 71 +1.43%
BenchmarkFileAndServer_16MB/NoTLS-4 68 70 +2.94%
BenchmarkFileAndServer_16MB/TLS-4 4154 1096 -73.62%
BenchmarkFileAndServer_64MB/NoTLS-4 72 72 +0.00%
BenchmarkFileAndServer_64MB/TLS-4 16393 4169 -74.57%

benchmark old bytes new bytes delta
BenchmarkFileAndServer_1KB/NoTLS-4 4939 6008 +21.64%
BenchmarkFileAndServer_1KB/TLS-4 5075 6110 +20.39%
BenchmarkFileAndServer_16MB/NoTLS-4 6298 38383 +509.45%
BenchmarkFileAndServer_16MB/TLS-4 138921 74240 -46.56%
BenchmarkFileAndServer_64MB/NoTLS-4 8298 39048 +370.57%
BenchmarkFileAndServer_64MB/TLS-4 543256 181004 -66.68%

darwin/amd64:

benchmark old ns/op new ns/op delta
BenchmarkFileAndServer_1KB/NoTLS-8 89535 87597 -2.16%
BenchmarkFileAndServer_1KB/TLS-8 94969 93567 -1.48%
BenchmarkFileAndServer_16MB/NoTLS-8 46918741 8503995 -81.88%
BenchmarkFileAndServer_16MB/TLS-8 48460393 15717655 -67.57%
BenchmarkFileAndServer_64MB/NoTLS-8 183066443 34352224 -81.24%
BenchmarkFileAndServer_64MB/TLS-8 201880289 68313850 -66.16%

benchmark old MB/s new MB/s speedup
BenchmarkFileAndServer_1KB/NoTLS-8 11.44 11.69 1.02x
BenchmarkFileAndServer_1KB/TLS-8 10.78 10.94 1.01x
BenchmarkFileAndServer_16MB/NoTLS-8 357.58 1972.86 5.52x
BenchmarkFileAndServer_16MB/TLS-8 346.20 1067.41 3.08x
BenchmarkFileAndServer_64MB/NoTLS-8 366.58 1953.55 5.33x
BenchmarkFileAndServer_64MB/TLS-8 332.42 982.36 2.96x

benchmark old allocs new allocs delta
BenchmarkFileAndServer_1KB/NoTLS-8 66 68 +3.03%
BenchmarkFileAndServer_1KB/TLS-8 70 71 +1.43%
BenchmarkFileAndServer_16MB/NoTLS-8 71 69 -2.82%
BenchmarkFileAndServer_16MB/TLS-8 3971 1126 -71.64%
BenchmarkFileAndServer_64MB/NoTLS-8 83 71 -14.46%
BenchmarkFileAndServer_64MB/TLS-8 15566 4311 -72.31%

benchmark old bytes new bytes delta
BenchmarkFileAndServer_1KB/NoTLS-8 4964 6024 +21.35%
BenchmarkFileAndServer_1KB/TLS-8 5094 6138 +20.49%
BenchmarkFileAndServer_16MB/NoTLS-8 7668 38533 +402.52%
BenchmarkFileAndServer_16MB/TLS-8 136434 75356 -44.77%
BenchmarkFileAndServer_64MB/NoTLS-8 12273 39359 +220.70%
BenchmarkFileAndServer_64MB/TLS-8 519660 191133 -63.22%


Please don’t reply on this GitHub thread. Visit golang.org/cl/163737.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Chris Marchesi:

Patch Set 3:

(1 comment)

Added the speedups for both Linux and Darwin. Let me know if that works!


Please don’t reply on this GitHub thread. Visit golang.org/cl/163737.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Chris Marchesi:

Patch Set 3:

Patch Set 3:

(1 comment)

Added the speedups for both Linux and Darwin. Let me know if that works!

Just waiting for gopherbot. If it didn't take from the GH PR in a few minutes I'll update here.


Please don’t reply on this GitHub thread. Visit golang.org/cl/163737.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Emmanuel Odeke:

Patch Set 4: Run-TryBot+1 Code-Review+2

Awesome, LGTM!


Please don’t reply on this GitHub thread. Visit golang.org/cl/163737.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Gobot Gobot:

Patch Set 4:

TryBots beginning. Status page: https://farmer.golang.org/try?commit=1393de5a


Please don’t reply on this GitHub thread. Visit golang.org/cl/163737.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Gobot Gobot:

Patch Set 4: TryBot-Result+1

TryBots are happy.


Please don’t reply on this GitHub thread. Visit golang.org/cl/163737.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Emmanuel Odeke:

Patch Set 4:

Hey Chris, would you mind rebasing from master as this currently registers as a merge conflict?


Please don’t reply on this GitHub thread. Visit golang.org/cl/163737.
After addressing review feedback, remember to publish your drafts!

Make persistConnWriter implement io.ReaderFrom, via an io.Copy on the
underlying net.Conn. This in turn enables it to use OS level
optimizations such as sendfile.

This has been observed giving performance gains even in the absence
of ReaderFrom, more than likely due to the difference in io's default
buffer (32 KB) versus bufio's (4 KB).

Updates #30377.
@gopherbot
Copy link
Contributor

This PR (HEAD: a6f67cd) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/go/+/163737 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link
Contributor

Message from Chris Marchesi:

Patch Set 5:

Patch Set 4:

Hey Chris, would you mind rebasing from master as this currently registers as a merge conflict?

Hey Emmanuel, just did it. Oddly enough I wasn't asked to resolve any conflicts, so hopefully this clears it up!


Please don’t reply on this GitHub thread. Visit golang.org/cl/163737.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Emmanuel Odeke:

Patch Set 5: Run-TryBot+1

Patch Set 5:

Patch Set 4:

Hey Chris, would you mind rebasing from master as this currently registers as a merge conflict?

Hey Emmanuel, just did it. Oddly enough I wasn't asked to resolve any conflicts, so hopefully this clears it up!

Yes, that rebase cleared it up and after this is submitted, please do rebase the
remaining CL but also let's centralize and reuse the test code from here too.


Please don’t reply on this GitHub thread. Visit golang.org/cl/163737.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Gobot Gobot:

Patch Set 5:

TryBots beginning. Status page: https://farmer.golang.org/try?commit=2cc31de4


Please don’t reply on this GitHub thread. Visit golang.org/cl/163737.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Gobot Gobot:

Patch Set 5: TryBot-Result+1

TryBots are happy.


Please don’t reply on this GitHub thread. Visit golang.org/cl/163737.
After addressing review feedback, remember to publish your drafts!

gopherbot pushed a commit that referenced this pull request Mar 7, 2019
Make persistConnWriter implement io.ReaderFrom, via an io.Copy on the
underlying net.Conn. This in turn enables it to use OS level
optimizations such as sendfile.

This has been observed giving performance gains even in the absence
of ReaderFrom, more than likely due to the difference in io's default
buffer (32 KB) versus bufio's (4 KB).

Speedups on linux/amd64:
benchmark                               old MB/s     new MB/s     speedup
BenchmarkFileAndServer_16MB/NoTLS-4     662.96       2703.74      4.08x
BenchmarkFileAndServer_16MB/TLS-4       552.76       1420.72      2.57x

Speedups on darwin/amd64:
benchmark                               old MB/s     new MB/s     speedup
BenchmarkFileAndServer_16MB/NoTLS-8     357.58       1972.86      5.52x
BenchmarkFileAndServer_16MB/TLS-8       346.20       1067.41      3.08x

Updates #30377.

Change-Id: Ic88d4ac254f665223536fcba4d551fc32ae105b6
GitHub-Last-Rev: a6f67cd
GitHub-Pull-Request: #30390
Reviewed-on: https://go-review.googlesource.com/c/go/+/163737
Run-TryBot: Emmanuel Odeke <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Emmanuel Odeke <[email protected]>
@gopherbot
Copy link
Contributor

This PR is being closed because golang.org/cl/163737 has been merged.

@gopherbot gopherbot closed this Mar 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Used by googlebot to label PRs as having a valid CLA. The text of this label should not change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants