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

[Master] Improve decoding performance for remoting commands #635

Closed
czah opened this issue Mar 29, 2021 · 0 comments
Closed

[Master] Improve decoding performance for remoting commands #635

czah opened this issue Mar 29, 2021 · 0 comments

Comments

@czah
Copy link
Contributor

czah commented Mar 29, 2021

The issue tracker is ONLY used for the go client (feature request of RocketMQ need to follow RIP process). Keep in mind, please check whether there is an existing same report before your raise a new one.

Alternately (especially if your communication is not a bug report), you can send mail to our mailing lists. We welcome any friendly suggestions, bug fixes, collaboration, and other improvements.

Please ensure that your bug report is clear and that it is complete. Otherwise, we may be unable to understand it or to reproduce it, either of which would prevent us from fixing the bug. We strongly recommend the report(bug report or feature request) could include some hints as to the following:

BUG REPORT

  1. Please describe the issue you observed:

Recently we've benchmarked our service which act as a RocketMQ consumer and I noticed that it spends much time on reflection while decoding remoting commands (as shown below):

image

After some investigations, I found it was caused by passing a byte slice pointer to binary.Read(). It makes binary.Read() to fallback to reflect-based decoding, consuming more CPU cycles.

headerData := make([]byte, headerLength)
err = binary.Read(buf, binary.BigEndian, &headerData)
if err != nil {
return nil, err
}

There're two ways to solve this issue.

  • pass an initialized byte slice instead of a slice pointer to binary.Read()
  • just use io.ReadFull() instead

I've tried the second way and got a ~1.9x performance boost on remoting command decoding:

before:

goos: linux
goarch: amd64
pkg: github.com/apache/rocketmq-client-go/v2/internal/remote
Benchmark_decode-8   	  141375	      7141 ns/op	    2334 B/op	      60 allocs/op
PASS
ok  	github.com/apache/rocketmq-client-go/v2/internal/remote	1.102s

after:

goos: linux
goarch: amd64
pkg: github.com/apache/rocketmq-client-go/v2/internal/remote
Benchmark_decode-8   	  286480	      3724 ns/op	    1950 B/op	      56 allocs/op
PASS
ok  	github.com/apache/rocketmq-client-go/v2/internal/remote	1.116s
@czah czah changed the title Improve decoding performance for remoting commands [Master] Improve decoding performance for remoting commands Mar 29, 2021
maixiaohai added a commit that referenced this issue Apr 22, 2021
[ISSUE #635] Improving decoding performance for remoting commands
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

No branches or pull requests

2 participants