翻译自disruptor在github上的文档,https://github.com/LMAX-Exchange/disruptor/wiki/Getting-Started

Basic Tuning Options 基本的调优方法

Using the above approach will work functionally in the widest set of deployment scenarios. However, if you able to make certain assumptions about the hardware and software environment that the Disruptor will run in then you can take advantage of a number of tuning options to improve performance. There are 2 main options for tuning, single vs. multiple producers and alternative wait strategies. ------------------------------------------------------------------------------------------------- 使用上面方法在大多数的部署场景里都可以很好的工作。 但是,如果你能搞清楚你将在什么样的硬件和软件环境中运行disruptor的话,有一些个调优方法能够提高性能。 主要有2种方法进行调优:单生产者vs多生产者,选择合适的等待策略。

Single vs. Multiple Producers  单生产者还是多生产者?

One of the best ways to improve performance in concurrect systems is to ahere to the Single Writer Princple, this applies to the Disruptor. If you are in the situation where there will only ever be a single thread producing events into the Disruptor, then you can take advantage of this to gain additional performance. 改进并发系统性能的最佳办法之一就是遵守“单写入者”定律,Disruptor就是这样干的。 如果你只需要用一个单生产者线程生成事件投入Disruptor的话,这样的应用场景会获得额外的性能表现。

public class LongEventMain {    

