-
Notifications
You must be signed in to change notification settings - Fork 295
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
Binc and MsgPack RPC Benchmark #9
Comments
The reason for the discrepancy is that gob and json (and probably bson) decoders internally do read buffering. The concern with that is that it can read beyond the actual gob and json data in the input stream. Both gob and json point this out explicitly in their docs. See For my codec library, I wanted to support the ability to have multiple data in an inputstream. E.g. use binc decoder to decode a struct, then read a boundary, then read a gif image right after that. Folks can pass a buffered reader directly to the NewDecoder call, and get the same benefits of buffering. At this point, they are managing the buffering themselves, and all is well. Binc/Msgpack will not internally read past its data. For RPC, since the assumption is that the RPC owns the connection, then RPC can create a buffered reader/writer around the connection and pass that to the codec. I've implemented that now, and the numbers are now as you would expect. BenchmarkEndToEndGob 50000 32450 ns/op It took me a while to figure out because I had to hunt down why gob/json was faster, which is unexpected because the encoding of binc/msgpack is consistently faster. I will push the change out within the next few hours and close this issue when I am done. Please let me know if this makes sense. |
Thanks for the detailed response! Yes, the added buffer speeds up MsgPack-RPC and Binc-RPC a lot. Thx! Here are my results: |
….ByteReader, and other misc optimizations. Also include other misc optimizations and clean up of comments. Improves RPC performance as seen in #9 .
Thanks. Added one last optimization in the latest update that should narrow the difference further. Since io.Reader may now be a buffered reader, it is also most likely a ByteReader with a specialized ReadByte() method. I now call ReadByte if available, instead of calling Read([]byte) when needing to read just one byte. In my testing, it brought the times vs gob to be about the same. BenchmarkEndToEndGob 50000 32226 ns/op Please test again on your end and let me know if you are seeing the same results. |
Can't go get, getting errors. pcdummy@ThinkPad-T410 ~/Projekte/golang/src $ go get -u github.com/ugorji/go/codec github.com/ugorji/go/codecgithub.com/ugorji/go/codec/binc.go:28: undefined: encdecHandle |
That is probably a problem with your environment. You will have to do some more digging there. The problem is not in the commit. Look at the commit description: It's all removal of comments, and a few short edits to use ReadByte and io.ReadAtLeast. |
Yes it was a problem at my side. New Results: Thanks a lot, will use MsgPack at my project! |
I did some benchmarks of RPC encoding speeds.
https://gist.github.com/pcdummy/6168792
Do you know why Binc and MsgPack perform that bad?
The text was updated successfully, but these errors were encountered: