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: use setHeader to set trace context header #643
Conversation
Codecov Report
@@ Coverage Diff @@
## master #643 +/- ##
==========================================
+ Coverage 96.03% 96.11% +0.07%
==========================================
Files 31 31
Lines 1615 1621 +6
Branches 290 289 -1
==========================================
+ Hits 1551 1558 +7
+ Misses 64 63 -1
Continue to review full report at Codecov.
|
This change improves the performance only when the client code is not tracing. The performance degradation still happens if the code is traced, right? I'm not sure if #639 is only for the former, not for the latter. Is there a way to improve for both cases? I'd imagine most production services would want to enable tracing all the time (at least for some of its traffic), and they wouldn't want the performance to be impacted severely. |
@jinwoo As long we're claiming a guarantee that the HTTP request options object is not being mutated (this could be up for discussion in the spirit of improving performance), I'm not sure there's a way around cloning the headers object. I'm not sure what the traffic patterns are like in #639 but it might very well be possible that the number of outgoing HTTP requests indeed far exceeds the number of traced requests (we by default limit it to 10 traces/second). |
@kjin would yall actually consider an option for mutating the request object? That seems like it would be the smallest performance hit. #639 is a socket.io server that makes outbound http requests on every socket pong that is received, so yes, the outbound requests greatly exceed the inbound requests for most cases. I also agree with @jinwoo. It would be ideal to tune for the production if we can :] |
@kjin Do you mean that this new code will degrade the performance only for 10 requests/second at maximum, while the old code will degrade for all the requests? If that is the case, I think this is in a much better state, if not ideal. |
Looking through the docs I'm reminded that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CI is failing.
@@ -65,21 +61,27 @@ function makeRequestTrace(request, api) { | |||
return request.apply(this, arguments); | |||
} | |||
|
|||
options = isString(options) ? url.parse(options) : merge({}, options); | |||
options.headers = options.headers || {}; | |||
var uri; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This was a bug. We were cloning the request options for all requests rather than the sampled requests. I expect that this change will fix the performance issue even without the change to avoid mutation. |
c0adcc1
to
5b5d696
Compare
5b5d696
to
b7dbeef
Compare
@GoogleCloudPlatform/node-team @evanlucas PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
src/plugins/plugin-http.ts
Outdated
// The former is already true (at least in supported Node versions up to | ||
// v9), so we simply follow the latter. | ||
// Ref: https://nodejs.org/dist/latest/docs/api/http.html#http_http_get_options_callback | ||
return function makeGetTrace() { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
239e530
to
6f7a591
Compare
CircleCI is backed up... a previous Node 6 build passed (differences are not specific to Node 6) https://circleci.com/gh/GoogleCloudPlatform/cloud-trace-nodejs/1289 Landing. |
Fixes #639
The HTTP tracing plugin should not be trying to clone the HTTP request options object if it's not even clear if the request is being traced. This change
moves the clone to after this check has been maderemoves themerge
call in favor of usingsetHeader
to mutate headers afterhttp.request
has been called.