Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slow logback start up times

Tags:

java

logback

In a very simple Java application, with logback using default values (no logback.xml in src/main/resources), the application starts up in around 400ms. As soon as we add a basic logback.xml to the classpath (src/main/resources), the start up time increases to around 5500ms. We have seen this in multiple projects. The config is as follows:

<configuration>

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%date{HH:mm:ss.SSS} %-7level - %-50logger{36} - %message%n</pattern>
        </encoder>
    </appender>

    <logger name="com.zaxxer.hikari" level="ERROR">
        <appender-ref ref="STDOUT"/>
    </logger>

    <logger name="org.sql2o" level="ERROR">
        <appender-ref ref="STDOUT"/>
    </logger>

    <root level="INFO">
        <appender-ref ref="STDOUT"/>
    </root>

</configuration>
like image 962
Nico Huysamen Avatar asked Jun 22 '16 15:06

Nico Huysamen


People also ask

Is Logback better than Log4j?

Log4J comes out the clear winner here, being able to write almost 270% more lines than JUL, 12.5% more than logback, 52% more than SLF4J SL.

What is Max history in Logback?

The maxHistory property controls the maximum number of archive files to keep, deleting older files. For example, if you specify monthly rollover, and set maxHistory to 6, then 6 months worth of archives files will be kept with files older than 6 months deleted.

What is rolling policy in Logback?

Size-based rolling policy allows to rollover based on file on each log file. For example, we can rollover to a new file when the log file reaches 10 MB in size. The maxFileSize is used to specify the size of each file when it gets rolled over.


2 Answers

5 seconds looks like a dns query timeout. It was the case for me. Just be sure that the hostname of your computer resolve to an ip. You can test that doing a ping:

ping `hostname`

If it resolve the name and start pinging, your problem is something else. But if you see a message saying "bad address", this may explain your problem.

To fix it simply, you can just add your hostname to the /etc/hosts file. Just add the hostname at the end of the line starting with 127.0.0.1. The change should apply immediately. It may not be the cleanest way to fix that, especially on modern linux with dhcp and so on. But if it works, you'll have a good pointer to how to solve this name resolution issue permanently.

like image 65
Damien Plumettaz Avatar answered Oct 24 '22 05:10

Damien Plumettaz


For me the issue was ipv6 resolution. Damien's answer above was spot on, only needed to add an ipv6 entry to etc/hosts. Something like:

::1        ${your.host.name}
like image 22
preston.m.price Avatar answered Oct 24 '22 06:10

preston.m.price