-
Notifications
You must be signed in to change notification settings - Fork 712
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
Improve codec performance #916
Conversation
acc8383
to
b46d5d1
Compare
As mentioned in #854 (comment), using ffjson without code generation helps a bit but doesn't cut it. I've tried the ffjson code generator. However, the encoder generated from https://github.com/weaveworks/scope/blob/master/report/node.go breaks the UI, that is:
Which results in: I really don't want to debug the generated code, so I am going to try https://github.com/ugorji/go/ next |
c9f1a2b
to
f40cc7c
Compare
Using compile-time generated JSON encoders/decoders with github.com/ugorji/go/codec doesn't seem to solve the problem either. Here are the profiles from the scenario described in #854 (comment) #812 I run scope in the service to test (5 probes 1 app). Here's the app's profile: pprof.localhost:4040.samples.cpu.009.pb.gz And here's the probe's profile: pprof.localhost:4041.samples.cpu.003.pb.gz As much as we would like to use json, I think it's time to move on to a faster codec. We can use part of this work for the communication with the UI (which the profile above is not taking into account). |
I think I am going to try gob+websockets next. |
The websocket+gob approach didn't help either (see #957 (comment) ) I replaced all the App: pprof.localhost:4040.samples.cpu.010.pb.gz Probe: pprof.localhost:4041.samples.cpu.004.pb.gz The Selfers now allow to move to faster codecs like msgpack very easily. I am going to try that next. |
After moving to msgpack and updating the App: Probe: Although the profile looks the same for the app, note how the duration has gone down considerably. The probe doesn't seem to improve much (it doesn't degrade either) so let's treat that separately. Note that this is still measured without connecting the UI (i.e. browser), but it brings down CPU usage of the app in the service (5 probes) to <10% compared to ~70% in master . The next steps would be:
@paulbellamy @peterbourgon Can you please take a look at this and give some feedback? If you are OK with the results/approach, I will go ahead and clean it up for code review. |
decoder = json.NewDecoder(reader).Decode | ||
decoder = func(i interface{}) error { | ||
return codec.NewDecoder(reader, &codec.JsonHandle{}).Decode(i) | ||
} |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This seems to have trouble with children's metrics. |
Thanks, I will look into it but I will fix the tests first to see if that catches it. Here's a final %CPU comparison against 26ccb49 running Scope in the service (5 probes -> 1 app)
(I cannot simply compare against master because it's broken on the service due to #955). For reference, here's the profile of the App with the UI attached: The codec is not the culprit (i.e. unrelated to this PR). |
I suspect it is with json encoding of metrics, so it won't... |
84bf578
to
9b781a7
Compare
This caused a dependency chain reaction (sigh): * All the k8s packages had to be fetched again. This in turn required: * Pining github.com/docker/docker/pkg/parsers to 0f5c9d301b9b1cca66b3ea0f9dec3b5317d3686d to cirvumvent kubernetes/kubernetes#18774 * Update github.com/juju/ratelimit * Make probe/kubernetes/client.go comply with API changes.
9b781a7
to
9f02e20
Compare
@paulbellamy What problems were you seeing with the metrics? I have noticed that the new codec outputs floats instead of ints. e.g:
instead of:
|
I was just never seeing any values rendered for them on children. Didn't look further into it than that. |
Sorry i clicked on the checkboxes on the first comment, not really paying attention to what I was doing! Hope they're in the right state. |
OK, so this is why controls are not working: ugorji/go#141 . The new codec library misbehaves when embedding types, which is exactly how our control details are defined, sigh. This may also be what's causing problems with the metrics. I think I may have a workaround though: generate selfers for all the types we serialize. @foot No worries |
@2opremio yep. |
OK, I found yet another bug, ugorji/go#142 which I worked around too. The controls are working and I think the metrics are alright. @paulbellamy PTAL, I think I will open a bottle of champaign when this gets merged. |
7c3c2f6
to
0ff1d16
Compare
0ff1d16
to
bdc97d6
Compare
Why are we using your own fork of the codec, vs. the upstream? |
let's ditch |
The fork is only used to build codecgen. It's a temporary solution, see the commit comment:
In fact we will be able to use upstream one once this is fixed: ugorji/go#140 (comment) , which I guess will be pretty soon judging by the maintainer's responsiveness. EDIT: I added #973 |
Agreed |
the secondary expansion thing is terribly complex and obtuse. |
@paulbellamy please take another look |
Much simpler, thanks. :) LGTM |
Improves #854