一个双向的TCP套接字或两个双向的? (Linux,高容量,低延迟) [英] one two-directed tcp socket OR two one-directed? (linux, high volume, low latency)

查看:150
本文介绍了一个双向的TCP套接字或两个双向的? (Linux,高容量,低延迟)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要定期发送(交换)大量数据,并使两台计算机之间的等待时间尽可能短.网络速度相当快(例如1Gbit甚至2G +).操作系统是linux.使用1个tcp套接字(用于send和recv)或使用2个单向tcp套接字会更快吗?

I need to send (interchange) a high volume of data periodically with the lowest possible latency between 2 machines. The network is rather fast (e.g. 1Gbit or even 2G+). Os is linux. Is it be faster with using 1 tcp socket (for send and recv) or with using 2 uni-directed tcp sockets?

此任务的测试非常类似于NetPIPE网络基准测试-测量2 ^ 1到2 ^ 13字节大小的等待时间和带宽,每种大小至少发送和接收3次(在青色任务中,发送数量为更大.这两个过程都将进行发送和接收,例如乒乓球.)

The test for this task is very like NetPIPE network benchmark - measure latency and bandwidth for sizes from 2^1 up to 2^13 bytes, each size sent and received 3 times at least (in teal task the number of sends is greater. both processes will be sending and receiving, like ping-pong maybe).

2个单向连接的好处来自linux:

The benefit of 2 uni-directed connections come from linux:

http://lxr.linux.no /linux+v2.6.18/net/ipv4/tcp_input.c#L3847

3847/*
3848 *      TCP receive function for the ESTABLISHED state. 
3849 *
3850 *      It is split into a fast path and a slow path. The fast path is 
3851 *      disabled when:
...
3859 *      - Data is sent in both directions. Fast path only supports pure senders
3860 *        or pure receivers (this means either the sequence number or the ack
3861 *        value must stay constant)
...
3863 *
3864 *      When these conditions are not satisfied it drops into a standard 
3865 *      receive procedure patterned after RFC793 to handle all cases.
3866 *      The first three cases are guaranteed by proper pred_flags setting,
3867 *      the rest is checked inline. Fast processing is turned on in 
3868 *      tcp_data_queue when everything is OK.

所有其他禁用快速路径的条件都是错误的.而且只有非单向套接字才能在接收

All other conditions for disabling fast path is false. And only not-unidirected socket stops kernel from fastpath in receive

推荐答案

单个答案的变量太多,无法始终保存在此处.除非您具有非常非常的快速网络链接-在现代硬件上可能> 1 GBit/sec,否则您链接到的fastpath/slowpath东西可能并不重要.

There are too many variables for a single answer to always hold here. Unless you have a very very fast network link - probably > 1 GBit/sec on modern hardware - the fastpath/slowpath stuff you linked to probably doesn't matter.

以防万一,您可以选择编写程序以两种方式工作.只需存储一个readsocket和一个writesocket,然后在connect()时,可以将它们分配为相同的套接字或两个不同的套接字.然后,您可以同时尝试两种方法,然后看看哪种方法更快.

Just in case, you can choose to write your program to work either way. Just store a readsocket and a writesocket, and at connect() time, you can either assign them to be the same socket, or two different sockets. Then you can just try it both ways and see which is faster.

您很有可能不会注意到两者之间的任何区别.

It's highly likely you won't notice any difference between the two.

这篇关于一个双向的TCP套接字或两个双向的? (Linux,高容量,低延迟)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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