SslStream慢速取决于BufferedStream的包装 [英] SslStream slow depending on wrapping of BufferedStream

查看:74
本文介绍了SslStream慢速取决于BufferedStream的包装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近调试了我使用SslStream的性能问题。

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

客户端是C#/。NET,并且具有以下Stream配置

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


  • 原始套接字/ NetStream

  • 由BufferedStream包装

  • 由SslStream包装

  • 被协议流包装(发送字节/整数/字符串等)

  • 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.

删除SSL流并加速连接到预期的水平。

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

然后,我将上述流配置更改为

Then I changed the above stream configuration to be..


  • 原始套接字/ NetStream

  • 由SslStream包装的

  • 由BufferedStream包裹<-移动了

  • 由协议流包裹(发送字节/整数/字符串等)

  • 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?

推荐答案

原因很简单。您保存一个int(仅4个字节),它将被包装到SSL数据包中,然后进行缓冲。更改顺序后,您开始在缓冲区中收集大量数据,然后将缓冲区包装为一个大块。更少的SSL包装器,更高的速度。

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.

这篇关于SslStream慢速取决于BufferedStream的包装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