Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Java logging performance of those things     - Chkconfig command Detailed service is added and shut down the system in two ways to start service under Linux (Linux)

- To learn linux security (Linux)

- Oracle set and remove columns unavailable (Database)

- Android media library of analysis: MediaProvider (Programming)

- Linux CPU Monitoring Index (Linux)

- PHP generates a random password several ways (Programming)

- OpenGL Programming Guide (8th edition of the original book) - compute shader (Programming)

- CentOS6 5 source compiler installation Hadoop2.5.1 (Server)

- Mounting Windows shared directory system under the Linux (Linux)

- Upgrading from Fedora 20 to 21 (Linux)

- Windows 8.1 and Ubuntu 14.04 dual system uninstall Ubuntu Tutorial (Linux)

- Recover accidentally deleted Nginx logs (Server)

- Linux command in the dialog whiptail (Linux)

- Python Django direct implementation of sql statement (Programming)

- Hadoop connection failed or stuck processing (Server)

- Linux system monitoring, top command of the diagnostic tool Detailed (Linux)

- How to track performance issues when using the Unity Game Development Android (Programming)

- Mongo-connector integrated MongoD to achieve incremental Solr index (Server)

- To install MySQL 5.6 binary packages under CentOS 6.4 64bit (Database)

- Safe learning through self-extracting package to achieve invasion (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:      
 
- Virtualbox virtual machine can not copy CentOS Network (Linux)
- Ubuntu 12.04 install RTL8723BE wireless network card driver (Programming)
- Use innobackupex full realization of MySQL hot backup (Database)
- Shell Scripting Basics (Linux)
- Depth understanding of the use of Spring Redis (Programming)
- CentOS 6.x and CentOS7 install MPlayer (Linux)
- The maximum subsequence algorithm and optimization problems (Programming)
- Linux Apache server configure to protect system security (Linux)
- To install MySQL on Linux (Database)
- Linux command in the dialog whiptail (Linux)
- GoldenGate update is missing (Database)
- How linux network security configuration (Linux)
- SpringMVC garbage processing (Programming)
- Installation Mate Desktop in FreeBSD 10.1 (Linux)
- Intel Graphics Installer 1.0.3 released, support for Ubuntu (Linux)
- Arrow keys, backspace key garbled in Python-2.7.5 Interactive Mode under CentOS 5.8 (Linux)
- Let Git variety of colors and custom log format output (Linux)
- Linux NFS service fixed ports and firewall configuration (Linux)
- CentOS 6.2 install git error Perl5 (Linux)
- How to implement large-scale distributed Yahoo depth study on the Hadoop cluster (Server)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.