Skip to content

Commit

Permalink
Add metrics to time each part of WSBroadcastServer’s StartWithHeader
Browse files Browse the repository at this point in the history
  • Loading branch information
ganeshvanahalli committed Oct 16, 2023
1 parent 0e57df7 commit 927a760
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions wsbroadcastserver/wsbroadcastserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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 (
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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() != "" {
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 927a760

Please sign in to comment.