Skip to content
This repository has been archived by the owner on Mar 11, 2020. It is now read-only.

Commit

Permalink
Merge pull request #108 from sbuzzard/perf_changes_flush
Browse files Browse the repository at this point in the history
Performance improvement, moving write and flush out of enframed and i…
  • Loading branch information
timperrett committed May 31, 2016
2 parents 813733b + cfd262b commit 5cccaaf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion core/src/main/scala/transport/netty/Client.scala
Expand Up @@ -70,7 +70,7 @@ object NettyTransport {
})
}

def write(c: Channel)(frame: Framed): Task[Unit] = evalCF(c.write(frame))
def write(c: Channel)(frame: Framed): Task[Unit] = evalCF(c.writeAndFlush(frame))

def single(host: InetSocketAddress,
expectedSigs: Set[Signature] = Set.empty,
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/scala/transport/netty/Transport.scala
Expand Up @@ -126,7 +126,7 @@ class Deframe extends ByteToMessageDecoder {
} else {
remaining = Some(rem)
}
}
}
case Some(rem) =>
// we are waiting for at least rem more bytes, as that is what
// is outstanding in the current frame
Expand Down Expand Up @@ -177,9 +177,9 @@ object Enframe extends ChannelOutboundHandlerAdapter {
obj match {
case Bits(bv) =>
val byv = bv.toByteVector
val _ = ctx.writeAndFlush(Unpooled.wrappedBuffer((codecs.int32.encode(byv.size).require ++ bv).toByteBuffer), cp)
val _ = ctx.write(Unpooled.wrappedBuffer((codecs.int32.encode(byv.size).require ++ bv).toByteBuffer), cp)
case EOS =>
val _ = ctx.writeAndFlush(Unpooled.wrappedBuffer(codecs.int32.encode(0).require.toByteBuffer), cp)
val _ = ctx.write(Unpooled.wrappedBuffer(codecs.int32.encode(0).require.toByteBuffer), cp)
case x => throw new IllegalArgumentException("was expecting Framed, got: " + x)
}
}
Expand Down

7 comments on commit 5cccaaf

@ahjohannessen
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sbuzzard @timperrett seems like this change causes DescribeSpec to hang for some reason.

@ahjohannessen
Copy link
Contributor

@ahjohannessen ahjohannessen commented on 5cccaaf May 31, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If changes in Transport.scala are reverted, then DescribeSpec works again. In general, as far as I can tell, is that you flush at the end of sending a request or a response, unless you are about to close the channel. I am not that well versed with Netty and such to tell what is the right thing to do here.

@sbuzzard
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flushing at the end of the request was causing a ~1 second lag in requests (we went from a suite of 150 tests taking nearly 3 minutes to under 9 seconds and integration tests likewise). It could well have been a 4.0.x bug that is fixed in 4.1 - I'll try reverting that with 4.1 and trying with our test suite again.

@ahjohannessen
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be of some inspiration: http://normanmaurer.me/presentations/2014-facebook-eng-netty/slides.html#1.0 :)

@sbuzzard Seems like there are many things to consider with respect to enqueuing and writing judging from those slides. Could you also just try the change with Client.scala and keep transport as before?

@sbuzzard
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works fine now with Transport reverted so I'll rebase. I think the issue, in hindsight, was that netty 4.0.x (at least to the version being used in remotely) didn't have TCP_NODELAY set to true by default. I was reading through the issues the other week when I came across that thread. Thxs for the link, @ahjohannessen!

@sbuzzard
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works fine with Transport reverted - but still slow as it use to be with client also reverted.

@ahjohannessen
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sbuzzard we should keep client change, IMHO :)

Please sign in to comment.