是否有通过网络发送数据的最佳字节大小? [英] Is there an optimal byte size for sending data over a network?

查看:76
本文介绍了是否有通过网络发送数据的最佳字节大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为100字节太小,在所有写入操作中都可能减慢较大文件的传输速度,但类似1MB的内容似乎太多了.有没有人建议通过网络发送数据来获得每次写入的最佳字节块?

I assume 100 bytes is too small and can slow down larger file transfers with all of the writes, but something like 1MB seems like it may be too much. Does anyone have any suggestions for an optimal chunk of bytes per write for sending data over a network?

为了进一步说明,我正在实现一些通过网络连接发送数据并显示发送数据进度的方法.我已经注意到,如果我发送每次写大约100字节的大文件,那是非常慢的,但是进度条效果很好.但是,如果我说每次写入发送1M,则速度要快得多,但是由于发送的块更大,进度条不能很好地工作.

To elaborate a bit more, I'm implementing something that sends data over a network connection and show the progress of that data being sent. I've noticed if I send large files at about 100 bytes each write, it is extremely slow but the progress bar works out very nicely. However, if I send at say 1M per write, it is much faster, but the progress bar doesn't work as nicely due to the larger chunks being sent.

推荐答案

不,没有通用的最佳字节大小.

No, there is no universal optimal byte size.

TCP数据包容易碎片化,虽然可以很好地假设从这里到您的目的地的一切都是具有巨大数据包大小的真实以太网,但实际上即使您可以获得所有单个网络的数据包大小,也是如此您的数据包所占用的空间,您发送的每个数据包都可能通过互联网使用不同的路径.

TCP packets are subject to fragmentation, and while it would be nice to assume that everything from here to your destination is true ethernet with huge packet sizes, the reality is even if you can get the packet sizes of all the individual networks one of your packets takes, each packet you send out may take a different path through the internet.

您可以解决"这不是问题,并且没有通用的理想尺寸.

It's not a problem you can "solve" and there's no universal ideal size.

将数据尽快送入OS和TCP/IP堆栈,它会根据网络连接动态调整数据包大小(您应该看到它们用于此优化的代码-确实非常有趣.至少在更好的堆栈上.)

Feed the data to the OS and TCP/IP stack as quickly as you can, and it'll dynamically adapt the packet size to the network connections (you should see the code they use for this optimization - it's really, really interesting. At least on the better stacks.)

但是,如果您控制客户端/服务器之间以及所有正在使用的网络和堆栈,则可以进行一些手动调整.但是通常,即使那样,在我建议您使用它之前,您也必须非常了解网络和发送的数据.

If you control all the networks and stacks being used and inbetween your clients/servers, though, then you can do some hand tuning. But generally even then you'd have to have a really good grasp of the network and the data your sending before I'd suggest you approach it.

-亚当

这篇关于是否有通过网络发送数据的最佳字节大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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