本文介绍了为什么log4j2在异步记录器中使用LMAX Disruptor而不是其他任何内置的非阻塞数据结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在不同的记录器中进行异步记录.我碰巧看到了log4j2的异步记录器的详细信息.它在内部使用 LMAX Disruptor 来存储事件.他们为什么使用LMAX Disruptor而不是Java的任何内置非阻塞数据结构?

I am going through Asynchronous logging in different loggers. I happened to see log4j2's async logger in detail. It is using LMAX Disruptor internally to store events. Why are they using LMAX Disruptor instead of any built-in non-blocking data structure of java?

推荐答案

基于LMAX Disruptor的异步记录器为于2013年4月在Log4j 2.0-beta-5 中引入.当时的Log4j2需要Java6.唯一的内置非阻塞数据结构我在Java 6中知道的是 ConcurrentLinkedQueue .

Async Loggers, based on the LMAX Disruptor, were introduced in Log4j 2.0-beta-5 in April 2013. Log4j2 at the time required Java 6. The only built-in non-blocking datastructure that I am aware of in Java 6 is ConcurrentLinkedQueue.

为什么要破坏者?阅读 LMAX Disruptor白皮书,我了解到队列是对于高性能线程间通信,通常不是最佳的数据结构,因为队列的头尾总是有竞争.

Why the Disruptor? Reading the LMAX Disruptor white paper, I learned that queues are generally not optimal data structure for high-performance inter-thread communication, because there is always contention on the head or the tail of the queue.

LMAX创建了更好的设计,并在其性能测试中找到 LMAX Disruptor的性能大大优于 ArrayBlockingQueue .他们没有测试 ConcurrentLinkedQueue ,因为它是无限制的,并且在使用方很慢的情况下(这很常见)会破坏生产方(内存不足错误).

LMAX created a better design, and found in their performance tests that the LMAX Disruptor vastly outperformed ArrayBlockingQueue. They did not test ConcurrentLinkedQueue because it is unbounded and would blow up the producer (out of memory error) in scenarios where there is a slow consumer (which is quite common).

我当时没有来自自己测试的数据,但我记得 ConcurrentLinkedQueue ArrayBlockingQueue 更好,这相当于吞吐量提高了2倍(我的内存确切的数字是含糊的).因此,LMAX Disruptor仍然明显更快,并且结果之间的差异小得多. ConcurrentLinkedQueue 有时的结果比 ArrayBlockingQueue 差,这很奇怪.

I don't have data from my own tests at the time, but I remember that ConcurrentLinkedQueue was better than ArrayBlockingQueue, something like 2x higher throughput (my memory of the exact numbers is vague). So LMAX Disruptor was still significantly faster, and there was much less variance around the results. ConcurrentLinkedQueue sometimes had worse results than ArrayBlockingQueue, quite strange.

LMAX Disruptor的性能稳定,比其他组件快得多,并且受到限制,因此,如果应用程序使用速度较慢的使用者(例如登录数据库或控制台),我们不会耗尽内存.

LMAX Disruptor performance was stable, much faster than other components, and it was bounded, so we would not run out of memory if an application would use a slow consumer like logging to a database or the console.

作为异步记录器性能页面,并且整体Log4j2 性能页面显示,使用LMAX Disruptor放置就性能而言,Log4j2领先于竞争对手产品,肯定是在Log4j2首次发布之时.

As the Async Loggers performance page, and the overall Log4j2 performance page shows, the use of LMAX Disruptor put Log4j2 miles ahead of competing offerings in terms of performance, certainly at the time when Log4j2 was first released.

这篇关于为什么log4j2在异步记录器中使用LMAX Disruptor而不是其他任何内置的非阻塞数据结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 19:38