Home IT Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ Java logging performance of those things     - How to use the process on the desktop xkill end Linux (Linux)

- Math objects easily overlooked but very convenient method --JavaScript (Programming)

- Jump table (skiplist) of code (Programming)

- The difference between Linux su and sudo commands (Linux)

- DataGuard add temporary data files bug (Database)

- C ++ stderr / stdout redirected to a file (Programming)

- How to install Ubuntu strategy game Wesnoth 1.12.0 (Linux)

- Protect your files, modify the Linux value Umask (Linux)

- Talk about the Linux folder permissions issue again (Linux)

- Sudo and Root Account in Ubuntu related (Linux)

- Java Prototype Pattern (Programming)

- Applications in Objective-C runtime mechanism (Programming)

- The AWK use Cygwin tools mysql binlog log viewer (Database)

- MongoDB simple replication configuration (Database)

- DRBD Principle and Features Overview (Server)

- Which file system is most suitable for your Linux system (Linux)

- Automate deployment of Docker-based Rails applications (Server)

- Linux, grep, sed usage (Linux)

- JITwatch installation under Linux (Linux)

- Growth since Oracle set the table space (Database)

  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.
- Getting Started with Linux: Learn how to install and access CentOS 7 Remote Desktop on a VPS (Server)
- To install the mail client terminal Evolution 3.13.2 under Ubuntu 14.04 (Linux)
- Linux System Getting Started Tutorial: Installing Brother printer in Linux (Linux)
- SaltStack installation and testing (Server)
- To see the Linux device tree (Linux)
- Ubuntu How to install screen recording tool Simple Screen Recorder 0.3.1 (Linux)
- See Shell Script Linux Server network traffic (Server)
- Sudo and Root Account in Ubuntu related (Linux)
- The Oracle VM VirtualBox use U disk under ubuntu (Linux)
- Linux unpack the tar file to a different directory (Linux)
- Linux boot process (Linux)
- Setup Qt development environment under Linux (Linux)
- Three easy open source firewall on the Linux platform (Linux)
- Use top to monitor the remote server (Server)
- JVM garbage collector and memory allocation strategy (Programming)
- Linux System Tutorial: Ubuntu on the desktop is disabled by default keyring to unlock tips (Linux)
- NAT (network address translation) Realization (Linux)
- Practical top command (Linux)
- DataGuard a hardware issue warnings found (Database)
- Node.js simple interface server (Server)
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.