le_me
le_me

Reputation: 3419

How can I measure the time netty 4.1 needs to send some data?

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?

Upvotes: 0

Views: 160

Answers (1)

Nikita
Nikita

Reputation: 194

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 holds long timestamp (which you could get with System.currentTimeMillis() or with some library like Guava's Stopwatch). And on client receive you can do smth like this: long latency = System.currentTimeMillis() - latencyPacket.getTimestamp().

Upvotes: 0

Related Questions