20 second log4j2 configuration. How to fix?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

20 second log4j2 configuration. How to fix?

Gregg Donovan
Hello! We noticed when profiling our server startup that log4j2's configuration process was taking over 20 seconds. From the YourKit profile (see below) it appears to be from scanning the classpath for JARs that may contain plugins. We have a lot of JARs, so this takes some time, I suppose.

Our configuration is fairly minimal. The StackdriverJsonLayout is a custom Etsy plugin.

<?xml version="1.0" encoding="UTF-8" ?>
<Configuration status="error" dest="error" shutdownHook="disable" packages="com.etsy.util,org.apache.logging.log4j.core.layout">
<Appenders><Console name="console"><StackdriverJsonLayout/></Console></Appenders>
<Loggers><Root level="info"><AppenderRef ref="console" /></Root></Loggers>
</Configuration>


How can we minimize log4J2 configuration time? We're open to anything, including using Java configuration. Minimizing configuration time trumps all other concerns.

Thanks!

Gregg Donovan
Staff Software Engineer, Etsy.com



Reply | Threaded
Open this post in threaded view
|

Re: 20 second log4j2 configuration. How to fix?

Ralph Goers
Do you really need the packages attribute? If you have custom plugins they will normally be included in a file that is created when the annotation processor runs during compilation. If that file is present then package scanning is not required.

Ralph

> On Jul 30, 2019, at 10:38 AM, Gregg Donovan <[hidden email]> wrote:
>
> Hello! We noticed when profiling our server startup that log4j2's configuration process was taking over 20 seconds. From the YourKit profile (see below) it appears to be from scanning the classpath for JARs that may contain plugins. We have a lot of JARs, so this takes some time, I suppose.
>
> Our configuration is fairly minimal. The StackdriverJsonLayout is a custom Etsy plugin.
>
> <?xml version="1.0" encoding="UTF-8" ?>
> <Configuration status="error" dest="error" shutdownHook="disable" packages="com.etsy.util,org.apache.logging.log4j.core.layout">
> <Appenders><Console name="console"><StackdriverJsonLayout/></Console></Appenders>
> <Loggers><Root level="info"><AppenderRef ref="console" /></Root></Loggers>
> </Configuration>
>
> How can we minimize log4J2 configuration time? We're open to anything, including using Java configuration. Minimizing configuration time trumps all other concerns.
>
> Thanks!
>
> Gregg Donovan
> Staff Software Engineer, Etsy.com
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: 20 second log4j2 configuration. How to fix?

Gregg Donovan
Thanks, Ralph! That's really helpful.

We use Bazel to build (bazel.build) and didn't have the PluginProcessor
configured. When I try adding PluginProcessor to Bazel, Bazel errors[1] due
to the PluginProcessor writing to stdout in 2.12.0
<https://github.com/apache/logging-log4j2/blob/log4j-2.12.0/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/processor/PluginProcessor.java>
.

I see that on master PluginProcessor uses javax.annotation.processing.Messenger
to send status and error messages. Would you be interested in backporting
that bit to a 2.x release?

Thanks!

Gregg


[1] -- "running annotation processors (PluginProcessor) failed: Worker
process returned an unparseable WorkResponse! Did you try to print
something to stdout? Workers aren't allowed to do this, as it breaks the
protocol between Bazel and the worker process."



On Tue, Jul 30, 2019 at 2:32 PM Ralph Goers <[hidden email]>
wrote:

> Do you really need the packages attribute? If you have custom plugins they
> will normally be included in a file that is created when the annotation
> processor runs during compilation. If that file is present then package
> scanning is not required.
>
> Ralph
>
> > On Jul 30, 2019, at 10:38 AM, Gregg Donovan <[hidden email]>
> wrote:
> >
> > Hello! We noticed when profiling our server startup that log4j2's
> configuration process was taking over 20 seconds. From the YourKit profile
> (see below) it appears to be from scanning the classpath for JARs that may
> contain plugins. We have a lot of JARs, so this takes some time, I suppose.
> >
> > Our configuration is fairly minimal. The StackdriverJsonLayout is a
> custom Etsy plugin.
> >
> > <?xml version="1.0" encoding="UTF-8" ?>
> > <Configuration status="error" dest="error" shutdownHook="disable"
> packages="com.etsy.util,org.apache.logging.log4j.core.layout">
> > <Appenders><Console
> name="console"><StackdriverJsonLayout/></Console></Appenders>
> > <Loggers><Root level="info"><AppenderRef ref="console"
> /></Root></Loggers>
> > </Configuration>
> >
> > How can we minimize log4J2 configuration time? We're open to anything,
> including using Java configuration. Minimizing configuration time trumps
> all other concerns.
> >
> > Thanks!
> >
> > Gregg Donovan
> > Staff Software Engineer, Etsy.com
> >
> >
> >
>
>