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

lightning: add send-kv-size to avoid oom when each kv is large on default config #43870

Merged
merged 4 commits into from
May 18, 2023

Conversation

D3Hunter
Copy link
Contributor

@D3Hunter D3Hunter commented May 16, 2023

What problem does this PR solve?

Issue Number: close #43853

Problem Summary:

What is changed and how it works?

  • add config send-kv-size together with existing config send-kv-pairs to control how much data to accumulate before send to tikv

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
    • there's 1 file of 1G in source data, each row is about 20K
    • set range-concurrency=1(2 thread writing concurrently); use a separate membuf.Pool for writeToTiKV and disable CGO version of membuf pool so we can know how much memory used by it; add sleep before send to tikv, so we can take a heap profile

before this pr:
FoiKbJsR9U

after

WmcarTuslK

  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

add config `send-kv-size` together with existing config `send-kv-pairs` to control how much data to accumulate before send to tikv

@ti-chi-bot
Copy link

ti-chi-bot bot commented May 16, 2023

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • gozssky
  • lance6716

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot bot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label May 16, 2023
@D3Hunter D3Hunter requested review from sleepymole and lance6716 May 16, 2023 07:52
@ti-chi-bot ti-chi-bot bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 16, 2023
@@ -395,7 +395,9 @@ type BackendConfig struct {
ConnCompressType config.CompressionType
// concurrency of generateJobForRange and import(write & ingest) workers
WorkerConcurrency int
KVWriteBatchSize int
Copy link
Contributor Author

Choose a reason for hiding this comment

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

renamed to KVWriteBatchCount

Copy link
Contributor

Choose a reason for hiding this comment

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

we'd better use a new name, rather than change the meaning of it. If we debug in different release version this is confusing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we have this name start from 7.1, if we pick to 7.1, i think it's ok

@D3Hunter D3Hunter added the component/lightning This issue is related to Lightning of TiDB. label May 16, 2023
@ti-chi-bot ti-chi-bot bot added needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. labels May 16, 2023
@D3Hunter
Copy link
Contributor Author

/run-integration-br-test

4 similar comments
@D3Hunter
Copy link
Contributor Author

/run-integration-br-test

@D3Hunter
Copy link
Contributor Author

/run-integration-br-test

@D3Hunter
Copy link
Contributor Author

/run-integration-br-test

@purelind
Copy link
Contributor

/run-integration-br-test

Copy link
Contributor

@lance6716 lance6716 left a comment

Choose a reason for hiding this comment

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

rest lgtm

@@ -395,7 +395,9 @@ type BackendConfig struct {
ConnCompressType config.CompressionType
// concurrency of generateJobForRange and import(write & ingest) workers
WorkerConcurrency int
KVWriteBatchSize int
Copy link
Contributor

Choose a reason for hiding this comment

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

we'd better use a new name, rather than change the meaning of it. If we debug in different release version this is confusing

KVWriteBatchCount = 32768
// KVWriteBatchSize batch size when write to TiKV.
// this is the default value of linux send buffer size(net.ipv4.tcp_wmem) too.
KVWriteBatchSize = 16 * units.KiB
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 too small considering a large row KV. Maybe we should use 4M which is the maximun value of it?

Copy link
Contributor Author

@D3Hunter D3Hunter May 17, 2023

Choose a reason for hiding this comment

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

it depends on how often do customer tune network parameters, if user do set to 4M
(256 * (accumulate 16k + serialize + append to linux send buffer)) + send to network compared to (accumulate 4M + serialize + append to linux send buffer) + send to network, seems no much difference, will test the default tcp_wmem + 16k/4m batch size using qa env

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i misunderstand, it works like this:

When a new TCP connection is established, a Send Buffer will be created using the default value (16KB); the buffer size will then be automatically adjusted within the maximum and minimum boundaries as needed and based on usage.

@ti-chi-bot ti-chi-bot bot added the status/LGT1 Indicates that a PR has LGTM 1. label May 17, 2023
@D3Hunter
Copy link
Contributor Author

D3Hunter commented May 17, 2023

no speed difference during write/ingest whether use default 16k or 4m(573.1GiB source data)

sh-5.1# grep 'send-kv-size' /tmp/sorted-kv-dir/lightning-default.log|sed -e 's/.*\(send-kv-size\\":\w*\).*/\1/g'
send-kv-size\":16384
send-kv-size\":16384
sh-5.1# grep 'import completed' /tmp/sorted-kv-dir/lightning-default.log
[2023/05/17 05:13:57.019 +00:00] [INFO] [backend.go:350] ["import completed"] [engineTag=`sysbench`.`user_data1`:1] [engineUUID=6a3dab49-c31c-5ac7-bde9-6b69aff9c175] [retryCnt=0] [takeTime=26m34.527426011s] []
[2023/05/17 05:13:57.959 +00:00] [INFO] [backend.go:350] ["import completed"] [engineTag=`sysbench`.`user_data1`:2] [engineUUID=c3eca481-19b1-54ea-96e9-8c81442d8797] [retryCnt=0] [takeTime=26m35.267945546s] []
[2023/05/17 05:13:58.719 +00:00] [INFO] [backend.go:350] ["import completed"] [engineTag=`sysbench`.`user_data1`:0] [engineUUID=37838caf-8257-5e42-98b2-a4c68350cf98] [retryCnt=0] [takeTime=26m39.689968454s] []
[2023/05/17 05:13:58.803 +00:00] [INFO] [backend.go:350] ["import completed"] [engineTag=`sysbench`.`user_data1`:5] [engineUUID=1e94b89f-1c47-5334-a1b7-2ec9883de322] [retryCnt=0] [takeTime=26m39.756035012s] []
[2023/05/17 05:13:58.854 +00:00] [INFO] [backend.go:350] ["import completed"] [engineTag=`sysbench`.`user_data1`:4] [engineUUID=91ff3623-ac29-5a10-b0b8-41236476f52d] [retryCnt=0] [takeTime=26m35.24200116s] []
[2023/05/17 05:13:58.914 +00:00] [INFO] [backend.go:350] ["import completed"] [engineTag=`sysbench`.`user_data1`:3] [engineUUID=1f8172f3-a74c-575e-a955-d25336615364] [retryCnt=0] [takeTime=26m35.506627828s] []
[2023/05/17 05:14:04.846 +00:00] [INFO] [backend.go:350] ["import completed"] [engineTag=`sysbench`.`user_data1`:-1] [engineUUID=d5b7ce1d-48da-51e0-ab64-c572d2662ff5] [retryCnt=0] [takeTime=4.795442123s] []
sh-5.1# grep 'send-kv-size' /tmp/sorted-kv-dir/lightning.log|sed -e 's/.*\(send-kv-size\\":\w*\).*/\1/g'
send-kv-size\":4194304
sh-5.1# grep 'import completed' /tmp/sorted-kv-dir/lightning.log
[2023/05/17 06:51:16.150 +00:00] [INFO] [backend.go:350] ["import completed"] [engineTag=`sysbench`.`user_data1`:2] [engineUUID=c3eca481-19b1-54ea-96e9-8c81442d8797] [retryCnt=0] [takeTime=26m20.269360517s] []
[2023/05/17 06:51:18.395 +00:00] [INFO] [backend.go:350] ["import completed"] [engineTag=`sysbench`.`user_data1`:4] [engineUUID=91ff3623-ac29-5a10-b0b8-41236476f52d] [retryCnt=0] [takeTime=26m18.665723666s] []
[2023/05/17 06:51:18.641 +00:00] [INFO] [backend.go:350] ["import completed"] [engineTag=`sysbench`.`user_data1`:5] [engineUUID=1e94b89f-1c47-5334-a1b7-2ec9883de322] [retryCnt=0] [takeTime=26m30.520199639s] []
[2023/05/17 06:51:18.672 +00:00] [INFO] [backend.go:350] ["import completed"] [engineTag=`sysbench`.`user_data1`:1] [engineUUID=6a3dab49-c31c-5ac7-bde9-6b69aff9c175] [retryCnt=0] [takeTime=26m22.901256154s] []
[2023/05/17 06:51:18.681 +00:00] [INFO] [backend.go:350] ["import completed"] [engineTag=`sysbench`.`user_data1`:0] [engineUUID=37838caf-8257-5e42-98b2-a4c68350cf98] [retryCnt=0] [takeTime=26m29.639917829s] []
[2023/05/17 06:51:18.699 +00:00] [INFO] [backend.go:350] ["import completed"] [engineTag=`sysbench`.`user_data1`:3] [engineUUID=1f8172f3-a74c-575e-a955-d25336615364] [retryCnt=0] [takeTime=26m23.120782966s] []
[2023/05/17 06:51:23.438 +00:00] [INFO] [backend.go:350] ["import completed"] [engineTag=`sysbench`.`user_data1`:-1] [engineUUID=d5b7ce1d-48da-51e0-ab64-c572d2662ff5] [retryCnt=0] [takeTime=3.719838598s] []

@ti-chi-bot ti-chi-bot bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 17, 2023
@ti-chi-bot ti-chi-bot bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 17, 2023
@D3Hunter
Copy link
Contributor Author

/retest

1 similar comment
@D3Hunter
Copy link
Contributor Author

/retest

@ti-chi-bot ti-chi-bot bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels May 18, 2023
@D3Hunter
Copy link
Contributor Author

/merge

@ti-chi-bot
Copy link

ti-chi-bot bot commented May 18, 2023

This pull request has been accepted and is ready to merge.

Commit hash: 48d321d

@ti-chi-bot ti-chi-bot bot added the status/can-merge Indicates a PR has been approved by a committer. label May 18, 2023
@D3Hunter
Copy link
Contributor Author

/retest

4 similar comments
@D3Hunter
Copy link
Contributor Author

/retest

@D3Hunter
Copy link
Contributor Author

/retest

@D3Hunter
Copy link
Contributor Author

/retest

@D3Hunter
Copy link
Contributor Author

/retest

@D3Hunter
Copy link
Contributor Author

unstable cases will be fixed in #43880

@ti-chi-bot ti-chi-bot bot removed the status/can-merge Indicates a PR has been approved by a committer. label May 18, 2023
@D3Hunter
Copy link
Contributor Author

/merge

@ti-chi-bot
Copy link

ti-chi-bot bot commented May 18, 2023

This pull request has been accepted and is ready to merge.

Commit hash: 86b6e11

@ti-chi-bot ti-chi-bot bot added the status/can-merge Indicates a PR has been approved by a committer. label May 18, 2023
@ti-chi-bot ti-chi-bot bot merged commit ca62944 into master May 18, 2023
@ti-chi-bot ti-chi-bot bot deleted the send-kv-size branch May 18, 2023 09:49
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-7.1: #43964.

@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-6.5: #43965.

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request May 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/lightning This issue is related to Lightning of TiDB. needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. 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.

lightning oom when importing wide table on default config
5 participants