免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3543 | 回复: 7

[网络子系统] recent improvements in UDP packets processing [复制链接]

论坛徽章:
0
发表于 2018-02-07 14:06 |显示全部楼层
各位大佬,
我刚看到一篇文章,
  1. https://developers.redhat.com/blog/2017/06/09/the-need-for-speed-and-the-kernel-datapath-recent-improvements-in-udp-packets-processing/
复制代码

有个疑惑, 这个性能的提高是需要多个UDP flow 的。UDP flow指的具体是啥, 假如我的进程只监听一个udp端口,并使用这个端口发送数据。这种情况下使用多线程同时发送/接收还有提升吗?

论坛徽章:
20
程序设计版块每日发帖之星
日期:2015-08-17 06:20:00程序设计版块每日发帖之星
日期:2016-07-16 06:20:00程序设计版块每日发帖之星
日期:2016-07-18 06:20:00每日论坛发贴之星
日期:2016-07-18 06:20:00黑曼巴
日期:2016-12-26 16:00:3215-16赛季CBA联赛之江苏
日期:2017-06-26 11:05:5615-16赛季CBA联赛之上海
日期:2017-07-21 18:12:5015-16赛季CBA联赛之青岛
日期:2017-09-04 17:32:0515-16赛季CBA联赛之吉林
日期:2018-03-26 10:02:16程序设计版块每日发帖之星
日期:2016-07-15 06:20:0015-16赛季CBA联赛之江苏
日期:2016-07-07 18:37:512015亚冠之萨济拖拉机
日期:2015-08-17 12:21:08
发表于 2018-02-08 10:03 |显示全部楼层
很好的文章。

论坛徽章:
0
发表于 2018-02-08 20:10 |显示全部楼层
  1. /**
  2. *  reuseport_select_sock - Select a socket from an SO_REUSEPORT group.
  3. *  @sk: First socket in the group.
  4. *  @hash: When no BPF filter is available, use this hash to select.
  5. *  @skb: skb to run through BPF filter.
  6. *  @hdr_len: BPF filter expects skb data pointer at payload data.  If
  7. *    the skb does not yet point at the payload, this parameter represents
  8. *    how far the pointer needs to advance to reach the payload.
  9. *  Returns a socket that should receive the packet (or NULL on error).
  10. */
  11. struct sock *reuseport_select_sock(struct sock *sk,
  12.                                    u32 hash,
  13.                                    struct sk_buff *skb,
  14.                                    int hdr_len)
  15. {
  16.         struct sock_reuseport *reuse;
  17.         struct bpf_prog *prog;
  18.         struct sock *sk2 = NULL;
  19.         u16 socks;

  20.         rcu_read_lock();
  21.         reuse = rcu_dereference(sk->sk_reuseport_cb);

  22.         /* if memory allocation failed or add call is not yet complete */
  23.         if (!reuse)
  24.                 goto out;

  25.         prog = rcu_dereference(reuse->prog);
  26.         socks = READ_ONCE(reuse->num_socks);
  27.         if (likely(socks)) {
  28.                 /* paired with smp_wmb() in reuseport_add_sock() */
  29.                 smp_rmb();

  30.                 if (prog && skb)
  31.                         sk2 = run_bpf(reuse, socks, prog, skb, hdr_len);
  32.                 else
  33.                         sk2 = reuse->socks[reciprocal_scale(hash, socks)];
  34.         }

  35. out:
  36.         rcu_read_unlock();
  37.         return sk2;
  38. }
  39. EXPORT_SYMBOL(reuseport_select_sock);
复制代码


为什么没有简单的轮流分配的选项? 我想优化单一udp flow啊
我打算开多个线程来收的,这个udp包五元组是一样的. 但是所有线程都能正确处理的.
这么搞的话,我创建再多线程也只能分到同一个线程上了.

论坛徽章:
0
发表于 2018-02-08 20:11 |显示全部楼层
/**
*  reuseport_select_sock - Select a socket from an SO_REUSEPORT group.
*  @sk: First socket in the group.
*  @hash: When no BPF filter is available, use this hash to select.
*  @skb: skb to run through BPF filter.
*  @hdr_len: BPF filter expects skb data pointer at payload data.  If
*    the skb does not yet point at the payload, this parameter represents
*    how far the pointer needs to advance to reach the payload.
*  Returns a socket that should receive the packet (or NULL on error).
*/
struct sock *reuseport_select_sock(struct sock *sk,
                                   u32 hash,
                                   struct sk_buff *skb,
                                   int hdr_len)
{
        struct sock_reuseport *reuse;
        struct bpf_prog *prog;
        struct sock *sk2 = NULL;
        u16 socks;

        rcu_read_lock();
        reuse = rcu_dereference(sk->sk_reuseport_cb);

        /* if memory allocation failed or add call is not yet complete */
        if (!reuse)
                goto out;

        prog = rcu_dereference(reuse->prog);
        socks = READ_ONCE(reuse->num_socks);
        if (likely(socks)) {
                /* paired with smp_wmb() in reuseport_add_sock() */
                smp_rmb();

                if (prog && skb)
                        sk2 = run_bpf(reuse, socks, prog, skb, hdr_len);
                else
                        sk2 = reuse->socks[reciprocal_scale(hash, socks)];
        }

out:
        rcu_read_unlock();
        return sk2;
}
EXPORT_SYMBOL(reuseport_select_sock);

论坛徽章:
0
发表于 2018-02-08 20:13 |显示全部楼层
为什么没有简单的轮流选择选项? 我要优化单一UDP FLOW的处理性能啊..
这么搞的话,创再多线程也只能分给其中一个了

论坛徽章:
0
发表于 2018-02-09 11:48 |显示全部楼层
原来多个线程同时sendto 同一个socket是有额外开销的,而且挺大。
原来多个线程通过SO_REUSEPORT recvfrom 各自独立的socket fd(绑到同一个port), 是可以提升收取效率的,可且提升还不小

论坛徽章:
0
发表于 2018-02-09 15:10 |显示全部楼层
哎哟,刚刚拜读kernel socket.h, 发现了recvmmsg()/sendmmsg()接口,
原来真可以一次系统调用就收发多个包

论坛徽章:
0
发表于 2018-02-10 18:17 |显示全部楼层
不过真是奇了怪.在lo上改用sendmmsg/recvmmsg一次收发16个包,(64字节payload). 居然没有任何提升,反而降了一点点.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP