Home IT Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ Java logging performance of those things     - Cacti monitoring service Nginx (Linux)

- Justniffer installed on Ubuntu 15.04 (Linux)

- Java heap (Heap) and stack difference (Programming)

- Solaris 10 nagios monitoring system (Linux)

- Automatic batch resolve dependencies problem locally installed rpm package (Linux)

- Autojump: an advanced cd command in the Linux file system fast navigation (Linux)

- Linux command Detailed chpasswd bulk edit user password (Linux)

- Build RPM package uses Docker mirror (Linux)

- Kitematic how seamless and DockerFILE (Server)

- Use Python automatically cleared Android Engineering excess resources (Programming)

- See Linux kernel, CPU, memory, and various versions of the command module and means (Linux)

- MySQL restart process can not be taken lightly (Database)

- Linux System Tutorial: Fix ImportError: No module named wxversion error (Linux)

- Security Knowledge: How to hide a backdoor PHP file tips (Linux)

- SpringMVC garbage processing (Programming)

- Using C ++ Container Templates in Shared Memory (Programming)

- Ora-1092: OPI colleague K aborting process --- killed by OO Well killer (Database)

- Schema snapshot rollback (Database)

- Installation on the way to the root source Ubuntu Server 14.04 LTS version Odoo8.0 (Server)

- shell script: the number of characters in the text to print no more than 6 words (Programming)

  Java logging performance of those things
  Add Date : 2017-09-18      
  In any system, the log is a very important part of it is an important basis to reflect the operation of the system, but also essential clues when troubleshooting. Most people recognize the importance of the log, but how many people thought carefully about how to play log, log influence on performance, how much of it? Today, let's talk about those things Java logging performance.

Speaking of Java logs, I am sure you will say that you want to choose the right level of logging, control the contents of the log, but this is only the first step in a long march ...... even if some of the DEBUG level logging in a production environment is not output to a file, or It may bring no small cost. We put aside the judgment and the cost of a method call, there is such a contrast in performance Log4J 2.x document:

 logger.debug ( "Entry number:" + i + "is" + String.valueOf (entry [i]));
 logger.debug ( "Entry number: {} is {}", i, entry [i]);
The effect of the above two statements in the log output is the same, but when you close DEBUG logs, their cost is not the same, the main impact is that the string conversion and string concatenation, regardless of whether the entry into force, the former will be variable converted to strings and stitching, while the latter will only perform these actions when needed. Log4J is the official test results both in performance can differ by two orders of magnitude. Imagine if the toString () method with an object in the ToStringBuilder to reflect the output of dozens of properties, then how much can save resources.

Therefore, some still in use Log4J 1.x or Apache Commons Logging (they do not support the wording template {}) companies will have the appropriate encoding specification, requiring a certain level of logs (such as DEBUG and INFO) to increase output before judge :

if (logger.isDebugEnabled ()) {
    logger.debug ( "Entry number:" + i + "is" + String.valueOf (entry [i]));
In addition to the log level and log messages, usually in the log will contain additional information, such as date, thread name, class information, MDC variables, and so, according to Takipi tests if class was added in the log, the performance would drop dramatically, than the default configuration from LogBack the throughput decline of 6 percent. If you must print the type of information, consider using the class name named Logger.

In a distributed system, a request may go through a number of different subsystems, then it is best to generate a UUID attached to the request, each subsystem when printing logs are the UUID on the MDC, the ease of subsequent queries related log. "The Ultimate Guide: 5 Methods For Debugging Production Servers At Scale" in an article on how to debug in a production environment is given a lot of recommendations, several of which are good on the log, and this is one of them. Another tip is to record all uncaught log, in fact, have thrown overhead, record exception will also bring some overhead, mainly because Throwable class fillInStackTrace default method is synchronous:

public synchronized native Throwable fillInStackTrace ();
General use logger.error exception stack will be played, if there are certain requirements for throughput, may be considered in the case of run-time override this method, remove the synchronized native, direct return an instance of itself.

After talking with the contents of the log, look at Appender. In Java, talking IO operations we will think of NIO, the JDK 7 also the AIO, know to read and write at least add a Buffer, logs, too, synchronous write Appender somewhat powerless in highly concurrent systems in large flow, At this time in respect of the use AsyncAppender, again using LogBack:

10 concurrent threads, the output 200 characters INFO log, AsyncAppender throughput can be up to 3.7 times the FileAppender. Without loss of the log, use the same AsyncAppender, queue length will have some impact on performance.

If you are using Log4J 2.x, so in addition to AsyncAppender, you can also consider higher performance asynchronous Logger, because the bottom layer of the Disruptor, no lock overhead performance is more amazing. According Log4J 2.x official test, again using Log4J 2.x:

64 threads under asynchronous Logger 12 times faster than asynchronous Appender, Logger 68 times faster than synchronous.

Also is asynchronous, there will be differences between the library:

Under the same hardware environment, Log4J 2.x use all asynchronous Logger 12 times faster than LogBack of AsyncAppender, 19 times faster than the Log4J 1.x asynchronous Appender.

Asynchronous Logger Log4J 2.x powerful performance, but there are different voices, I think it is just a very elegant look, only as a toy. On this issue, or left to the reader to think about it.

If you must use synchronization Appender, consider using ConsoleAppender, then STDOUT redirected to a file, which can also have about 10% performance improvement.

Most production systems are clustered deployment for logging distributed on different servers, use a tool like Logstash collected enough. Many times will be deployed on a single machine with multiple instances in order to make full use of server resources, then do not covet log monitoring or logging to facilitate inquiries, the log is written to multiple instances of the same log file, although LogBack provides a prudent pattern, It allows multiple JVM write to the same file in the log, but this way also have an impact on the performance of the same, about 10% degrade performance.

If a large number of written demand for the same log file, you can consider splitting logs into separate files, one approach is to add multiple Appender, while modifying the code, different situations using different Logger; LogBack provides SiftingAppender, can be directly based on MDC split the contents of the log, Jetty tutorial examples have to split logs according to host, but according to Takipi testing, performance SiftingAppender will split with the growth of the number of files together to enhance, when split into four files when 10 concurrent SiftingAppender throughput is about three times more than the FileAppender.

The above data read so much, I wonder if you feel there is a lot of room for improvement in the log, you have not optimized the system to the extreme, or if you also have other log optimization methods, you may wish to share.
- Analytical Ceph: handle network layer (Server)
- MySQL binlog automatic cleanup script (Database)
- Shared directory settings between Linux and Linux (Linux)
- 10 tips daily Docker (Server)
- Ubuntu 14.04 configure JDK1.8.0_25, switchable version (Linux)
- Security enhancements in Ubuntu ssh service (Linux)
- Linux System Getting Started Learning: On Linux how to convert text files to PDF (Linux)
- Linux cron job (crontab) Examples (Linux)
- Computer security perimeter recommendations (Linux)
- MySQL various log summary (Database)
- Linux redirection and piping (Linux)
- Talking about the shortcomings and deficiencies of the firewall (Linux)
- Linux server is how to do after the invasion (Linux)
- shellinabox: one uses AJAX Web-based terminal emulator (Linux)
- To install Jetty server configuration in detail (Server)
- Efficient Linux Shell - Shell special characters Summary (Linux)
- Linux Mint 17.2 64 bit installation Docker and management software seagull (Linux)
- Modern Objective-C syntax and new features (Programming)
- To install Xen in Ubuntu 12.04 (Linux)
- Linux Security Module (LSM) Introduction (Linux)
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.