Skip to content

Accept protobuf encoded messages in the statserver.#8626

Merged
knative-prow-robot merged 4 commits intoknative:masterfrom
markusthoemmes:protobuf-websocket
Jul 15, 2020
Merged

Accept protobuf encoded messages in the statserver.#8626
knative-prow-robot merged 4 commits intoknative:masterfrom
markusthoemmes:protobuf-websocket

Conversation

@markusthoemmes
Copy link
Contributor

Proposed Changes

This further improves the efficiency of the statserver by allowing it to receive a slice of StatMessages, binary-encoded via protobufs. The protobufs are already quite an improvement over using JSON, both in terms of density and serdes performance. Collapsing all stats into a single message further reduces the overhead of the surrounding protocols, making for a much more efficient protocol overall.

Benchmark results

goos: linux
goarch: amd64
pkg: knative.dev/serving/pkg/autoscaler/statserver
BenchmarkStatServer/json-encoding-1-msgs-16         	   37719	     32458 ns/op	    3661 B/op	      23 allocs/op
BenchmarkStatServer/proto-encoding-1-msgs-16        	   53277	     22843 ns/op	    2600 B/op	      15 allocs/op
BenchmarkStatServer/json-encoding-2-msgs-16         	   23275	     50602 ns/op	    7322 B/op	      46 allocs/op
BenchmarkStatServer/proto-encoding-2-msgs-16        	   50244	     24294 ns/op	    3088 B/op	      24 allocs/op
BenchmarkStatServer/json-encoding-5-msgs-16         	   14947	     83316 ns/op	   18308 B/op	     115 allocs/op
BenchmarkStatServer/proto-encoding-5-msgs-16        	   43286	     28117 ns/op	    4624 B/op	      50 allocs/op
BenchmarkStatServer/json-encoding-10-msgs-16        	    9296	    130637 ns/op	   36618 B/op	     230 allocs/op
BenchmarkStatServer/proto-encoding-10-msgs-16       	   42984	     28248 ns/op	    7136 B/op	      91 allocs/op
BenchmarkStatServer/json-encoding-20-msgs-16        	    5286	    228309 ns/op	   73225 B/op	     460 allocs/op
BenchmarkStatServer/proto-encoding-20-msgs-16       	   28622	     41278 ns/op	   16272 B/op	     173 allocs/op
BenchmarkStatServer/json-encoding-50-msgs-16        	    2389	    490206 ns/op	  183048 B/op	    1151 allocs/op
BenchmarkStatServer/proto-encoding-50-msgs-16       	   16401	     72992 ns/op	   39280 B/op	     415 allocs/op
BenchmarkStatServer/json-encoding-100-msgs-16       	    1308	    938296 ns/op	  366103 B/op	    2302 allocs/op
BenchmarkStatServer/proto-encoding-100-msgs-16      	   10000	    121983 ns/op	   63856 B/op	     816 allocs/op
PASS
ok  	knative.dev/serving/pkg/autoscaler/statserver	21.040s

Release Note

NONE

/assign @vagababov @julz

This further improves the efficiency of the statserver by allowing it to receive a slice of StatMessages, binary-encoded via protobufs. The protobufs are already quite an improvement over using JSON, both in terms of density and serdes performance. Collapsing all stats into a single message further reduces the overhead of the surrounding protocols, making for a much more efficient protocol overall.
@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Jul 14, 2020
@knative-prow-robot knative-prow-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 14, 2020
@knative-prow-robot
Copy link
Contributor

