Skip to content

executor: unify executor concurrency#16999

Merged
SunRunAway merged 19 commits into
pingcap:masterfrom
niedhui:niedhui/unify_executor_concurrency
Jun 22, 2020
Merged

executor: unify executor concurrency#16999
SunRunAway merged 19 commits into
pingcap:masterfrom
niedhui:niedhui/unify_executor_concurrency

Conversation

@niedhui
Copy link
Copy Markdown
Contributor

@niedhui niedhui commented May 6, 2020

UCP #15428

What problem does this PR solve?

Issue Number: part of #15428

Problem Summary:

What is changed and how it works?

What's Changed:

Deprecated existing executor-concurrency related variables, use a single ExecutorConcurreny to control the concurrency of all types of executors.

How it Works:

  1. Introduce a system variable ExecutorConcurrency to control the concurrency of all types of executors.
  2. All deprecated fields of sessionctx/Concurrency were hidden, and use the exported functions to get the value
  3. The functions first try to read the deprecated-field for compatibility, if the value was -1 (which means unset), the value of ExecutorConcurrency was returned.

Updates

We have nine executor-concurrency related variables:

  • tidb_index_lookup_concurrency
  • tidb_index_lookup_join_concurrency
  • tidb_hashagg_partial_concurrency
  • tidb_hashagg_final_concurrency
  • tidb_window_concurrency
  • tidb_projection_concurrency
  • tidb_hash_join_concurrency
  • tidb_distsql_scan_concurrency
  • tidb_index_serial_scan_concurrency

I planed to migrate these variables in the following steps:

  1. In this PR, I only migrate the first 6 variables to adopt ExecutorConcurrency. Because the original default value of these variables is all 4, by making the default value of ExecutorConcurrency to 4 (not the number of cups), we would not break too many tests
  2. I will migrate tidb_hash_join_concurrency and tidb_distsql_scan_concurrency in the following PR, the original default value of these two is 5 and 15, we may discuss the default fixed-value of ExecutorConcurreny in the PR, 4 or 15, and this will break many tests, in TiDB, mysql-tester and copr-test, I would make changes on these repos by setting the fixed value of the concurrency variables.
  3. As we already knew, some tests are in strict mode, we may add the deprecated warning in a separate PR as the last step.
  4. tidb_index_serial_scan_concurrency will be kept since it's used by analyze-table as @SunRunAway suggested.

Known issues about tests currently :
We should only use set @@session.tidb_executor_concurrenly= to control the concurrency of executor, the execution plan may not be the same as it is, which may lead to lots of changes for currency tests.

Check List

  • All executors use ExecutorConcurrency
  • Bootstrap from old version
  • Show variable and values in mysql.global_variables
  • fix test

Tests

  • Unit test
  • Integration test

Release note

Deprecate tidb_index_lookup_concurrency, tidb_index_lookup_join_concurrency, , `tidb_hashagg_partial_concurrency`, `tidb_hashagg_final_concurrency`, `tidb_window_concurrency`, `tidb_projection_concurrency` and use the new tidb_executor_concurrency instead.

@niedhui niedhui requested review from a team as code owners May 6, 2020 15:00
@sre-bot
Copy link
Copy Markdown
Contributor

sre-bot commented May 6, 2020

Thanks for your contribution. If your PR get merged, you will be rewarded 300 points.

@ghost ghost requested review from eurekaka and qw4990 and removed request for a team May 6, 2020 15:00
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 6, 2020

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions Bot added sig/execution SIG execution sig/planner SIG: Planner labels May 6, 2020
@niedhui niedhui force-pushed the niedhui/unify_executor_concurrency branch 6 times, most recently from b5635f5 to bd39e1a Compare May 7, 2020 03:45
@zz-jason zz-jason requested a review from SunRunAway May 7, 2020 15:43
@zz-jason zz-jason added the contribution This PR is from a community contributor. label May 7, 2020
@niedhui
Copy link
Copy Markdown
Contributor Author

