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

Add basic overhead benchmarks #46

Merged
merged 4 commits into from
Jul 5, 2023
Merged

Add basic overhead benchmarks #46

merged 4 commits into from
Jul 5, 2023

Conversation

jchadwick-buf
Copy link
Member

The intent of this benchmark is not to show off the performance of httplb, but instead the overhead. Since under the hood httplb still uses net/http and all of its primitives, the baseline performance is dictated by how net/http performs. By comparing a very similar codepath through httplb.Client and net/http.Client, we can see roughly how much overhead you get by using httplb.

Locally, I get:

$ go test -bench .                      
goos: darwin
goarch: arm64
pkg: github.com/bufbuild/httplb
BenchmarkNoOpTransportHTTPLB-10          2712876               419.8 ns/op
BenchmarkNoOpTransportNetHTTP-10         4035433               283.8 ns/op
PASS
ok      github.com/bufbuild/httplb      5.268s

...Which is not too bad, all things considered. This is obviously the minimal overhead you can get, but it seems like a good start nonetheless. More benchmarks would be nice (e.g. benchmarking TLS overhead; may want a sync.Pool for when we have to clone that, as well!) and I assume there's still more we could grind down in terms of CPU overhead if we wanted to. There are some events that would cause additional contention in the hot path, but these should not be happening often enough to impact the overall throughput or latency of the system by a large amount.

It turns out we do not need request.Clone, so just do a shallow copy
instead. We can grind overhead further by pooling allocations to
ammortize the cost.
@jchadwick-buf jchadwick-buf requested a review from jhump July 5, 2023 18:30
@linear
Copy link

linear bot commented Jul 5, 2023

TCN-1894 Benchmarks

We'll want benchmarks, to measure the overhead of this library and be able to compare against baseline "net/http". And we may also want a separate benchmark-like harness, to do high-throughput, high-concurrency testing, to try to tickle concurrency bugs and verify correctness in the face of traffic and many goroutines.

Forgot about linting completely. Tunnel vision.
@jchadwick-buf jchadwick-buf changed the title Add basic overhead benchmarks. Add basic overhead benchmarks Jul 5, 2023
overhead_test.go Outdated Show resolved Hide resolved
overhead_test.go Outdated
Comment on lines 57 to 58
req, _ := http.NewRequestWithContext(context.TODO(), http.MethodGet, "http://localhost:0/", nil)
resp, _ := client.Do(req)
Copy link
Member

Choose a reason for hiding this comment

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

Here and also below, since we don't expect any errors, would be nice to assert that with require.NoError(b, err) instead of just ignoring. (Maybe that would have also caught the issue you had before, where the request was never even making it to the underlying transport?)

Copy link
Member Author

Choose a reason for hiding this comment

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

The problem with doing that is that require.NoError inadvertently takes up most of the CPU time in the test (figures shoot up to 1700-1800ns/op from around 300-400ns/op.) I can make a manual assertion, which I think is the best we can do.

Copy link
Member Author

Choose a reason for hiding this comment

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

Did that. The manual assertion adds basically noise per op, so I think that's the best we can really do.

transport.go Show resolved Hide resolved
overhead_test.go Outdated Show resolved Hide resolved
@jchadwick-buf jchadwick-buf requested a review from jhump July 5, 2023 20:00
Copy link
Member

@jhump jhump left a comment

Choose a reason for hiding this comment

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

LGTM!

@jchadwick-buf jchadwick-buf merged commit 4c32075 into main Jul 5, 2023
3 checks passed
@jchadwick-buf jchadwick-buf deleted the jchadwick/benchmark branch July 5, 2023 22:46
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.

2 participants