SslStream slow depending on wrapping of BufferedStream

北慕城南 提交于 2019-12-13 00:27:50

问题


I recently debugged a performance issue with how I was using SslStream.

The client is C#/.NET and had the following Stream configuration

  • Raw Socket/NetStream
  • Wrapped by BufferedStream
  • Wrapped by SslStream
  • Wrapped by "protocol" stream (which sends bytes/ints/strings etc)

I was seeing extremely slow performance when sending data from a client to a server, across the internet where it was taking a long time to serialise information on the client side.

Removing SSL stream and the connection sped up to expected levels.

Then I changed the above stream configuration to be..

  • Raw Socket/NetStream
  • Wrapped by SslStream
  • Wrapped by BufferedStream <-- moved this
  • Wrapped by "protocol" stream (which sends bytes/ints/strings etc)

And the connection sped up to expected levels.

Can someone explain why changing the stream configuration helps the performance so much?Particularly as I tested the original configuration with the client on the same machine as the server at it ran very quickly?


回答1:


The reason is simple. You save an int (just 4 bytes), it gets wrapped into SSL packet and then buffered. After you changed the order, you started to collect lots of data in the buffer, which was then wrapped with SSL as one large block. Less SSL wrappers, higher speed.



来源:https://stackoverflow.com/questions/14965073/sslstream-slow-depending-on-wrapping-of-bufferedstream

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!