[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

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow-robot knative-prow-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. area/autoscale labels Jul 14, 2020
Copy link
Contributor

@knative-prow-robot knative-prow-robot left a comment

Choose a reason for hiding this comment

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

@markusthoemmes: 0 warnings.

Details

In response to this:

Proposed Changes

This further improves the efficiency of the statserver by allowing it to receive a slice of StatMessages, binary-encoded via protobufs. The protobufs are already quite an improvement over using JSON, both in terms of density and serdes performance. Collapsing all stats into a single message further reduces the overhead of the surrounding protocols, making for a much more efficient protocol overall.

Benchmark results

goos: linux
goarch: amd64
pkg: knative.dev/serving/pkg/autoscaler/statserver
BenchmarkStatServer/json-encoding-1-msgs-16         	   37719	     32458 ns/op	    3661 B/op	      23 allocs/op
BenchmarkStatServer/proto-encoding-1-msgs-16        	   53277	     22843 ns/op	    2600 B/op	      15 allocs/op
BenchmarkStatServer/json-encoding-2-msgs-16         	   23275	     50602 ns/op	    7322 B/op	      46 allocs/op
BenchmarkStatServer/proto-encoding-2-msgs-16        	   50244	     24294 ns/op	    3088 B/op	      24 allocs/op
BenchmarkStatServer/json-encoding-5-msgs-16         	   14947	     83316 ns/op	   18308 B/op	     115 allocs/op
BenchmarkStatServer/proto-encoding-5-msgs-16        	   43286	     28117 ns/op	    4624 B/op	      50 allocs/op
BenchmarkStatServer/json-encoding-10-msgs-16        	    9296	    130637 ns/op	   36618 B/op	     230 allocs/op
BenchmarkStatServer/proto-encoding-10-msgs-16       	   42984	     28248 ns/op	    7136 B/op	      91 allocs/op
BenchmarkStatServer/json-encoding-20-msgs-16        	    5286	    228309 ns/op	   73225 B/op	     460 allocs/op
BenchmarkStatServer/proto-encoding-20-msgs-16       	   28622	     41278 ns/op	   16272 B/op	     173 allocs/op
BenchmarkStatServer/json-encoding-50-msgs-16        	    2389	    490206 ns/op	  183048 B/op	    1151 allocs/op
BenchmarkStatServer/proto-encoding-50-msgs-16       	   16401	     72992 ns/op	   39280 B/op	     415 allocs/op
BenchmarkStatServer/json-encoding-100-msgs-16       	    1308	    938296 ns/op	  366103 B/op	    2302 allocs/op
BenchmarkStatServer/proto-encoding-100-msgs-16      	   10000	    121983 ns/op	   63856 B/op	     816 allocs/op
PASS
ok  	knative.dev/serving/pkg/autoscaler/statserver	21.040s

Release Note

NONE

/assign @vagababov @julz

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Copy link
Contributor

@julz julz left a comment

Choose a reason for hiding this comment

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

couple of questions but only really holding off lgtm for the tiny tiny nit and to let @vagababov look

switch messageType {
case websocket.BinaryMessage:
dec = gob.NewDecoder(bytes.NewBuffer(msg))
var wsms metrics.WireStatMessages
Copy link
Contributor

Choose a reason for hiding this comment

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

kind of a shame we can't reuse this variable between iterations, but I don't know if it even matters since it's on the stack anyway. probably not 🤷.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think unmarshal call escapes it anyway. But there is Reset standard proto method, so it can be reused, but I am not sure if is helpful from performance standpoint.

Copy link
Contributor

@vagababov vagababov left a comment

Choose a reason for hiding this comment

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

/lgtm
/hold
If you want to fix the nits

switch messageType {
case websocket.BinaryMessage:
dec = gob.NewDecoder(bytes.NewBuffer(msg))
var wsms metrics.WireStatMessages
Copy link
Contributor

Choose a reason for hiding this comment

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

I think unmarshal call escapes it anyway. But there is Reset standard proto method, so it can be reused, but I am not sure if is helpful from performance standpoint.

@knative-prow-robot knative-prow-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm Indicates that a PR is ready to be merged. labels Jul 14, 2020
@knative-prow-robot knative-prow-robot removed the lgtm Indicates that a PR is ready to be merged. label Jul 15, 2020
@knative-metrics-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-knative-serving-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/autoscaler/statserver/server.go 81.2% 79.5% -1.7

@knative-prow-robot
Copy link
Contributor

@markusthoemmes: The following test failed, say /retest to rerun all failed tests:

Test name Commit Details Rerun command
pull-knative-serving-go-coverage c9f0388 link /test pull-knative-serving-go-coverage

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

Copy link
Contributor

@vagababov vagababov left a comment

Choose a reason for hiding this comment

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

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 15, 2020
Copy link
Contributor

@julz julz left a comment

Choose a reason for hiding this comment

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

/lgtm

@markusthoemmes
Copy link
Contributor Author

/unhold

@knative-prow-robot knative-prow-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 15, 2020
@knative-prow-robot knative-prow-robot merged commit 81d40bf into knative:master Jul 15, 2020
@julz julz mentioned this pull request Jul 23, 2020
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. area/autoscale cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants