What is a good buffer size for socket programming?
http://stackoverflow.com/questions/2811006/what-is-a-good-buffer-size-for-socket-programming
问题:
We are using .Net and sockets.
The server is using the Socket.Sender(bytes[]) method so it just sends the entire payload.
On the other side we are clients consuming the data.
Socket.Receive(buffer[]).
In all the examples from Microsoft (and others) they seem to stick with a buffer size of 8192.
We have used this size but 【every now and then不时地,常常】 we are sending data down to the clients that exceeds this buffer size.
Is there a way of determining how much data the server's sent method sent us? What is the best buffer size?
回答:
Even if you're sending more data than that, it may well not be available in one call to Receive.
You can't determine how much data the server has sent - it's a stream of data, and you're just reading chunks at a time.
You may read part of what the server sent in one Send call, or you may read the data from two Send calls in one Receive call.
8K is a reasonable buffer size - not so big that you'll waste a lot of memory, and not so small that you'll have to use loads of wasted Receive calls.
4K or 16K would quite possibly be fine too... I personally wouldn't start going above 16K for network buffers - I suspect you'd rarely fill them.
You could experiment by trying to use a very large buffer and log how many bytes were received in each call - that would give you some idea of how much is generally available -
but it wouldn't really show the effect of using a smaller buffer.
What concerns do you have over using an 8K buffer?
If it's performance, do you have any evidence that this aspect of your code is a performance bottleneck?
What is a good buffer size for socket programming?的更多相关文章
- socket programming Max size of tcp/ip socket Buffer?
TCP data is buffered at both sender and receiver. The size of the receiver's socket receive buffer d ...
- 关于socket buffer size的调优
为了达到最大网络吞吐,socket send buffer size(SO_SNDBUF)不应该小于带宽和延迟的乘积.之前我遇到2个性能问题,都和SO_SNDBUF设置得太小有关.但是,写程序的时候可 ...
- bulkTransfer通讯必须注意的问题:bulk buffer size(16K)
Android USB host与HID使用bulkTransfer通讯接收和发送的数据长度不会超过16384,这个问题困扰了我很长一段时间,终于发现问题所在,不是出在我的程序设计,也不是硬件的发送/ ...
- 如何修改dmesg log buffer size
CONFIG_LOG_BUF_SHIFT: Kernel log buffer size (16 => 64KB, 17 => 128KB) General informations Th ...
- Spring整合JUnit4进行AOP单元测试的时候,报:"C:\Program Files\Java\jdk1.8.0_191\bin\java.exe" -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2018.3\lib\idea_rt.jar=64
错误代码 "C:\Program Files\Java\jdk1.8.0_191\bin\java.exe" -ea -Didea.test.cyclic.buffer.size= ...
- Flume启动运行时报错org.apache.flume.ChannelFullException: Space for commit to queue couldn't be acquired. Sinks are likely not keeping up with sources, or the buffer size is too tight解决办法(图文详解)
前期博客 Flume自定义拦截器(Interceptors)或自带拦截器时的一些经验技巧总结(图文详解) 问题详情 启动agent服务 [hadoop@master flume-1.7.0]$ ...
- the attribute buffer size is too small 解决方法
在进行查询的时候引发The attribute buffer size is too small错误解决 http://bbs.esrichina-bj.cn/esri/viewthread.php? ...
- Socket Programming in C#--Multiple Sockets
Now lets say you have two sockets connecting to either two different servers or same server (which i ...
- Socket Programming in C#--Getting Started
Getting Started You can argue that one can overcome these shortcomings by multithreading meaning tha ...
随机推荐
- DWARF调试格式的简介
DWARF调试格式的简介 Michael J. Eager, Eager Consulting Feb, 2007 翻译:吴晖 2012年2月 如果我们可以编写确保能正确工作且永远不需要调试的程序,这 ...
- Discuz!伪静态原理分析
伪静态在seo火热的时代,是每个站长都比较关注的问题,discuz!论坛如何伪静态,为什么伪静态失效了,为什么列表页无法实现伪静态,为什么有些页面不是伪静态呢?下面dz官方nxy105从两个角度入手为 ...
- win10系统杀毒功能
最近很多客户的电脑都是win10的,部署web服务时用到的破解软件(exe文件),经常被当成病毒杀死,今天发现可以在杀毒记录里找到刚刚被杀掉的文件,然后点击操作,点击允许,再运行时就可以畅通无阻了
- Executors工厂类
newCachedThreadPool 重用之前的线程 适合执行许多短期异步任务的程序. 调用 execute() 将重用以前构造的线程 如果没有可用的线程,则创建一个新线程并添加到池中 默认为60s ...
- 个人Linux(ubuntu)使用记录——远程访问linux
说明:记录自己的linux使用过程,并不打算把它当作一个教程,仅仅只是记录下自己使用过程中的一些命令,配置等东西,这样方便自己查阅,也就不用到处去网上搜索了,所以文章毫无章法可言,甚至会记录得很乱. ...
- TFRecordReader "OutOfRangeError (see above for traceback): RandomShuffleQueue '_1_shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 1, current size 0)" 问题原因总结;
1. tf.decode_raw(features['image_raw'],tf.uint8) 解码时,数据类型有没有错?tf.float32 和tf.uint8有没有弄混??? 2. tf.tra ...
- Java垃圾回收简介
Java关键术语 JavaAPI:一系列帮助开发者创建Java应用程序的封装好的库. Java 开发工具包 (JDK):一系列工具帮助开发者创建Java应用程序.JDK包含工具编译.运行.打包.分发和 ...
- HP下kafka的实践
kafka 简介 Kafka 是一种高吞吐量的分布式发布订阅消息系统 kafka角色必知 producer:生产者. consumer:消费者. topic: 消息以topic为类别记录,Kafka将 ...
- Python3.0科学计算学习之类
类: Python中的类是一个抽象的概念,甚至比函数还要抽象.可以把它简单的看作是数据以及由存取.操作这些数据的方法所组成的一个集合.类是Python的核心概念,是面向对象编程的基础. 类有如下的优点 ...
- 网络基础——UDP
UDP 1.UDP首部格式 源端口号(16) 目标端口号(16) UDP长度(16) UDP校验和(16) UDP长度:用来指出UDP的总长度 校验和:用来完成对UDP数据的差错检验,它是UDP协议提 ...