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

Parallel building cop tasks with cop workers in TiKV client. (select * from limit 1 is too slow) #14320

Open
SunRunAway opened this issue Jan 2, 2020 · 9 comments
Assignees
Labels
component/tikv help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. type/enhancement The issue or PR belongs to an enhancement. type/performance

Comments

@SunRunAway
Copy link
Contributor

SunRunAway commented Jan 2, 2020

Description

The current procedure when sending a cop request is

  1. build all cop tasks in memory.
  2. send each cop task to copIteratorWorker
  3. copIteratorWorker execute the task

If we have thousands of tasks, the building step may take too long(and it may load region info from pd), it will enlarge the time of first meeting row.

We need build all cop tasks in a diffrent goroutine, and send tasks which successfully builded immediately to copIteratorWorker.

  1. For OLTP SQLs, it would be better build first 1 or 2 tasks in the same goroutine, then create a new goroutine to build the rest.
  2. We can fix this issue when the request need an asending order firstly.
  3. If the request need a desending order response, it may takes extra works on this issue. (We may need implement a desending spliting range method)

Difficulty

  • Medium

Score

  • 2500

Mentor(s)

Recommended Skills

  • Go programming
@SunRunAway SunRunAway added type/enhancement The issue or PR belongs to an enhancement. type/performance labels Jan 2, 2020
@SunRunAway SunRunAway self-assigned this Jan 2, 2020
@SunRunAway SunRunAway added sig/execution SIG execution difficulty/easy good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. component/tikv and removed sig/execution SIG execution good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. difficulty/easy labels Jan 2, 2020
@SunRunAway SunRunAway changed the title tikv: Parallel building cop tasks with cop workers. PCP: Parallel building cop tasks with cop workers in TiKV client. Jan 3, 2020
@sre-bot sre-bot added the PCP-S1 label Jan 3, 2020
@SunRunAway SunRunAway removed their assignment Jan 3, 2020
@ekalinin
Copy link
Contributor

ekalinin commented Jan 3, 2020

/pick-up-challenge

@sre-bot
Copy link
Contributor

sre-bot commented Jan 3, 2020

@ekalinin already had picked #12939, finish it before pick up a new one.

@ekalinin
Copy link
Contributor

ekalinin commented Jan 3, 2020

/pick-up-challenge

@sre-bot
Copy link
Contributor

sre-bot commented Jan 3, 2020

@ekalinin pick up issue success

@SunRunAway
Copy link
Contributor Author

Hi @ekalinin , Thank you for picking this chanllenge.
Do you have any ideas or plans? Feel free to ask me anything here or on slack.

@ekalinin
Copy link
Contributor

ekalinin commented Jan 7, 2020

Hi @ekalinin , Thank you for picking this chanllenge.
Do you have any ideas or plans? Feel free to ask me anything here or on slack.

Hi @SunRunAway

Yes, i'm working on this issue it the moment.
Current plan is:

  • Add new function buildCopTasksChan. It's gonna be almost the same as buildCopTasks, except several things:
    • returns buffered channel (like: tasksCh := make(chan *copTask, 1024), 1024 is for example, we can think about more suitable value)
    • splitRanges / buildTiDBMemCopTasks will be called in background
    • splitRanges / buildTiDBMemCopTasks: all new instances of the copTask will be sent into that channel
  • Remove buildCopTasks call from Send(...)
  • Add buildCopTasksChan call during the copIterator.open(), returned channel will be saved in copIterator.tasksCh
  • Replace copIteratorTaskSender.tasks []*copTask with copIteratorTaskSender.tasksCh chan *copTask,
  • Update copIteratorTaskSender.run:
    • iterate over sender.tasksCh instead of sender.tasks
    • fill copIterator.tasks during iteration
  • Update copIterator.Next:
    • for the keepOrder branch wait until all it.tasks are filled

Current state: did almost all steps, except last one (copIterator.Next). And a lot of tests are failing at the moment.

@SunRunAway
Copy link
Contributor Author

👍 Sounds great, looking forward your pull request.

@you06 you06 changed the title PCP: Parallel building cop tasks with cop workers in TiKV client. Parallel building cop tasks with cop workers in TiKV client. Feb 29, 2020
@SunRunAway
Copy link
Contributor Author

@fzhedu PTAL when you're free, Thanks.

@you06
Copy link
Contributor

you06 commented Jun 25, 2024

After #53850, both tiflash and tikv coprocessor load the region info in batch from PD, building all the cop tasks no more taks a long time, I think this issue can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/tikv help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. type/enhancement The issue or PR belongs to an enhancement. type/performance
Projects
None yet
8 participants