mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 23:26:44 +00:00
rpc: lazily instantiate rpcServingTimer to prevent spinning up go-routine upon rpc package import
This commit is contained in:
parent
aac621987e
commit
5e511283cb
2 changed files with 5 additions and 2 deletions
|
|
@ -523,7 +523,7 @@ func (h *handler) handleCall(cp *callProc, msg *jsonrpcMessage) *jsonrpcMessage
|
|||
} else {
|
||||
successfulRequestGauge.Inc(1)
|
||||
}
|
||||
rpcServingTimer.UpdateSince(start)
|
||||
rpcServingTimer().UpdateSince(start)
|
||||
updateServeTimeHistogram(msg.Method, answer.Error == nil, time.Since(start))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package rpc
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/metrics"
|
||||
|
|
@ -31,7 +32,9 @@ var (
|
|||
// serveTimeHistName is the prefix of the per-request serving time histograms.
|
||||
serveTimeHistName = "rpc/duration"
|
||||
|
||||
rpcServingTimer = metrics.NewRegisteredTimer("rpc/duration/all", nil)
|
||||
rpcServingTimer = sync.OnceValue(func() *metrics.Timer {
|
||||
return metrics.NewRegisteredTimer("rpc/duration/all", nil)
|
||||
})
|
||||
)
|
||||
|
||||
// updateServeTimeHistogram tracks the serving time of a remote RPC call.
|
||||
|
|
|
|||
Loading…
Reference in a new issue