  public static void main(String[] args) throws Exception     {        

  //.....        

  // Construct the Disruptor with a SingleProducerSequencer        

  Disruptor<LongEvent> disruptor = new Disruptor(factory,       

                            bufferSize,     

                            ProducerType.SINGLE, // Single producer                                                       

                            new BlockingWaitStrategy(),   

                                         executor);

        //.....     }

}

To give an indication of how much of a performance advantage can be achieved through this technique we can change the producer type in the OneToOne performance test. Tests run on i7 Sandy Bridge MacBook Air. 为了证明这样的技术到底能带来多少性能上的提升, 我们可以通过调整producerType来一场1对1的性能测试。(译者注:ProducersType.Single vs. ProducersType.Multiple ) 测试环境:i7 Sandy Bridge MacBook Air

Multiple Producer

Run 0, Disruptor=26,553,372 ops/sec

Run 1, Disruptor=28,727,377 ops/sec

Run 2, Disruptor=29,806,259 ops/sec

Run 3, Disruptor=29,717,682 ops/sec

Run 4, Disruptor=28,818,443 ops/sec

Run 5, Disruptor=29,103,608 ops/sec

Run 6, Disruptor=29,239,766 ops/sec

Single Producer

Run 0, Disruptor=89,365,504 ops/sec

Run 1, Disruptor=77,579,519 ops/sec

Run 2, Disruptor=78,678,206 ops/sec

Run 3, Disruptor=80,840,743 ops/sec

Run 4, Disruptor=81,037,277 ops/sec

Run 5, Disruptor=81,168,831 ops/sec

Run 6, Disruptor=81,699,346 ops/sec

Alternative Wait Strategies 可选择的等待策略

BlockingWaitStrategy 阻塞等待策略

The default wait strategy used by the Disruptor is the BlockingWaitStrategy. Internally the BlockingWaitStrategy uses a typical lock and condition variable to handle thread wake-up. The BlockingWaitStrategy is the slowest of the available wait strategies, but is the most conservative with the respect to CPU usage and will give the most consistent behaviour across the widest variety of deployment options. However, again knowledge of the deployed system can allow for additional performance. -------------------------------------------------------------------------------------------------------- disruptor的默认消费者等待策略是BlockingWaitStrategy。 BlockingWaitStrategy内部使用的是典型的锁和条件变量机制,来处理线程的唤醒。 这种策略是所有disruptor等待策略中最慢的一种,但是是最保守使用消耗cpu的一种用法,并且在不同的部署环境下最能保持性能一致。 但是,随着我们对部署系统的了解可以优化出额外的性能。(译者注:BlockingWaitStrategy是适用面最广的默认策略, 但是随着对具体系统部署环境的具体分析,我们可以采用其他策略替换它,来取得更好的优化性能)

SleepingWaitStrategy  休眠等待策略

Like the BlockingWaitStrategy the SleepingWaitStrategy it attempts to be conservative with CPU usage, by using a simple busy wait loop, but uses a call to  LockSupport.parkNanos(1)  in the middle of the loop. On a typical Linux system this will pause the thread for around 60μs. However it has the benefit that the producing thread does not need to take any action other increment the appropriate counter and does not require the cost of signalling a condition variable. However, the mean latency of moving the event between the producer and consumer threads will be higher. It works best in situations where low latency is not required, but a low impact on the producing thread is desired. A common use case is for asynchronous logging. --------------------------------------------------------------------------------------------------------- 像BlockingWaitStrategy一样,SleepingWaitStrategy也是属于一种保守使用cpu的策略。 它使用一个简单的loop繁忙等待循环,但是在循环体中间它调用了LockSupport.parkNanos(1)。 通常在linux系统这样会使得线程停顿大约60微秒。但是这样做的好处是,生产者线程不需要额外的动作去累加计数器,也不需要产生条件变量信号量开销。 但是这样带来的负面影响是,在生产者线程与消费者线程之间传递event的延迟变高了。所以SleepingWaitStrategy适合在不需要低延迟, 但需要很低的生产者线程影响的情形。一个典型的案例就是异步日志记录功能。

YieldingWaitStrategy  服从等待策略

The YieldingWaitStrategy is one of 2 Wait Strategies that can be use in low latency systems, where there is the option to burn CPU cycles with the goal of improving latency. The YieldingWaitStrategy will busy spin waiting for the sequence to increment to the appropriate value. Inside the body of the loop  Thread.yield()  will be called allowing other queued threads to run. This is the recommended wait strategy when need very high performance and the number of Event Handler threads is less than the total number of logical cores, e.g. you have hyper-threading enabled. ---------------------------------------------------------------------------------------------------------- YieldingWaitStrategy是2种可以用于低延迟系统的等待策略之一,充分使用压榨cpu来达到降低延迟的目标。 YieldingWaitStrategy不断的循环等待sequence去递增到合适的值。 在循环体内,调用Thread.yield()来允许其他的排队线程执行。 这是一种在需要极高性能并且event handler线程数少于cpu逻辑内核数的时候推荐使用的策略。 例如,你开启了超线程。(译者注:超线程是intel研发的一种cpu技术,可以使得一个核心提供两个逻辑线程,比如4核心超线程后有8个线程)

BusySpinWaitStrategy  繁忙旋转等待策略

The BusySpinWaitStrategy is the highest performing Wait Strategy, but puts the highest constraints on the deployment environment. This wait strategy should only be used if the number of Event Handler threads is smaller than the number of physical cores on the box.  E.g. hyper-threading should be disabled. BusySpinWaitStrategy是性能最高的等待策略,但是受部署环境的制约依赖也越强。 仅仅当event处理线程数少于物理核心数的时候才应该采用这种等待策略。 例如,超线程不可开启。

disruptor调优方法的更多相关文章

  1. JVM垃圾回收机制总结:调优方法

    转载: JVM垃圾回收机制总结:调优方法 JVM 优化经验总结 JVM 垃圾回收器工作原理及使用实例介绍

  2. JVM调优总结:调优方法

    JVM调优总结:调优方法 2012-01-10 14:35 和你在一起 和你在一起的博客 字号:T | T 下面文章将讲解JVM的调优工具以及如何去调优等等问题,还有一些异常问题的处理.详细请看下文. ...

  3. Web app 的性能瓶颈与性能调优方法

    1. web app 性能测试工具使用 2. mysql 性能分析与调优方法

  4. 性能测试培训:tomcat性能调优方法

    性能测试培训:tomcat性能调优方法   poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.在poptest的loadrunner ...

  5. JVM调优方法

