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

may use Counter instead of Histogram for Packet IO metrics #32075

Closed
siddontang opened this issue Jan 30, 2022 · 3 comments · Fixed by #35514
Closed

may use Counter instead of Histogram for Packet IO metrics #32075

siddontang opened this issue Jan 30, 2022 · 3 comments · Fixed by #35514
Assignees
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. type/enhancement The issue or PR belongs to an enhancement. type/performance

Comments

@siddontang
Copy link
Member

Enhancement

I found that we use Histogram to track the packet IO, see https://github.com/pingcap/tidb/blob/master/server/packetio.go#L52

But is it necessary to use Histogram here? In the Grafana, We have a Client Traffic Panel, see below, but in the panel, we can see that here we use histogram sum, and we can use a counter instead.

image

Counter is much faster than Histogram, I wrote a very simple benchmark here:

func BenchmarkPromHistogram(b *testing.B) {
	r := PacketIOHistogram.WithLabelValues("read")
	for i := 0; i < b.N; i++ {
		r.Observe(10)
	}
}

func BenchmarkPromCounter(b *testing.B) {
	r := QueryTotalCounter.WithLabelValues("read", "write")
	for i := 0; i < b.N; i++ {
		r.Add(10)
	}
}
cpu: Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz
BenchmarkPromHistogram-8   	19636056	        60.26 ns/op
BenchmarkPromCounter-8     	95965551	        10.68 ns/op
@siddontang siddontang added type/enhancement The issue or PR belongs to an enhancement. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. type/performance labels Jan 30, 2022
@siddontang
Copy link
Member Author

If we decide to advance this, I think we should list all the histogram metrics and check whether we need to use Counter instead.

@bb7133
Copy link
Member

bb7133 commented Feb 7, 2022

Checked the current metrics by:

  • The calls of prometheus.NewHistogram() / prometheus.NewHistogramVec()
  • The use of {histogram_metrics}_sum / {histogram_metrics}_count

One another metric that can be improved is DistSQLCoprCacheHistogram:

DistSQLCoprCacheHistogram = prometheus.NewHistogramVec(

"expr": "sum(rate(tidb_distsql_copr_cache_sum{tidb_cluster=\"$tidb_cluster\"}[1m])) by (type)",

It was introduced as a histogram metric in #19979 but after #26338 and #30712(IMO the change is reasonable), it using a counter is enough.

@AricSu
Copy link
Contributor

AricSu commented Jun 20, 2022

/assign

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. type/enhancement The issue or PR belongs to an enhancement. type/performance
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants