czah opened a new issue #635:
URL: https://github.com/apache/rocketmq-client-go/issues/635


   The issue tracker is **ONLY** used for the go client (feature request of 
RocketMQ need to follow [RIP 
process](https://github.com/apache/rocketmq/wiki/RocketMQ-Improvement-Proposal)).
 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](http://rocketmq.apache.org/about/contact/). 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**  
   **Please add the branch name [Native]/[Master] at the header of the Isssue 
title.**
   
   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](https://user-images.githubusercontent.com/81543537/112792798-b3256a80-9096-11eb-95bb-dc353485ae51.png)
   
   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 time.
   
   
https://github.com/apache/rocketmq-client-go/blob/d6e66a2d648d6529eca833f9bf912915d1749a5c/internal/remote/codec.go#L227-L231
   
   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
   ```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to