Add benchmarking for the http tracing handler#2080
Conversation
Codecov Report
@@ Coverage Diff @@
## main #2080 +/- ##
==========================================
- Coverage 67.36% 67.29% -0.08%
==========================================
Files 215 215
Lines 9111 9091 -20
==========================================
- Hits 6138 6118 -20
Misses 2698 2698
Partials 275 275
Continue to review full report at Codecov.
|
Both the activator and the queue-proxy already do this, so I'd be curious what we're even getting from this handler. |
markusthoemmes
left a comment
There was a problem hiding this comment.
I'd love to understand what this handler even does for us. Even if disabled, it causes quite a bit of overhead, see knative/serving#11016.
We're already manually adding traces in both the activator and the queue-proxy so... does this even add any value?
|
|
||
| fw := &fakeWriter{} | ||
|
|
||
| req, err := http.NewRequest("GET", "http://test.example.com", nil) |
There was a problem hiding this comment.
nit
| req, err := http.NewRequest("GET", "http://test.example.com", nil) | |
| req, err := http.NewRequest(http.MethodGet, "http://test.example.com", nil) |
| next := testHandler{} | ||
| middleware := HTTPSpanMiddleware(&next) | ||
|
|
||
| fw := &fakeWriter{} |
There was a problem hiding this comment.
Is anything ever calling Write on this? That function would cause additional allocations I believe if called.
There was a problem hiding this comment.
I can create a dummy doing nothing.
There was a problem hiding this comment.
Yeah if the tracing handler doesn't call Write (which I guess it shouldn't anyway), we should be fine.
There was a problem hiding this comment.
Actually its one allocation less (pretty predictible):
$ go test -benchmem -memprofile memprofile.out -cpuprofile profile.out -test.v -test.bench BenchmarkSpanMiddleware -test.run ^$ ./tracing/
goos: linux
goarch: amd64
pkg: knative.dev/pkg/tracing
BenchmarkSpanMiddleware
BenchmarkSpanMiddleware/sequential
BenchmarkSpanMiddleware/sequential-12 141504 10679 ns/op 6911 B/op 97 allocs/op
BenchmarkSpanMiddleware/parallel
BenchmarkSpanMiddleware/parallel-12 661308 4737 ns/op 6742 B/op 97 allocs/op
PASS
ok knative.dev/pkg/tracing 5.204s
There was a problem hiding this comment.
Okay, no biggy then. Fine to keep as-is.
There was a problem hiding this comment.
It calls the handler here, verified it also locally.
|
/retest |
|
It is irrelevant. |
|
|
|
/retest |
1 similar comment
|
/retest |
|
@markusthoemmes I see that the broker ingress handler and other handlers do not mix with the special opencensus http handler. This means that they cannot extract the request headers and add them to the local context (In Serving it is the opposite, for activator and queue-proxy). |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: markusthoemmes The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |

trace.StartSpan()in its event handlers and sets span attributes explicitly in several occasions (this is lighter compared to the handler we benchmark here). I am wondering if we can do the same for Serving as trace.StartSpan() is run anyway as part of the HTTPSpanMiddleware (worth investigating next and use this benchmark to compare changes). Maybe create an optimized handler to be used with activator, queue-proxy?Allocations btw seem to be pretty high check bellow. /cc @evankanderson
From sequential execution:
It means that for the most part there is gc work going on here. Let's check gc allocation:
By digging into startStats I see that similar to the findings in metrics benchmarking, mutators and other tag/attributes manipulation cause significant overhead.