博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
What is a good buffer size for socket programming?
阅读量:4987 次
发布时间:2019-06-12

本文共 1627 字,大约阅读时间需要 5 分钟。

问题:

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?

 

转载于:https://www.cnblogs.com/chucklu/p/5279336.html

你可能感兴趣的文章
327 作业
查看>>
sql 取汉字首字母
查看>>
bzoj4034: [HAOI2015]树上操作(树剖)
查看>>
${sessionScope.user}的使用方法
查看>>
WCF开发框架形成之旅---结合代码生成工具实现快速开发
查看>>
Spring事务管理
查看>>
linux下mysql配置文件my.cnf详解
查看>>
08ssm三大框架整合以前步骤
查看>>
R语言学习笔记之八
查看>>
主动与被动监控 拓扑图组合图 自定义监控
查看>>
SQL总结(一)基本查询
查看>>
PDF分割--可脱离python环境执行,可传参数,可弹窗的PC端小工具
查看>>
layui中的html怎样接收后台的值,layui框架与SSM前后台交互的方法
查看>>
Skulpt在线模拟运行Python工具
查看>>
287.软件测试概述
查看>>
297.白盒测试
查看>>
新闻客户端的突破与创新
查看>>
网络通信引擎ICE的使用
查看>>
js滚动事件实现滚动触底加载
查看>>
javascript事件小结(事件处理程序方式)--javascript高级程序设计笔记
查看>>