From 3e862fd467c7d38d41ea04620909dbc8d516d031 Mon Sep 17 00:00:00 2001 From: Hein Meling Date: Tue, 13 Feb 2024 18:19:12 +0100 Subject: [PATCH] feat: added latency recording per node This needs to have some tests; maybe using localhost with some extra delays imposed. --- channel.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/channel.go b/channel.go index 8d884737..c8f6b56d 100644 --- a/channel.go +++ b/channel.go @@ -30,6 +30,7 @@ type response struct { type responseRouter struct { c chan<- response + ts time.Time streaming bool } @@ -81,6 +82,7 @@ func (c *channel) routeResponse(msgID uint64, resp response) { c.responseMut.Lock() defer c.responseMut.Unlock() if router, ok := c.responseRouters[msgID]; ok { + c.latency = time.Since(router.ts) router.c <- resp // delete the router if we are only expecting a single message if !router.streaming { @@ -92,7 +94,7 @@ func (c *channel) routeResponse(msgID uint64, resp response) { func (c *channel) enqueue(req request, responseChan chan<- response, streaming bool) { if responseChan != nil { c.responseMut.Lock() - c.responseRouters[req.msg.Metadata.MessageID] = responseRouter{responseChan, streaming} + c.responseRouters[req.msg.Metadata.MessageID] = responseRouter{responseChan, time.Now(), streaming} c.responseMut.Unlock() } c.sendQ <- req