From 927a760942846eed49658147adbe62a9427b449a Mon Sep 17 00:00:00 2001 From: ganeshvanahalli Date: Mon, 16 Oct 2023 15:43:49 -0500 Subject: [PATCH 1/6] =?UTF-8?q?Add=20metrics=20to=20time=20each=20part=20o?= =?UTF-8?q?f=20WSBroadcastServer=E2=80=99s=20StartWithHeader?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wsbroadcastserver/wsbroadcastserver.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/wsbroadcastserver/wsbroadcastserver.go b/wsbroadcastserver/wsbroadcastserver.go index cd277387a0..f3e693d5d8 100644 --- a/wsbroadcastserver/wsbroadcastserver.go +++ b/wsbroadcastserver/wsbroadcastserver.go @@ -23,6 +23,7 @@ import ( flag "github.com/spf13/pflag" "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/metrics" "github.com/offchainlabs/nitro/arbutil" ) @@ -32,6 +33,8 @@ var ( HTTPHeaderFeedClientVersion = textproto.CanonicalMIMEHeaderKey("Arbitrum-Feed-Client-Version") HTTPHeaderRequestedSequenceNumber = textproto.CanonicalMIMEHeaderKey("Arbitrum-Requested-Sequence-Number") HTTPHeaderChainId = textproto.CanonicalMIMEHeaderKey("Arbitrum-Chain-Id") + UpgradeToWSTimer = metrics.NewRegisteredTimer("arb/wsbroadcastserver/wsupgrade/duration", nil) + StartWithHeaderTimer = metrics.NewRegisteredTimer("arb/wsbroadcastserver/startwithheader/duration", nil) ) const ( @@ -205,6 +208,7 @@ func (s *WSBroadcastServer) Start(ctx context.Context) error { } func (s *WSBroadcastServer) StartWithHeader(ctx context.Context, header ws.HandshakeHeader) error { + startTimeMain := time.Now() s.startMutex.Lock() defer s.startMutex.Unlock() if s.started { @@ -316,7 +320,10 @@ func (s *WSBroadcastServer) StartWithHeader(ctx context.Context, header ws.Hands } // Zero-copy upgrade to WebSocket connection. + startTime := time.Now() _, err = upgrader.Upgrade(conn) + elapsed := time.Since(startTime) + UpgradeToWSTimer.Update(elapsed) if err != nil { if err.Error() != "" { @@ -483,6 +490,9 @@ func (s *WSBroadcastServer) StartWithHeader(ctx context.Context, header ws.Hands s.started = true + elapsedMain := time.Since(startTimeMain) + StartWithHeaderTimer.Update(elapsedMain) + return nil } From b49e10369bae00f3b3ef8946355edf2e03fb1209 Mon Sep 17 00:00:00 2001 From: ganeshvanahalli Date: Mon, 16 Oct 2023 15:52:27 -0500 Subject: [PATCH 2/6] refactor --- wsbroadcastserver/wsbroadcastserver.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/wsbroadcastserver/wsbroadcastserver.go b/wsbroadcastserver/wsbroadcastserver.go index f3e693d5d8..43ac27593a 100644 --- a/wsbroadcastserver/wsbroadcastserver.go +++ b/wsbroadcastserver/wsbroadcastserver.go @@ -33,8 +33,8 @@ var ( HTTPHeaderFeedClientVersion = textproto.CanonicalMIMEHeaderKey("Arbitrum-Feed-Client-Version") HTTPHeaderRequestedSequenceNumber = textproto.CanonicalMIMEHeaderKey("Arbitrum-Requested-Sequence-Number") HTTPHeaderChainId = textproto.CanonicalMIMEHeaderKey("Arbitrum-Chain-Id") - UpgradeToWSTimer = metrics.NewRegisteredTimer("arb/wsbroadcastserver/wsupgrade/duration", nil) - StartWithHeaderTimer = metrics.NewRegisteredTimer("arb/wsbroadcastserver/startwithheader/duration", nil) + upgradeToWSTimer = metrics.NewRegisteredTimer("arb/wsbroadcastserver/wsupgrade/duration", nil) + startWithHeaderTimer = metrics.NewRegisteredTimer("arb/wsbroadcastserver/startwithheader/duration", nil) ) const ( @@ -323,7 +323,7 @@ func (s *WSBroadcastServer) StartWithHeader(ctx context.Context, header ws.Hands startTime := time.Now() _, err = upgrader.Upgrade(conn) elapsed := time.Since(startTime) - UpgradeToWSTimer.Update(elapsed) + upgradeToWSTimer.Update(elapsed) if err != nil { if err.Error() != "" { @@ -491,7 +491,7 @@ func (s *WSBroadcastServer) StartWithHeader(ctx context.Context, header ws.Hands s.started = true elapsedMain := time.Since(startTimeMain) - StartWithHeaderTimer.Update(elapsedMain) + startWithHeaderTimer.Update(elapsedMain) return nil } From a430014a20e58db025d8612b0e324fcab1fe936e Mon Sep 17 00:00:00 2001 From: ganeshvanahalli Date: Tue, 24 Oct 2023 18:00:46 -0500 Subject: [PATCH 3/6] code refactor --- wsbroadcastserver/wsbroadcastserver.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wsbroadcastserver/wsbroadcastserver.go b/wsbroadcastserver/wsbroadcastserver.go index 43ac27593a..9a7037a713 100644 --- a/wsbroadcastserver/wsbroadcastserver.go +++ b/wsbroadcastserver/wsbroadcastserver.go @@ -33,8 +33,8 @@ var ( HTTPHeaderFeedClientVersion = textproto.CanonicalMIMEHeaderKey("Arbitrum-Feed-Client-Version") HTTPHeaderRequestedSequenceNumber = textproto.CanonicalMIMEHeaderKey("Arbitrum-Requested-Sequence-Number") HTTPHeaderChainId = textproto.CanonicalMIMEHeaderKey("Arbitrum-Chain-Id") - upgradeToWSTimer = metrics.NewRegisteredTimer("arb/wsbroadcastserver/wsupgrade/duration", nil) - startWithHeaderTimer = metrics.NewRegisteredTimer("arb/wsbroadcastserver/startwithheader/duration", nil) + upgradeToWSTimer = metrics.NewRegisteredTimer("arb/feed/clients/wsupgrade/duration", nil) + startWithHeaderTimer = metrics.NewRegisteredTimer("arb/feed/clients/start/duration", nil) ) const ( From 0e9445dbf9ea1efe29408fef7f1d5be5b85362e6 Mon Sep 17 00:00:00 2001 From: Ganesh Vanahalli Date: Wed, 25 Oct 2023 09:35:58 -0500 Subject: [PATCH 4/6] Update wsbroadcastserver/wsbroadcastserver.go Co-authored-by: Joshua Colvin --- wsbroadcastserver/wsbroadcastserver.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wsbroadcastserver/wsbroadcastserver.go b/wsbroadcastserver/wsbroadcastserver.go index 9a7037a713..fed5489636 100644 --- a/wsbroadcastserver/wsbroadcastserver.go +++ b/wsbroadcastserver/wsbroadcastserver.go @@ -33,7 +33,7 @@ var ( HTTPHeaderFeedClientVersion = textproto.CanonicalMIMEHeaderKey("Arbitrum-Feed-Client-Version") HTTPHeaderRequestedSequenceNumber = textproto.CanonicalMIMEHeaderKey("Arbitrum-Requested-Sequence-Number") HTTPHeaderChainId = textproto.CanonicalMIMEHeaderKey("Arbitrum-Chain-Id") - upgradeToWSTimer = metrics.NewRegisteredTimer("arb/feed/clients/wsupgrade/duration", nil) + upgradeToWSTimer = metrics.NewRegisteredTimer("arb/feed/clients/upgrade/duration", nil) startWithHeaderTimer = metrics.NewRegisteredTimer("arb/feed/clients/start/duration", nil) ) From 70df6d6a225cf0b88d5178971c5c55cb56a4ef84 Mon Sep 17 00:00:00 2001 From: ganeshvanahalli Date: Wed, 25 Oct 2023 09:57:01 -0500 Subject: [PATCH 5/6] code refactor --- wsbroadcastserver/wsbroadcastserver.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/wsbroadcastserver/wsbroadcastserver.go b/wsbroadcastserver/wsbroadcastserver.go index fed5489636..c26a910144 100644 --- a/wsbroadcastserver/wsbroadcastserver.go +++ b/wsbroadcastserver/wsbroadcastserver.go @@ -204,11 +204,18 @@ func (s *WSBroadcastServer) Start(ctx context.Context) error { HTTPHeaderChainId: []string{strconv.FormatUint(s.chainId, 10)}, }) - return s.StartWithHeader(ctx, header) + startTime := time.Now() + err := s.StartWithHeader(ctx, header) + elapsed := time.Since(startTime) + startWithHeaderTimer.Update(elapsed) + + if err != nil { + return err + } + return nil } func (s *WSBroadcastServer) StartWithHeader(ctx context.Context, header ws.HandshakeHeader) error { - startTimeMain := time.Now() s.startMutex.Lock() defer s.startMutex.Unlock() if s.started { @@ -490,9 +497,6 @@ func (s *WSBroadcastServer) StartWithHeader(ctx context.Context, header ws.Hands s.started = true - elapsedMain := time.Since(startTimeMain) - startWithHeaderTimer.Update(elapsedMain) - return nil } From e88f53e12a99e8c8ef553945779f10d0f3e56ba6 Mon Sep 17 00:00:00 2001 From: Ganesh Vanahalli Date: Thu, 26 Oct 2023 09:40:19 -0500 Subject: [PATCH 6/6] Update wsbroadcastserver.go --- wsbroadcastserver/wsbroadcastserver.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/wsbroadcastserver/wsbroadcastserver.go b/wsbroadcastserver/wsbroadcastserver.go index c26a910144..d51b368400 100644 --- a/wsbroadcastserver/wsbroadcastserver.go +++ b/wsbroadcastserver/wsbroadcastserver.go @@ -208,11 +208,7 @@ func (s *WSBroadcastServer) Start(ctx context.Context) error { err := s.StartWithHeader(ctx, header) elapsed := time.Since(startTime) startWithHeaderTimer.Update(elapsed) - - if err != nil { - return err - } - return nil + return err } func (s *WSBroadcastServer) StartWithHeader(ctx context.Context, header ws.HandshakeHeader) error {