如何衡量Netty 4.1需要发送一些数据的时间?
我有一个工作负载,在我的控制下都有一个服务器和客户端。他们使用Netty 4.1通过TCP连接进行通信。状态图看起来像这样:
Server Client
params = f();
-->
res = compute(params);
<--
store(res);
我想测量他们通过网络交流的时间。这意味着我希望总运行时减去F,Compute和Res的运行时间。但是,实际上它更加复杂,因此我无法可靠地衡量程序的所有其他部分。
我可以衡量Netty转移的时间吗?如果是,怎么回事?
I have a workload where I have a server and a client, both under my control. They communicate via a TCP connection using Netty 4.1. The state diagram looks like this:
Server Client
params = f();
-->
res = compute(params);
<--
store(res);
I want to measure the time they spend communicating via the network. This means I want the total runtime minus the runtimes of f, compute and res. But, in reality it's more complicated, so I can't measure all the other parts of my program reliably.
Can I measure the time netty takes for the transfer? If yes, how so?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我让您正确,您想测量网络延迟。如果是这样,您可以从客户端发送时间戳,在服务器上接收它并将其发送回客户端。收到后,您可以像
now() - 接收到的延迟,在客户端接收到Timestamp
。我想您在应用程序数据包中使用了一些POJO,因此您可以添加一种
litencyMeasure
System Packet,它将容纳long Timestamp
(您可以使用获得
System.CurrentTimeMillis()
或使用Guava的stopwatch
)。在客户端接收时,您可以这样做:long Latency = System.CurrentTimeMillis()-LatencyPacket.getTimestamp()
。If I got you right you want to measure a network latency. If so, you could send timestamp from the client, receive it on the server and send back to the client. Once received, you could calculate the latency like
now() - receivedTimestamp
on the client side.I suppose that you use some POJO for the application data packets, so you can add kind of
LatencyMeasure
system packet which will holdslong timestamp
(which you could get withSystem.currentTimeMillis()
or with some library like Guava'sStopwatch
). And on client receive you can do smth like this:long latency = System.currentTimeMillis() - latencyPacket.getTimestamp()
.