    目 录 目 录 I 诠释JVM调优 1 第1章 JVM内存模型及垃圾收集算法 1 1.1 根据Java虚拟机规范,JVM将内存划分为 1 1.2 垃圾回收算法 1 第2章 内存泄漏及解决方法 2 2. ...

  6. 【Hibernate 8】Hibernate的调优方法:抓取策略

    在上一篇博客中,介绍了Hibernate的缓存机制.合理的配置缓存,可以极大程度上优化Hibernate的性能.这篇博客,介绍另外一个调优方式:抓取策略. 一.什么是抓取策略 抓取策略(fetchin ...

  7. JVM垃圾回收机制总结(7) :调优方法

    JVM调优工具 Jconsole,jProfile,VisualVM Jconsole : jdk自带,功能简单,但是可以在系统有一定负荷的情况下使用.对垃圾回收算法有很详细的跟踪.详细说明参考这里 ...

  8. JVM调优总结(十)-调优方法

    JVM调优工具 Jconsole,jProfile,VisualVM Jconsole : jdk自带,功能简单,但是可以在系统有一定负荷的情况下使用.对垃圾回收算法有很详细的跟踪.详细说明参考这里 ...

  9. JVM调优总结-调优方法

    JVM调优工具 Jconsole,jProfile,VisualVM Jconsole : jdk自带,功能简单,但是可以在系统有一定负荷的情况下使用.对垃圾回收算法有很详细的跟踪 JProfiler ...

随机推荐

  1. session以及分布式服务器session共享

    一.session的本质 http协议是无状态的,即你连续访问某个网页100次和访问1次对服务器来说是没有区别对待的,因为它记不住你. 那么,在一些场合,确实需要服务器记住当前用户怎么办?比如用户登录 ...

  2. phpstorm2018.3的安装和激活和汉化

    安装 第一步:解压并打开文件,运行安装程序,点击Next进入下一步, 第二步:选择软件安装目录,自定义选择安装根目录--> 注意!后面还需要找安装目录里的文件,所以记住安装到一个比较容易查看的目 ...

  3. windows下用tcc编译Lua

    脚本来源:Demon's Blog,http://demon.tw/software/compile-lua-with-tcc.html 版权归原作者所有 使用方法: 1.下载tcc编译器,本文解压目 ...

  4. 如何定义一个高逼格的原生JS插件

    插件的需求 我们写代码,并不是所有的业务或者逻辑代码都要抽出来复用.首先,我们得看一下是否需要将一部分经常重复的代码抽象出来,写到一个单独的文件中为以后再次使用.再看一下我们的业务逻辑是否可以为团队服 ...

  5. [python] can not find app ,module

    can not find module 1 startapp appname 而不是 startproject 2 不要自己创建项目根目录,要用mamage.py生成 can not find app ...

  6. 小X归来 模拟赛1 解析

    Problem1 单峰 小X 归来后,首先对数列很感兴趣.他想起有1类特殊的数列叫单峰数列. 我们说一个数列 {ai} 是单峰的,当且仅当存在一个位置 k 使得 ai < ai+1(i < ...

  7. Codeforces C. NP-Hard Problem 搜索

    C. NP-Hard Problem time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...

  8. Java中通过SimpleDateFormat格式化当前时间:/** 输出格式:20060101010101001**/

    import java.util.*; import java.text.SimpleDateFormat; int y,m,d,h,mi,s,ms; String cur; Calendar cal ...

  9. 将C语言宏定义数值转换成字符串!

    将C语言宏定义转换成字符串! 摘自:https://blog.csdn.net/happen23/article/details/50602667 2016年01月28日 19:15:47 六个九十度 ...

  10. kafka系列 -- 基础概念

    kafka是一个分布式的.分区化.可复制提交的发布订阅消息系统 传统的消息传递方法包括两种: 排队:在队列中,一组用户可以从服务器中读取消息,每条消息都发送给其中一个人. 发布-订阅:在这个模型中,消 ...