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

perf: optimize get tso frequency #801

Merged
merged 3 commits into from
Aug 3, 2020

Conversation

liuzix
Copy link
Contributor

@liuzix liuzix commented Jul 28, 2020

What problem does this PR solve?

Querying CurrentVersion too frequently when resolving lock. #790

What is changed and how it works?

CurrentVersion is now cached and is updated regularly by a separate goroutine.

Check List

Tests

  • Manual test (add detailed scripts or steps below)

Code changes

  • Has exported function/method change

Release note

  • No release note

@liuzix liuzix added the component/kv-client TiKV kv log client component. label Jul 28, 2020
cdc/kv/client.go Outdated
@@ -251,6 +252,8 @@ type CDCClient struct {

regionCache *tikv.RegionCache
kvStorage tikv.Storage

currentVersionCache tidbkv.Version
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
currentVersionCache tidbkv.Version
currentVersionCache model.Ts

cdc/kv/client.go Outdated
select {
case <-ctx.Done():
return
case <-ticker.C:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there is no region to resolve lock, we still query the tso from pd every two seconds?

cdc/kv/client.go Outdated
// GetCurrentVersion gets a cached version that is regularly updated by a background goroutine
func (c *CDCClient) GetCurrentVersion() tidbkv.Version {
for atomic.LoadUint64(&c.currentVersionCache.Ver) == 0 {
time.Sleep(1 * time.Second)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not graceful

cdc/kv/client.go Outdated
@@ -286,6 +308,14 @@ func (c *CDCClient) Close() error {
return nil
}

// GetCurrentVersion gets a cached version that is regularly updated by a background goroutine
func (c *CDCClient) GetCurrentVersion() tidbkv.Version {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How many CDCClient would CDC create? How about caching the TS in the processor?

@liuzix liuzix force-pushed the zixiong-tso-optimization branch from fb3f770 to 5c722b0 Compare July 29, 2020 06:23
@liuzix
Copy link
Contributor Author

liuzix commented Jul 29, 2020

/run-all-tests

return tidbkv.Version{Ver: ver}, nil
}

func (s *kvStorageWithVersionCache) Close() error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the Close called

@@ -15,6 +15,7 @@ package puller

import (
"context"
"github.com/pingcap/ticdc/pkg/notify"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this import to the group of third-party lib

@@ -69,6 +166,7 @@ func NewPuller(
spans []regionspan.Span,
limitter *BlurResourceLimitter,
) Puller {
kvStorage = newKvStorageWithVersionCache(kvStorage)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

KvStorageWithVersionCache should be globally unique, not one per puller.

@liuzix
Copy link
Contributor Author

liuzix commented Jul 30, 2020

/run-all-tests

2 similar comments
@liuzix
Copy link
Contributor Author

liuzix commented Jul 30, 2020

/run-all-tests

@liuzix
Copy link
Contributor Author

liuzix commented Jul 30, 2020

/run-all-tests

@liuzix liuzix changed the title perf: optimize get tso frequency WIP perf: optimize get tso frequency Jul 31, 2020
@amyangfei amyangfei added this to the v4.0.5 milestone Aug 3, 2020
@liuzix liuzix force-pushed the zixiong-tso-optimization branch from ccdae04 to c1dc174 Compare August 3, 2020 06:10
@liuzix
Copy link
Contributor Author

liuzix commented Aug 3, 2020

/run-all-tests

@codecov-commenter
Copy link

codecov-commenter commented Aug 3, 2020

Codecov Report

Merging #801 into master will not change coverage.
The diff coverage is n/a.

@@             Coverage Diff             @@
##             master       #801   +/-   ##
===========================================
  Coverage   32.4447%   32.4447%           
===========================================
  Files            96         96           
  Lines         10541      10541           
===========================================
  Hits           3420       3420           
  Misses         6780       6780           
  Partials        341        341           

@liuzix liuzix changed the title WIP perf: optimize get tso frequency perf: optimize get tso frequency Aug 3, 2020
@liuzix
Copy link
Contributor Author

liuzix commented Aug 3, 2020

/run-all-tests

1 similar comment
@liuzix
Copy link
Contributor Author

liuzix commented Aug 3, 2020

/run-all-tests

Copy link
Contributor

@amyangfei amyangfei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@ti-srebot ti-srebot added the status/LGT1 Indicates that a PR has LGTM 1. label Aug 3, 2020
@ti-srebot ti-srebot removed the status/LGT1 Indicates that a PR has LGTM 1. label Aug 3, 2020
@ti-srebot ti-srebot added the status/LGT2 Indicates that a PR has LGTM 2. label Aug 3, 2020
@zier-one
Copy link
Contributor

zier-one commented Aug 3, 2020

/merge

@ti-srebot ti-srebot added the status/can-merge Indicates a PR has been approved by a committer. label Aug 3, 2020
@ti-srebot
Copy link
Contributor

/run-all-tests

@ti-srebot ti-srebot merged commit 0749793 into pingcap:master Aug 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/kv-client TiKV kv log client component. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants