Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Java logging performance of those things     - Ubuntu 15.04 / 14.04 install Ubuntu After Install 2.6 (Linux)

- To compile and install Redis Linux and master-slave replication configuration (Database)

- The file name is garbled or deleted files with special characters under Linux (Linux)

- The three-way division of the sorting algorithm Quicksort (Programming)

- RHEL7.0 log system (Linux)

- C data types is how it is supported by most computer systems (Programming)

- CentOS 6.6 source compiler GCC upgrade to 4.8.2 (Linux)

- Google open source TCP team repaired the Linux kernel TCP flaw (Linux)

- Oracle 11g creates virtual private directory RMAN-06004 ORA-00942 error handling (Database)

- How to modify the Sublime in Tab four spaces (Linux)

- Fedora network set up simple (Linux)

- Get and Post requests Comments (Linux)

- Getting case of Python Hello World (Programming)

- Oracle SDE and maintain common commands - Display space (Database)

- Learning OpenCV: (VS2010-openCV2.4.3-win7 configuration instructions) (Linux)

- Oracle 11g Export guide problem not an empty table (Database)

- Linux system security knowledge (Linux)

- Ubuntu 14.04 How to install Cinnamon 2.4.5 (Linux)

- Do not find ifconfig eth0 and IP address under CentOS6.5 (Linux)

- Let your PHP 7 faster (GCC PGO) (Linux)

 
         
  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.
     
         
       
         
  More:      
 
- How to install Linux Kernel 4.0 On CentOS 7 system (Linux)
- tar decompression problems gzip: stdin: not in gzip format (Linux)
- Linux Creating a new user error Creating mailbox file: File exists (Linux)
- Linux system security knowledge (Linux)
- How to install Laravel PHP framework on CentOS 7 / Ubuntu 15.04 (Server)
- Use cmake to compile and install MySQL 5.5 (Database)
- Initialization and starting process of Linux (Linux)
- Calculate CPU utilization (Linux)
- Linux environment installation of rvm and ruby (Linux)
- Git remote repository Explanation (Linux)
- Debian 7 and Debian 8 users how to install Oracle Java 8 (Linux)
- RedHat / CentOS ext4 partition can not be formatted large supplementary ext4 formatting (Linux)
- Oracle RMAN repair logical bad blocks (Database)
- a virtual machine created migrated to host RHEL6.4 on Ubuntu 14.04 (Linux)
- View processes and threads under Linux (Linux)
- vector C ++ sequence containers (Programming)
- SVN hook code set to synchronize Web directory (Server)
- Linux5 install MySQL 5.6 (RPM mode) (Database)
- Top command: the Task Manager under linux (Linux)
- 64-bit Windows Server 2012 R2 install Oracle 10g Second Edition (Database)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.