Commit cf1b011f authored by Janos Guljas's avatar Janos Guljas

measure compete time, not per message in pingpong rtt

parent e094e221
......@@ -59,6 +59,7 @@ func (s *Service) Protocol() p2p.ProtocolSpec {
}
func (s *Service) Ping(ctx context.Context, address string, msgs ...string) (rtt time.Duration, err error) {
start := time.Now()
stream, err := s.streamer.NewStream(ctx, address, protocolName, streamName, streamVersion)
if err != nil {
return 0, fmt.Errorf("new stream: %w", err)
......@@ -68,7 +69,6 @@ func (s *Service) Ping(ctx context.Context, address string, msgs ...string) (rtt
w, r := protobuf.NewWriterAndReader(stream)
var pong Pong
start := time.Now()
for _, msg := range msgs {
if err := w.WriteMsg(&Ping{
Greeting: msg,
......@@ -87,7 +87,7 @@ func (s *Service) Ping(ctx context.Context, address string, msgs ...string) (rtt
s.logger.Debugf("got pong: %q", pong.Response)
s.metrics.PongReceivedCount.Inc()
}
return time.Since(start) / time.Duration(len(msgs)), nil
return time.Since(start), nil
}
func (s *Service) Handler(peer p2p.Peer, stream p2p.Stream) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment