Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metrics,server: add a get_token_duration_seconds metrics #7110

Merged
merged 8 commits into from
Jul 23, 2018
Merged
10 changes: 10 additions & 0 deletions metrics/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ var (
Help: "Counter of hand shake error.",
},
)

GetTokenDurationHistogram = prometheus.NewHistogram(
prometheus.HistogramOpts{
Namespace: "tidb",
Subsystem: "server",
Name: "get_token_duration_seconds",
Help: "Duration (us) for getting token, it should be small until concurrency limit is reached.",
Buckets: prometheus.ExponentialBuckets(1, 2, 22), // 1us ~ 2s
})
)

func init() {
Expand All @@ -124,6 +133,7 @@ func init() {
prometheus.MustRegister(KeepAliveCounter)
prometheus.MustRegister(PlanCacheCounter)
prometheus.MustRegister(HandShakeErrorCounter)
prometheus.MustRegister(GetTokenDurationHistogram)
}

// ExecuteErrorToLabel converts an execute error to label.
Expand Down
6 changes: 5 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ func (s *Server) ConnectionCount() int {
}

func (s *Server) getToken() *Token {
return s.concurrentLimiter.Get()
start := time.Now()
tok := s.concurrentLimiter.Get()
// Note that data smaller than one microsecond is ignored, because that case can be viewed as non-block.
metrics.GetTokenDurationHistogram.Observe(float64(time.Since(start).Nanoseconds() / 1e3))
return tok
}

func (s *Server) releaseToken(token *Token) {
Expand Down