免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 8198 | 回复: 11
打印 上一主题 下一主题

网络编程碰到一个问题,send成功但是数据还在Send-Q中 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-01-23 17:26 |只看该作者 |倒序浏览
环境描述:
    创建4个线程分别读写网卡,4个循环几乎是一样的,使用select函数发送或者接收数据.
每次循环使用sched_yield释放CPU资源.
    使用top查看,整个进程占用CPU资源1-2%

问题描述:

    send函数发送正常,但是使用netstat查看,发现数据阻塞在Send-Q里,如下:
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0    264 192.168.250.1:9200      192.168.250.2:2734      ESTABLISHED

需要经过随机的时间,大约5-50秒不等,才发送出去.

问题总结:
    send函数立刻成功,但是为什么网卡需要花费太多的时间发送缓存中的数据?


是不是内核调度网卡不及时?

当时其他的网络是正常的.使用ssh登陆,smb等都没有任何停顿.

论坛徽章:
0
2 [报告]
发表于 2006-01-24 00:22 |只看该作者
It was caused by Nagle algorithm.
man 7 tcp
see TCP_NODELAY
       TCP_NODELAY
              If  set,  disable  the Nagle algorithm.  This means
              that segments are always sent as soon as  possible,
              even if there is only a small amount of data.  When
              not set, data is buffered until there is  a  suffi-
              cient amount to send out, thereby avoiding the fre-
              quent sending of small packets,  which  results  in
              poor  utilization of the network.  This option can-
              not  be  used  at  the  same  time  as  the  option
              TCP_CORK.

论坛徽章:
0
3 [报告]
发表于 2006-01-24 03:50 |只看该作者
1.send只是表示写入send buffer成功(default方式),印象中可以通过修改setsockopt改变成真正发送出去send才返回.
2.nagle算法最大是2S延迟.

论坛徽章:
0
4 [报告]
发表于 2006-01-24 11:51 |只看该作者
原帖由 柳五随风 于 2006-1-24 03:50 发表
2.nagle算法最大是2S延迟.


Really?? Where did you get this constant?

I didn't find any timeout hard limitations on nagle algorithm in linux-2.6.15 kernel source tree, and RFCs either.

Tell me the truth, so I can submit a kernel patch for linux.

论坛徽章:
0
5 [报告]
发表于 2006-01-24 14:23 |只看该作者
建议楼上能打中文的时候还是打中文
我想不到有什么理由你非要用英文。
毕竟不是所有人英文都像你这么。。。厉害。。。
作为版主,还是让更多人能看懂你的贴好。

论坛徽章:
0
6 [报告]
发表于 2006-01-24 14:44 |只看该作者
to JohnBull;
talk to this guy:cec@gryphon.gsfc.nasa.gov

he knows exactly what the 2 seconds delay means.

I think the Nagle algorithm affects only the data in the TCP sliding woindow between time of last  two ack's, that is definitely defined in any *nix kernel.

论坛徽章:
0
7 [报告]
发表于 2006-01-24 14:45 |只看该作者
原帖由 xujg 于 2006-1-24 14:23 发表
建议楼上能打中文的时候还是打中文
我想不到有什么理由你非要用英文。
毕竟不是所有人英文都像你这么。。。厉害。。。
作为版主,还是让更多人能看懂你的贴好。


Sorry!
I am upgrading my X11 system (Don't you know? X11R7.0 was officially released!! ),
I can NOT type Chinese for now (But I can read).

[ 本帖最后由 JohnBull 于 2006-1-24 14:47 编辑 ]

论坛徽章:
0
8 [报告]
发表于 2006-01-24 20:47 |只看该作者
问题没有解决,
   通过TCP_NODELAY

问题解决途径:
    把10M/100M的Dlink交换机改为一个10M的Hub后,问题解决.
    非常偶然.
    是P-IV与ixp425之间创建socket的编程,不知道是不是ixp425的板子有问题.

论坛徽章:
0
9 [报告]
发表于 2006-01-24 22:29 |只看该作者
估计板子的网口驱动有问题!

再写个UDP的发包来测试一下呢?

或者ping小包和大包分别测试一下?

TCP发大包测试一下?

论坛徽章:
0
10 [报告]
发表于 2006-01-25 10:03 |只看该作者
如果是网卡驱动问题,有如下两种情况,我没有相关知识,请前辈们指点:
1.P-IV板子的网口驱动有问题,
2.P-IV与IXP425通讯,数据阻塞在P-IV这边的SEND-Q,
   但仍然会是IXP425网卡驱动的问题.

我从直观上看觉得都不像.苦于没有相关理论知识.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP