server: improve the addMetrics method performance#12454
Merged
lonng merged 5 commits intopingcap:masterfrom Sep 29, 2019
lonng:simplify-metrics
Merged
server: improve the addMetrics method performance#12454lonng merged 5 commits intopingcap:masterfrom lonng:simplify-metrics
lonng merged 5 commits intopingcap:masterfrom
lonng:simplify-metrics
Conversation
Signed-off-by: Lonng <heng@lonng.org>
Contributor
Author
|
/bench |
Member
|
Do you have bench results? |
lysu
reviewed
Sep 28, 2019
server/conn.go
Outdated
| case metrics.LblGeneral: | ||
| queryDurationHistogramGeneral.Observe(time.Since(startTime).Seconds()) | ||
| default: | ||
| observer, found := queryDurationHistogram[sqlType] |
Contributor
There was a problem hiding this comment.
how about refactor sqlType to be int first, then here also can use array :D
Signed-off-by: Lonng <heng@lonng.org>
Contributor
Author
|
@ngaut
See snippet: https://gist.github.com/lonng/339c17800a20fe48998d552d9ee1d535 So I have reverted the hashmap part. |
Member
|
/bench |
|
/run-all-tests |
Codecov Report
@@ Coverage Diff @@
## master #12454 +/- ##
===========================================
Coverage 79.8785% 79.8785%
===========================================
Files 462 462
Lines 102622 102622
===========================================
Hits 81973 81973
Misses 14752 14752
Partials 5897 5897 |
Contributor
Author
Contributor
Author
|
/run-all-tests |
Contributor
|
LGTM |
lysu
approved these changes
Sep 29, 2019
Contributor
|
/run-all-tests |
Contributor
|
@lonng merge failed. |
Contributor
Author
|
/run-unit-test |
lonng
added a commit
that referenced
this pull request
Sep 30, 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Signed-off-by: Lonng heng@lonng.org
What problem does this PR solve?
addMetricsmethod is a hot path in TiDB and will be executed in every query. It usesswitch .. caseto find theCounterand add metrics to monitor system. It's not an efficient way.See: https://godbolt.org/z/czr__4
What is changed and how it works?
This PR makes the following change.
Counterbycmd(index).Observerfrom map is fast thanswitch .. casein common case.Check List
Tests
Release note