diff --git a/src/main/java/io/netty/channel/socket/nio/NioSocketChannel.java b/src/main/java/io/netty/channel/socket/nio/NioSocketChannel.java index a7343419b8..f00046de54 100644 --- a/src/main/java/io/netty/channel/socket/nio/NioSocketChannel.java +++ b/src/main/java/io/netty/channel/socket/nio/NioSocketChannel.java @@ -56,7 +56,7 @@ import sun.nio.ch.ChannelPerf; /** {@link io.netty.channel.socket.SocketChannel} which uses NIO selector based implementation. */ public class NioSocketChannel extends AbstractNioByteChannel implements io.netty.channel.socket.SocketChannel { - private static final double SLOW_IO_THRESHOLD = 0.01; + private static final long SLOW_IO_THRESHOLD = 10_000_000; public static final Histogram socketWriteDuration = HistogramUtils.buildDuration() .name("netty_nio_socket_channel_write_duration_seconds") @@ -392,11 +392,12 @@ public class NioSocketChannel extends AbstractNioByteChannel final RecvByteBufAllocator.Handle allocHandle = unsafe().recvBufAllocHandle(); int attemptedBytes = byteBuf.writableBytes(); allocHandle.attemptedBytesRead(attemptedBytes); - Histogram.Timer socketReadTime = socketReadDuration.startTimer(); SocketChannel sc = javaChannel(); + Histogram.Timer socketReadTime = socketReadDuration.startTimer(); + long start = System.nanoTime(); int localReadBytes = byteBuf.writeBytes(sc, allocHandle.attemptedBytesRead()); double duration = socketReadTime.observeDuration(); - if (duration > SLOW_IO_THRESHOLD) { + if (System.nanoTime() - start >= SLOW_IO_THRESHOLD) { // read slower than 10ms is strange System.out.println( "[slow io] read " @@ -478,9 +479,10 @@ public class NioSocketChannel extends AbstractNioByteChannel int attemptedBytes = buffer.remaining(); socketWriteBytes.observe(attemptedBytes); Histogram.Timer writeTime = socketWriteDuration.startTimer(); + long start = System.nanoTime(); final int localWrittenBytes = ch.write(buffer); double duration = writeTime.observeDuration(); - if (duration > SLOW_IO_THRESHOLD) { + if (System.nanoTime() - start >= SLOW_IO_THRESHOLD) { // read slower than 10ms is strange System.out.println( "[slow io] write " @@ -516,9 +518,10 @@ public class NioSocketChannel extends AbstractNioByteChannel long attemptedBytes = in.nioBufferSize(); socketWriteBytes.observe(attemptedBytes); Histogram.Timer writeTime = socketWriteDuration.startTimer(); + long start = System.nanoTime(); final long localWrittenBytes = ch.write(nioBuffers, 0, nioBufferCnt); double duration = writeTime.observeDuration(); - if (duration > SLOW_IO_THRESHOLD) { + if (System.nanoTime() - start >= SLOW_IO_THRESHOLD) { // read slower than 10ms is strange System.out.println( "[slow io] write "