我需要在两台机器之间以尽可能低的延迟定期发送(交换)大量数据。网络相当快(例如 1Gbit 甚至 2G+)。操作系统是linux。使用 1 个 tcp 套接字(用于发送和接收)还是使用 2 个单向 tcp 套接字会更快吗?
此任务的测试非常类似于 NetPIPE 网络基准测试 - 测量从 2^1 到 2^13 字节大小的延迟和带宽,每个大小发送和接收至少 3 次(在青色任务中,发送次数更多。两者进程将发送和接收,就像乒乓球一样)。
2个单向连接的好处来自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.
禁用快速路径的所有其他条件都是错误的。并且只有非单向套接字会阻止内核从快速路径接收