niedhui commented May 12, 2020

@SunRunAway friendly ping 😀

Copy link
Copy Markdown
Contributor

@SunRunAway SunRunAway left a comment

Choose a reason for hiding this comment

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

Hi, @niedhui

Firstly I apologize for the late reply.

Do you mean remove all the existing concurrency system variable, and make these as user-defined variable for compatibility?

I have to send my second apology to you that I misunderstood what you said and might give the wrong information to you. And the issue description may also lead us to an unexpected way.

It's not related to The user-defined variable.

What we want is,

  1. introduce a session and global variable tidb_executor_concurrency, which defaults to the numbers of CPU cores.
  2. change the default session and global variable tidb_hash_join_concurrency to NULL
  3. if tidb_hash_join_concurrency is NULL, apply the Hash Join concurrency by tidb_executor_concurrency, or by tidb_hash_join_concurrency for compatibility.

We do not need really remove existing concurrency system variables, but only deprecate and hide to new users for tidb v4.0.

For users upgraded from old versions, we may introduce a bootstrap policy,

  1. If all the global concurrency variables are the default value in old versions, we may assume that users haven't changed even one of them. So tidb-server can set all the global concurrency variables to NULL, the default value in new version, to make use of tidb_executor_concurrency in bootstrap.go

Comment thread sessionctx/variable/tidb_vars.go Outdated
@niedhui
Copy link
Copy Markdown
Contributor Author

niedhui commented May 26, 2020

🤣 Welcome back, mentor. I'll update this tomorrow

@niedhui
Copy link
Copy Markdown
Contributor Author

niedhui commented May 27, 2020

@SunRunAway

but only deprecate and hide to new users for tidb v4.0.

Then will the user still be able to change these deprecated variables using SQL? like

set @@session.tidb_hashagg_partial_concurrency = 1

@SunRunAway
Copy link
Copy Markdown
Contributor

SunRunAway commented May 28, 2020

@SunRunAway

but only deprecate and hide to new users for tidb v4.0.

Then will the user still be able to change these deprecated variables using SQL? like

set @@session.tidb_hashagg_partial_concurrency = 1

Yes. And the code is like,

if `tidb_hashagg_partial_concurrency` is not `NULL`:
    concurrency = tidb_hashagg_partial_concurrency
else 
    concurrency = tidb_executor_concurrency

Signed-off-by: niedhui <niedhui@gmail.com>
@niedhui niedhui force-pushed the niedhui/unify_executor_concurrency branch from bd39e1a to 7580be5 Compare May 28, 2020 13:51
@sre-bot
Copy link
Copy Markdown
Contributor

sre-bot commented May 28, 2020

Copy link
Copy Markdown
Contributor

@SunRunAway SunRunAway left a comment

Choose a reason for hiding this comment

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

For users upgraded from old versions, we may introduce a bootstrap policy,

If all the global concurrency variables are the default value in old versions, we may assume that users haven't changed even one of them. So tidb-server can set all the global concurrency variables to NULL, the default value in new version, to make use of tidb_executor_concurrency in bootstrap.go

Comment thread executor/builder.go Outdated
Comment thread sessionctx/variable/session.go Outdated
Comment thread sessionctx/variable/session.go
Comment thread sessionctx/variable/varsutil_test.go
Comment thread sessionctx/variable/session.go
Comment thread sessionctx/variable/tidb_vars.go
@SunRunAway
Copy link
Copy Markdown
Contributor

And best to update the PR description for your newest code and add a release note for the check_release_note bot.

@niedhui
Copy link
Copy Markdown
Contributor Author

niedhui commented Jun 16, 2020

