Skip to content

Commit

Permalink
[netty#2362] AbstractChannel.AbstractUnsafe.write(...) is slow
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Norman Maurer committed Apr 4, 2014
1 parent 2fa79b2 commit fdb1db9
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions transport/src/main/java/io/netty/channel/AbstractChannel.java
Original file line number Diff line number Diff line change
Expand Up @@ -653,18 +653,18 @@ public void run() {

@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
Expand Down

0 comments on commit fdb1db9

Please sign in to comment.