Published on 00/00/0000
Last updated on 00/00/0000
Published on 00/00/0000
Last updated on 00/00/0000
Share
Share
PRODUCT
3 min read
Share
Compliant logging is highly important for application development, as it affects performance.
Consider the following code:
parseMessage(List<Message> messages) {
log.debug("messages: " + messages);
}
or on a different version:
parseMessage(List<Message> messages) {
log.debug("messages: {}", messages.toString());
}
What is the issue with this code line of log writing ? This resulting with redundant toString() method invocation on each call, even when log verbosity resulting with nothing written in log. This method invocation is redundant, and when written in such processing methods which are executed per message, it can result in performance degradation in high scale executions. Similar effect could arise if this was intended for logging in info verbosity such that it was printed to log file.
During high scale test analysis, resources were analyzed. Execution was with 100 parallel threads processing the data. With tools like memory heap dump and thread dump, such described phenomena do not comes to place, since it results in temporary high resources usage of memory allocation, CPU processing, and possibly file IO if this is written to log according to verbosity. As these are temporary, it is not reflects in the memory heap dump and other tools. This is where process recording analysis comes to place. Look on memory, before logging changes: Here we see 70G of temporary memory consumption is used from the non-compliant logging. This can cause garbage collector redundant heavy processing, which uses system memory and CPU.
Look on memory, after logging changes: -> 70G of temporary memory consumption is removed.
Look on method profiling, before logging changes: Here we see many of the methods invocations are redundant.
Look on method profiling, after logging changes: -> Redundant methods invocations are removed.
Look on lock instances, before logging changes: Here we see long processing time is spent busy with logging, which can be changed to debug.
after fixing non-compliant logging, and moving some excessive logging to debug, execution showed massive improvement. Reduced at least temporary 70G memory consumption per the recording from the non-compliant logging. Processing time down from 1~ minute to 25 seconds after fixing non-compliant logging, and moving some excessive logging to debug.
Solution is valid code writing which will cause toString() method invocation only when needed, for example when log is in debug verbosity:
parseMessage(List<Message> messages) {
log.debug("messages: {}", messages);
}
Review logging, move unnecessary log to DEBUG or remove if not needed anymore post development.
Fixing non-compliant logging, and reducing excessive logging can drastically improve performance, reduce processing time, reduce CPU and temporary memory usage and I/O for log file writing.
Get emerging insights on innovative technology straight to your inbox.
Discover how AI assistants can revolutionize your business, from automating routine tasks and improving employee productivity to delivering personalized customer experiences and bridging the AI skills gap.
The Shift is Outshift’s exclusive newsletter.
The latest news and updates on generative AI, quantum computing, and other groundbreaking innovations shaping the future of technology.