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

session, tikv: allocate task IDs for distsql requests #16520

Merged
merged 10 commits into from
May 13, 2020

Conversation

sticnarf
Copy link
Contributor

@sticnarf sticnarf commented Apr 17, 2020

What problem does this PR solve?

Issue Number: close tikv/tikv#7484

Problem Summary:

Currently TiDB provides no information for TiKV that some group of requests belong to the same statement (task). So TiKV's unified read pool uses the start TS of the transaction as the task identifier . It's not suitable in all cases to use start ts as the task id for the unified read pool. For example, in the same transaction, a big query is executed and the following point selects are also downgraded.

What is changed and how it works?

What's Changed:

Currently in this PR, we only set task ids for distsql requests that can be run in transactions. For other distsql requests (like DDL reorg, analyze and checksum), the task id is not provided and TiKV still uses start_ts as task id. And TiKV uses random numbers as the task ids for point gets commands so this PR also does not set task ids for these requests.

Related changes

  • Need to cherry-pick to the release branch

Check List

Tests

  • Unit test

Side effects

Release note

Allocate task IDs for distsql requests to help TiKV schedule them better.

@sticnarf sticnarf requested a review from a team as a code owner April 17, 2020 08:09
@ghost ghost requested review from XuHuaiyu and removed request for a team April 17, 2020 08:09
@github-actions github-actions bot added the sig/execution SIG execution label Apr 17, 2020
@breezewish
Copy link
Member

Should it be called SqlStatementId instead?

Copy link
Member

@breezewish breezewish left a comment

Choose a reason for hiding this comment

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

LGTM

Signed-off-by: Jay Lee <[email protected]>
@codecov
Copy link

codecov bot commented Apr 28, 2020

Codecov Report

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

@@             Coverage Diff             @@
##             master     #16520   +/-   ##
===========================================
  Coverage   80.0905%   80.0905%           
===========================================
  Files           510        510           
  Lines        139597     139597           
===========================================
  Hits         111804     111804           
  Misses        18823      18823           
  Partials       8970       8970           


// AllocateTaskID allocates a new unique ID for a statement execution
func AllocateTaskID() uint64 {
return atomic.AddUint64(&taskIDAlloc, 1)
Copy link
Member

Choose a reason for hiding this comment

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

There is a chance that different tidb-server use the same task ID.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Got it, how about moving this calculation logic into the request sender side?

Copy link
Contributor

Choose a reason for hiding this comment

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

TiDB's logic is too complicated, I'm not sure if start ts exists when task id is assigned.

Copy link
Member

Choose a reason for hiding this comment

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

Can we use the statement idx, starts from 0 as the task id in the transaction?

Copy link
Contributor

Choose a reason for hiding this comment

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

The original author also suggests to use the ID for tracing. I'm not sure if allocating as statement index will affect the purpose.

@@ -38,6 +39,13 @@ const (
WarnLevelNote = "Note"
)

var taskIDAlloc uint64
Copy link
Contributor

Choose a reason for hiding this comment

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

taskIDAlloc is a server-level variable here.
Can we define it as a session-level variable to reduce the contention on it?

@XuHuaiyu
Copy link
Contributor

/bench + sysbench

@XuHuaiyu
Copy link
Contributor

/bench + tpcc

1 similar comment
@XuHuaiyu
Copy link
Contributor

/bench + tpcc

@sre-bot
Copy link
Contributor

sre-bot commented Apr 29, 2020

Benchmark Report

Run TPC-C Performance Test on VMs

@@                               Benchmark Diff                               @@
================================================================================
--- tidb: cd362cae723a1699cb6d3f77ed5b3600ac910c40
+++ tidb: 7aa06145f5eaa760c9e13d8caf0957e5df7caaac
tikv: cdca278ba7c2f631d5b3b5db08f1335dc7a89108
pd: 5a8ccb5b53e0a048146c019bfb48fd99c696cc6c
================================================================================
Measured tpmC (NewOrders): 7111.71 ± 1.41% (std=67.58), delta: 0.31% (p=0.756)

Copy link
Contributor

@XuHuaiyu XuHuaiyu left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@zz-jason zz-jason left a comment

Choose a reason for hiding this comment

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

@sticnarf please resolve conflict.

@zz-jason zz-jason added the status/LGT1 Indicates that a PR has LGTM 1. label May 6, 2020
@sticnarf
Copy link
Contributor Author

/run-all-tests

@sticnarf
Copy link
Contributor Author

/run-unit-test

@sticnarf
Copy link
Contributor Author

PTAL again @XuHuaiyu @zz-jason
Thanks!

Copy link
Member

@zz-jason zz-jason left a comment

Choose a reason for hiding this comment

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

LGTM

@zz-jason zz-jason added status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels May 13, 2020
@sre-bot
Copy link
Contributor

sre-bot commented May 13, 2020

/run-all-tests

@sre-bot
Copy link
Contributor

sre-bot commented May 13, 2020

@sticnarf merge failed.

@sticnarf sticnarf added status/can-merge Indicates a PR has been approved by a committer. and removed status/can-merge Indicates a PR has been approved by a committer. labels May 13, 2020
@sre-bot
Copy link
Contributor

sre-bot commented May 13, 2020

/run-all-tests

@sre-bot
Copy link
Contributor

sre-bot commented May 13, 2020

@sticnarf merge failed.

@sticnarf sticnarf added status/can-merge Indicates a PR has been approved by a committer. and removed status/can-merge Indicates a PR has been approved by a committer. labels May 13, 2020
@sre-bot
Copy link
Contributor

sre-bot commented May 13, 2020

/run-all-tests

@sre-bot sre-bot merged commit 526a711 into pingcap:master May 13, 2020
sre-bot pushed a commit to sre-bot/tidb that referenced this pull request May 13, 2020
@sre-bot
Copy link
Contributor

sre-bot commented May 13, 2020

cherry pick to release-4.0 in PR #17155

sticnarf added a commit to sticnarf/tidb that referenced this pull request May 13, 2020
@SunRunAway
Copy link
Contributor

Does this PR need a release note? It seems not to affect users

@sticnarf
Copy link
Contributor Author

Does this PR need a release note? It seems not to affect users

Currently the only effect is to help TiKV schedule requests better. I think you can decide whether to include the release note as you please.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/session component/tikv sig/execution SIG execution 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.

The unified read pool should not use start_ts as task id
8 participants