SparkMan
V2EX  ›  Java

号称“能够在一个线程里每秒处理 6 百万订单”的 disruptor 框架,大家有在项目中使用吗?

  •  2
     
  •   SparkMan · Dec 18, 2015 · 13390 views
    This topic created in 3988 days ago, the information mentioned may be changed or developed.

    disruptor 号称"能够在一个线程里每秒处理 6 百万订单",好厉害,用过的使用场景是什么样的? RingBuffer 的效率如何?

    19 replies  •  2015-12-23 11:54:56 +08:00
    liangzhi102292
    liangzhi102292
    Dec 18, 2015
    1
    The best way to understand what the Disruptor is, is to compare it to something well understood and quite similar in purpose. In the case of the Disruptor this would be Java's BlockingQueue. Like a queue the purpose of the Disruptor is to move data (e.g. messages or events) between threads within the same process. However there are some key features that the Disruptor provides that distinguish it from a queue. They are:

    Multicast events to consumers, with consumer dependency graph.
    Pre-allocate memory for events.
    Optionally lock-free.

    来源: https://github.com/LMAX-Exchange/disruptor/wiki/Introduction
    slixurd
    slixurd
    Dec 18, 2015
    2
    同理,还有 Reactor 和 Akka 。但是实际上业务代码能用上这些的不多
    RxJava 倒是在 Android 上被应用了。服务器端没见到有人敢用。(虽然我用来写 utils ,但也只是边缘应用
    SparkMan
    SparkMan
    OP
    Dec 18, 2015
    3
    @liangzhi102292
    @slixurd 部门其他项目也有用 disruptor 的,主要是日志的发送。不容易摸透的东西,不好使用在生产中,所以还是得多摸索摸索
    est
    est
    Dec 18, 2015
    4
    每秒处理 6 百万订单。。。我一个订单有 1024 字节的 payload ,这就是 45G 的带宽。那么问题来了,你们服务器是万兆网卡互联吗?集群的交换机背板带宽有多大?
    SparkMan
    SparkMan
    OP
    Dec 18, 2015
    5
    @est 额, 6000000/1024/1024*8=45.7G 额,这个不是我们服务器,这个是 disruptor 官方的测试数据 https://lmax-exchange.github.io/disruptor/
    zacard
    zacard
    Dec 18, 2015
    6
    还真用了。效率刚刚的。
    SparkMan
    SparkMan
    OP
    Dec 18, 2015
    7
    @est 也要看他所谓的订单是什么内容吧,如果 200 字节,再加上双网卡应该还是可以的
    SparkMan
    SparkMan
    OP
    Dec 18, 2015
    8
    @zacard 你什么公司什么项目什么场景用到了?
    letuslinux
    letuslinux
    Dec 18, 2015
    9
    @est 处理 6 百万不用想就知道肯定是纯内存计算,无 io 的
    SparkMan
    SparkMan
    OP
    Dec 18, 2015
    10
    @letuslinux 恩,底层用的是数组而不是链表,可以直接让 CPU 友好的缓存,所以还省了很多读内存的开销
    Midnight
    Midnight
    Dec 18, 2015
    11
    能够在一个线程里每秒处理 6 百万订单

    是指在超算上跑吗?
    c742435
    c742435
    Dec 18, 2015 via Android
    12
    @Midnight 超算的一个线程未必有你家的一个线程快。
    est
    est
    Dec 18, 2015
    13
    @SparkMan inter-thread library 。。。。。。。。。这效率也是醉了。有些机器内存带宽也就 10G 。
    hantsy
    hantsy
    Dec 19, 2015
    14
    @slixurd 服务端应用应该有很多, 之前我用过 Reactor 。下一代的 Spring 5 会基于 Reactive Stream ,首先集成 Reactor , RxJava 。现在已经 Github 已经有一个项目了 spring-reactive 项目,作为 Spring 5 的前奏。
    hantsy
    hantsy
    Dec 19, 2015
    15
    disruptor 算法有一个论文,看了半天,比较晕,真的老了,静不下心看这些了。
    kozora
    kozora
    Dec 19, 2015
    16
    认识北京一家做 P2P 的在用这个框架= =
    liangzhi102292
    liangzhi102292
    Dec 21, 2015
    17
    @SparkMan 主要是应用在 传统的 PCP (生产者消费者问题)场景。传统的 blockingqueue 此类都需要加锁操作,而 disruptor 使用了 CAS 指令和 ringbuffer 使得效率变得非常高。具体可 google
    SparkMan
    SparkMan
    OP
    Dec 22, 2015
    18
    @liangzhi102292 额,我倒不是问你什么是 disruptor ,你说这些官方文档我肯定都看过,肯定也 google 过;我其实是问具体使用场景,比如我们其他项目组是日志收集项目中使用了,或者用 ringbuffer 重写了 logback 组件
    liangzhi102292
    liangzhi102292
    Dec 23, 2015
    19
    @SparkMan 都说了嘛, PCP 场景为了追求高性能
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4461 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 44ms · UTC 08:04 · PVG 16:04 · LAX 00:04 · JFK 03:04
    ♥ Do have faith in what you're doing.