Change threshold

This commit is contained in:
Xiaoguang Sun 2022-01-16 23:00:41 +08:00
parent d2f5f4a238
commit 6b360b980c
1 changed files with 8 additions and 5 deletions

View File

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