logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Remko Popma (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LOG4J2-1343) Update ConsoleAppender to utilize gc-free Layout method
Date Fri, 01 Apr 2016 10:04:25 GMT

    [ https://issues.apache.org/jira/browse/LOG4J2-1343?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15221488#comment-15221488
] 

Remko Popma commented on LOG4J2-1343:
-------------------------------------

Note to self on how to approach this (draft):

AbstractOutputStreamAppender
{code}
public void append(final LogEvent event) {
    if (Constants.ENABLE_THREADLOCALS) {
        final ByteBufferDestination destination = manager.getByteBufferDestination();
        getLayout().encode(event, destination);
        if (this.immediateFlush || event.isEndOfBatch()) {
            destination.drain(destination.getByteBuffer()); // write buffer to outputStream
            manager.flush();
        }
        return;
    }
...// rest is same as before
{code}

OutputStreamManager
{code}
public class OutputStreamManager extends AbstractManager {

    private static final int DEFAULT_BUFFER_SIZE = 4 * 1024;

    private class ByteBufferDestinationAdapter implements ByteBufferDestination {
        private ByteBuffer buffer;

        @Override
        public ByteBuffer getByteBuffer() {
            if (buffer == null) {
                buffer = createByteBuffer();
            }
            return buffer;
        }

        @Override
        public ByteBuffer drain(final ByteBuffer buf) {
            buf.flip();
            write(buf.array(), 0, buf.limit(), false);
            buf.clear();
            return buf;
        }
    }

    protected final Layout<?> layout;
    private volatile OutputStream os;
    private final ByteBufferDestination byteBufferDestination = new ByteBufferDestinationAdapter();

    protected ByteBufferDestination getByteBufferDestination() {
        return  byteBufferDestination;
    }

    // subclasses can override for different buffer size
    protected ByteBuffer createByteBuffer() {
        return ByteBuffer.wrap(new byte[DEFAULT_BUFFER_SIZE]);
    }
... // rest is same as before
{code}



> Update ConsoleAppender to utilize gc-free Layout method
> -------------------------------------------------------
>
>                 Key: LOG4J2-1343
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1343
>             Project: Log4j 2
>          Issue Type: Improvement
>          Components: Appenders
>    Affects Versions: 2.5
>            Reporter: Remko Popma
>
> TBD: would we want to include this in the upcoming 2.6 release?



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message