Answer the question
In order to leave comments, you need to log in
How to calculate real response time in Netty 4?
There is an HTTP server on Netty 4, the question is how to measure the time from the moment the request came to the server and the response was sent. If measured inside SimpleChannelInboundHandler, there is no sense, since the time there is the time the handler is running. Or is it possible to somehow get the size of the queue of processed requests.
Answer the question
In order to leave comments, you need to log in
new ServerBootstrap().group(group)
.channel(NioServerSocketChannel.class)
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel socketChannel) {
final long startTime = System.currentTimeMillis();
ChannelPipeline pipeline = socketChannel.pipeline();
pipeline.addLast(new ChannelOutboundHandlerAdapter() {
@Override
public void read(ChannelHandlerContext ctx) {
ctx.writeAndFlush(Unpooled.wrappedBuffer("Hello!".getBytes()));
.addListener(ChannelFutureListener.CLOSE);
}
});
ChannelFuture f = socketChannel.closeFuture();
f.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
System.out.println(System.currentTimeMillis() - startTime);
}
});
}
})
.bind("localhost", 1025)
.sync()
.channel()
.closeFuture()
.syncUninterruptibly();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question