Yes writing to the console on either Windows or Linux was ~50x(!) slower than 
writing to a file. This is documented on the log4j performance page. 

Mikael’s JIRA ticket on the direct option has some perf numbers: 
https://issues.apache.org/jira/browse/LOG4J2-1395
I seem to remember that the direct option gave about a 10% speed up, but I’m 
not sure. 
I don’t remember this option giving performance anywhere near file I/O. 

Stack Overflow has a bunch of questions on this topic (the sheer number of 
people complaining about this should be a warning not to put console output in 
the critical path of any application):
https://stackoverflow.com/questions/3857052/why-is-printing-to-stdout-so-slow-can-it-be-sped-up



> On Apr 3, 2018, at 3:32, Matt Sicker <[email protected]> wrote:
> 
> From what I remember, we didn't enable it by default because there's no
> official API docs about if it's supported by non-OpenJDK implementations.
> 
>> On 2 April 2018 at 12:28, Ralph Goers <[email protected]> wrote:
>> 
>> They do it to allow Kubernetes to manage the configuration externally in a
>> generic way. Then it doesn’t matter if it is a Java app, Ruby, Python, C#,
>> etc. They can use the same configuration on every container to do the same
>> thing.
>> 
>> What I am most interested in was the discussion we had some time ago about
>> the performance aspects of writing to stdout. I seem to recall that was the
>> discussion where direct=“true” was being tested and some oddities in
>> performance were found.
>> 
>> Ralph
>> 
>>> On Apr 2, 2018, at 10:09 AM, Chandra <chandra.tungathurthi@rwth-
>> aachen.de> wrote:
>>> 
>>> In general, I believe writing stuff to stdout is a bad idea, even if you
>> are just using it as a `debug` log.  the itchy thing for me is that there’s
>> always another extra “piping” / “redirect” which has to happen for
>> _persisting_ the log data. If you want to do that, why not just write it to
>> a file directly.
>>> 
>>> 
>>> 
>>> Best,
>>> Chandra
>>> 
>>>> On 2 Apr 2018, 10:38 PM +0530, Matt Sicker <[email protected]>, wrote:
>>>> I always set direct="true" on console appenders (it's false by default
>>>> because we added that option later).
>>>> 
>>>>> On 2 April 2018 at 12:05, Gary Gregory <[email protected]> wrote:
>>>>> 
>>>>> I'm sure this is OS dependent as well. I've only seen the obvious: if
>> you
>>>>> log a ton of data, say at the DEBUG level, and enable DEBUG, then yeah,
>>>>> things are going to slow down. Obvious.
>>>>> 
>>>>> The complain I usually hear is that our server logs too much DEBUG
>> data,
>>>>> and that users do not know which log category to disable to alleviate
>> this
>>>>> issue. But that is not a Log4j issue.
>>>>> 
>>>>> Gary
>>>>> 
>>>>> On Mon, Apr 2, 2018 at 10:29 AM, Ralph Goers <
>> [email protected]
>>>>> wrote:
>>>>> 
>>>>>> Some of my team members at work are looking to move some services into
>>>>>> Docker containers managed by Kubernetes following the guidance at
>>>>>> https://12factor.net/logs <https://12factor.net/logs>.
>>>>>> 
>>>>>> We have guidance that shows writing to the console is terrible and I
>>>>>> remember having a discussion that writing to stdout is bad even if it
>> is
>>>>>> redirected to a file, but I can’t seem to find a link to that.
>>>>>> 
>>>>>> Do any of you have experience with this? My gut instinct is telling me
>>>>>> that what they are trying to do is a horrible idea.
>>>>>> 
>>>>>> Ralph
>>>>> 
>>>> 
>>>> 
>>>> 
>>>> --
>>>> Matt Sicker <[email protected]
>> 
>> 
>> 
> 
> 
> -- 
> Matt Sicker <[email protected]>

Reply via email to