Java Open Source Log framework Competition

Source: Internet
Author: User
Keywords We J2.

Http://www.aliyun.com/zixun/aggregation/14223.html "> Application system, the log is an indispensable important part of all the application of error information should be able to find in the log file, Some application system log may be very small, some large application system log is quite large, while the log file must be user-friendly and search, to have a high performance, otherwise it will affect the performance of the application system.

Since logs often involve IO read-write disks (or are blocked or asynchronous), this can be time-consuming. When there is a lot of data in a large system, the time that the log takes is apparent. In this article, we will delve into the current Java open Source world's leading five log frames, in all aspects of comparison, to point out that this article is not to explore which log framework is the best, but only to list their strengths and weaknesses.

The five log frames we selected were:

1. log4j

2. Log4j2

3. Logback

4. slf4j Simple Logging (slf4j SL)

5. Java Util Logging (June)

We want to compare the performance of these log frameworks for basic logging activity, each of which includes the timestamp and the process ID of its context. We conducted the following four assessment:

1. Record string constants

2. Logging the. ToString () value of a POJO to POJO use. ToString () method

3. Logging a Throwable object records throwable objects 4 test only. ToString () method

We decided to evaluate each scenario five times to determine which one had the best results by measuring the number of times the day paper was completed. In each test, the log engine is executed with 10 threads in a minute, and the maximum 2 deviations are eliminated, averaging the remaining three times.

In each individual logging operation, we let the CPU perform some operations (such as checking whether a random number is prime) when logging. The log engines for these evaluations are run by SLF4J using their respective default configurations. The evaluation was done on the Amazon M1.large EC2 instance.

In Log4j2 's first Test, we set%c's layout parameters (reference: http://logging.apache.org/log4j/2.x/manual/layouts.html), which increases its overhead, at @ REMKOPOPMA's recommendation, we have updated the set to%c (the name of the log) to match other configurations, which gives LOG4J2 a significant performance boost, and in the following two graphs, it is worth noting the performance overhead of the recording context.

Use Settings for%c:

Use Settings for%c:

Complete test result set reference to this link:https://docs.google.com/spreadsheet/ccc?key=0alceaf46x4gpdhboltdyq29nrdh6v1dry00zt1fwwwc& Usp=sharing

The following is a detailed analysis of test results based on 4 scenarios:

A string constant

In this round of competition, the log engine is required to use thread and timestamp contexts to record string constants. LOG4J is the champion, more than June can write 270% journal line, more than Logback 12.5%, more than slf4j SL 52%. The interesting thing is that before we change the configuration of log4j2, it writes more rows than 1/4, after changing the configuration, the performance is ranked third, only 30% less than the number of rows recorded in the Logback.

Two. ToString ()

The Pojo (using the. ToString method) is recorded in this round, and the same thread and timestamp are used. As a result, log4j2 is about the same as the first round, but has a 25% performance boost compared to SLF4J sl. Log4j and Logback, ranked third, had a throughput of 88% of SLF4J sl.

Three. Throwable

In this round of competition, the log engine logs exception objects and related descriptive information. Log4j2 is ranked first, its performance is 3 times times higher than slf4j SL, slf4j SL is in fifth place.

and log4j and Logback can only be ranked in this round after the championship, the number of rows recorded only about half of the championship, and the second is June, can record the title of the Log4j2 log volume of about 82%.

Four. ToString () method competition

When processing server logs, the context of each log entry (such as the thread ID, the related context of the class, the timestamp, and so on) is as important as the log content. In previous tests, you used flags that were common in most log files-thread ID numbers and timestamps. Next we think it's worth analyzing the performance of the. toString () method in the log.

At this point, Log4j2 is the winner (if you change the configuration to get 180% performance boost), win Logback and June about 25%. SL4FJ SL was defeated. In five tests per round, slf4j SL is better than not enabled when Appenders is enabled.

Log4j has a 15% increase in throughput. June is no match for log4j and log4j2 in this round, and the result is the same as not using contextual data.

The test code for this article can be downloaded in https://github.com/takipi/the-logging-olympics.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.