[#2362] AbstractChannel.AbstractUnsafe.write(...) is slow

Motivation:
At the moment we do a Channel.isActive() check in every AbstractChannel.AbstractUnsafe.write(...) call which gives quite some overhead as shown in the profiler when you write fast enough. We can eliminate the check and do something more smart here.

Modifications:
Remove the isActive() check and just check if the ChannelOutboundBuffer was set to null before, which means the Channel was closed. The rest will be handled in flush0() anyway.

Result:
Less overhead when doing many write calls
This commit is contained in:
Norman Maurer 2014-04-04 09:45:03 +02:00
parent 2fa79b2d5d
commit fdb1db90c4

View File

@ -653,18 +653,18 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
@Override
public void write(Object msg, ChannelPromise promise) {
if (!isActive()) {
// Mark the write request as failure if the channel is inactive.
if (isOpen()) {
safeSetFailure(promise, NOT_YET_CONNECTED_EXCEPTION);
} else {
safeSetFailure(promise, CLOSED_CHANNEL_EXCEPTION);
}
ChannelOutboundBuffer outboundBuffer = this.outboundBuffer;
if (outboundBuffer == null) {
// If the outboundBuffer is null we know the channel was closed and so
// need to fail the future right away. If it is not null the handling of the rest
// will be done in flush0()
// See https://github.com/netty/netty/issues/2362
safeSetFailure(promise, CLOSED_CHANNEL_EXCEPTION);
// release message now to prevent resource-leak
ReferenceCountUtil.release(msg);
} else {
outboundBuffer.addMessage(msg, promise);
return;
}
outboundBuffer.addMessage(msg, promise);
}
@Override