[2020-06-16T13:07:04.798Z] time="2020-06-16T21:07:04+08:00" level=warning msg="Create new db&{0 {root:@tcp(127.0.0.1:4001)/test?strict=true&time_zone=%27Asia%2FShanghai%27 0x10a1110} 0 {0 0} [0xc000134280] map[] 0 1 0xc00002c2a0 0xc0000ca840 false map[0xc000134280:map[0xc000134280:true]] map[] 0 0 0 <nil> 0 0 0 0x48c430}"

[2020-06-16T13:07:04.798Z] time="2020-06-16T21:07:04+08:00" level=fatal msg="Executing \"SET @@tidb_hash_join_concurrency=2\" err[Warning 1287: 'tidb_hash_join_concurrency' is deprecated and will be removed in a future release. Please use tidb_executor_concurrency instead]"

Seems in strict mode, the warning was treated as error, should I remove the warning temporarily ?

@niedhui
Copy link
Copy Markdown
Contributor Author

niedhui commented Jun 18, 2020

@sre-bot /run-all-tests

@niedhui
Copy link
Copy Markdown
Contributor Author

niedhui commented Jun 18, 2020

@sre-bot /run-integration-br-test br=pr/362

@niedhui niedhui force-pushed the niedhui/unify_executor_concurrency branch from 9c00501 to 00bccb3 Compare June 18, 2020 15:58
Signed-off-by: niedhui <niedhui@gmail.com>
@niedhui niedhui force-pushed the niedhui/unify_executor_concurrency branch from 00bccb3 to b861379 Compare June 18, 2020 16:10
@niedhui
Copy link
Copy Markdown
Contributor Author

niedhui commented Jun 18, 2020

@sre-bot /run-all-tests

@niedhui
Copy link
Copy Markdown
Contributor Author

niedhui commented Jun 18, 2020

@sre-bot /run-unit-test

@niedhui
Copy link
Copy Markdown
Contributor Author

niedhui commented Jun 18, 2020

@sre-bot /run-common-test

@SunRunAway
Copy link
Copy Markdown
Contributor

/run-integration-br-test

@SunRunAway
Copy link
Copy Markdown
Contributor

SunRunAway commented Jun 18, 2020

image

@kennytm It seems that the BR command-line binary does not use the version in this pull request as a dependency.
This PR seems to require both tidb-server and BR itself to upgrade to this PR version because it changes the default value of tidb_index_lookup_concurrency along with the corresponding validation code.

Copy link
Copy Markdown
Contributor

@SunRunAway SunRunAway left a comment

Choose a reason for hiding this comment

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

LGTM

@SunRunAway SunRunAway added status/LGT1 Indicates that a PR has LGTM 1. and removed status/LGT2 Indicates that a PR has LGTM 2. labels Jun 19, 2020
@SunRunAway SunRunAway requested a review from zz-jason June 19, 2020 05:53
@kennytm
Copy link
Copy Markdown
Contributor

kennytm commented Jun 19, 2020

@SunRunAway We could modify the BR CI to add a replace the github.com/pingcap/tidb dependency by the specific TiDB commit, but the TiDB CI must be modified to tell the BR CI which TiDB commit is used. Someone from SRE may chime in?

Also, even if this trick allows the integration-br-test test to pass, BR itself would still not be fixed until a manual update.

@niedhui
Copy link
Copy Markdown
Contributor Author

niedhui commented Jun 19, 2020

Hi @zz-jason, I add an Updates section in the PR description. TLDR, in order to not break too many tests, I will only adopt some variables to ExecutorConcurrency and will open another PR to adopt the left.
PTAL, thanks.

Copy link
Copy Markdown
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/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Jun 22, 2020
@zz-jason
Copy link
Copy Markdown
Member

/merge

@ti-srebot
Copy link
Copy Markdown
Contributor

/run-all-tests

@ti-srebot
Copy link
Copy Markdown
Contributor

@niedhui merge failed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component/expression contribution This PR is from a community contributor. sig/execution SIG execution sig/planner SIG: Planner 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.

8 participants