Hey Ganapathi!

First, `JsonLayout` (JL) and `JsonTemplateLayout` (JTL) are two different
beasts, but more importantly, JTL is the successor of JL. We are keeping JL
around only for backward-compatibility reasons. All JSON-based log needs
are advised to be sufficed using JTL.

JTL is heavily optimized and battle-tested. I, as one of JTL developers,
can assure you that it is blazing fast. Similar to `PatternLayout` (PL),
JTL uses garbage-free formatting constructs wherever possible. Hence, I
would expect JTLs performance to be on par with PL, if not faster! If you
or anybody happens to find a case where JTL performs worse than PL, I will
volunteer to fix it ASAP!

> Is it a reasonable thing to compare the performance of these two layouts?

Not really. Since JTL produces extra JSON-structure which is not there in
PL. This said, judging from my experience, I would expect JTL to perform on
par in most cases.

> Are there any existing resources comparing the performance of these two
layouts?

Nope. But feel free to do your own comparison by tweaking
`JsonTemplateLayoutBenchmark` in `log4j-perf`.

> What considerations should we make if we switch to JsonTemplateLayout?

The only thing you need to keep in mind while using JTL is that resolvers
incurring garbage (e.g., using regex in stack trace truncation) will mostly
determine the overall latency. Since a majority of the resolvers are
garbage-free, those will complete instantly. Though this advice more or
less applies to any Java code, including PL.

If you happen to have any questions, feedback, feature/change requests,
etc. feel free to share them here.

Cheers!

On Wed, Nov 16, 2022 at 11:55 AM Ganapathi Vara Prasad <
ganapathibasamse...@gmail.com> wrote:

> Hello Team,
>
> Our log4j2 configuration uses *PatternLayout* and we are exploring
> switching to JsonLayout for simplifying integration with ELK. I am trying
> to find any performance comparison between pattern and json layouts but
> couldn't find any. I could find only the JsonTemplateLayout benchmark in
> the log4j-perf module.
>
> I wanted to know:
>
>    - Is it a reasonable thing to compare the performance of these two
>    layouts?
>    - Are there any existing resources comparing the performance of these
>    two layouts?
>    - What considerations should we make if we switch to JsonTemplateLayout?
>
> Thank you for the help.
>
> --Ganapati
>

Reply via email to