Browse files

ChannelStatsHandler: count requested writes, not complete ones.

  • Loading branch information...
1 parent d3f0050 commit 5874ce12785cbeb2e9b0a8b1e31ac651705b10a9 @mariusae mariusae committed Mar 21, 2011
Showing with 14 additions and 8 deletions.
  1. +14 −8 finagle-core/src/main/scala/com/twitter/finagle/channel/ChannelStatsHandler.scala
View
22 finagle-core/src/main/scala/com/twitter/finagle/channel/ChannelStatsHandler.scala
@@ -6,10 +6,9 @@ package com.twitter.finagle.channel
*/
import java.util.concurrent.atomic.{AtomicInteger, AtomicLong}
+import java.util.logging.Logger
-import org.jboss.netty.channel.{
- SimpleChannelHandler, ChannelHandlerContext,
- WriteCompletionEvent, MessageEvent}
+import org.jboss.netty.channel.{SimpleChannelHandler, ChannelHandlerContext, MessageEvent}
import org.jboss.netty.buffer.ChannelBuffer
import com.twitter.util.{Time, Future}
@@ -19,6 +18,8 @@ class ChannelStatsHandler(statsReceiver: StatsReceiver)
extends SimpleChannelHandler
with ConnectionLifecycleHandler
{
+ private[this] val log = Logger.getLogger(getClass.getName)
+
private[this] val connects = statsReceiver.counter("connects")
private[this] val connectionDuration = statsReceiver.stat("connection_duration")
private[this] val connectionReceivedBytes = statsReceiver.stat("connection_received_bytes")
@@ -48,12 +49,17 @@ class ChannelStatsHandler(statsReceiver: StatsReceiver)
}
}
- override def writeComplete(ctx: ChannelHandlerContext, e: WriteCompletionEvent) {
+ override def writeRequested(ctx: ChannelHandlerContext, e: MessageEvent) {
val (_, channelWriteCount) = ctx.getAttachment().asInstanceOf[(AtomicLong, AtomicLong)]
- channelWriteCount.getAndAdd(e.getWrittenAmount())
- writeCount.getAndAdd(e.getWrittenAmount())
- super.writeComplete(ctx, e)
+ e.getMessage match {
+ case buffer: ChannelBuffer =>
+ channelWriteCount.getAndAdd(buffer.readableBytes)
+ case _ =>
+ log.warning("ChannelStatsHandler received non-channelbuffer write")
+ }
+
+ super.writeRequested(ctx, e)
}
override def messageReceived(ctx: ChannelHandlerContext, e: MessageEvent) {
@@ -63,7 +69,7 @@ class ChannelStatsHandler(statsReceiver: StatsReceiver)
channelReadCount.getAndAdd(buffer.readableBytes())
readCount.getAndAdd(buffer.readableBytes())
case _ =>
- ()
+ log.warning("ChannelStatsHandler received non-channelbuffer read")
}
super.messageReceived(ctx, e)

0 comments on commit 5874ce1

Please sign in to comment.