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

re-organize the reuse chunk pool implementation #49661

Closed
YangKeao opened this issue Dec 21, 2023 · 2 comments · Fixed by #49667
Closed

re-organize the reuse chunk pool implementation #49661

YangKeao opened this issue Dec 21, 2023 · 2 comments · Fixed by #49667
Labels
type/enhancement The issue or PR belongs to an enhancement.

Comments

@YangKeao
Copy link
Member

Enhancement

Sometimes, we re-used the chunk pool to avoid re-allocating memories across multiple statements. This chunk pool located in the "connection", and is set into session context when it's possible to re-use the allocator. This part of code is quite confusing:

  1. chunk.Allocator is not safe to call concurrently. Therefore, we always use GetNewChunkWithCapacity to allocate chunks from the allocator, and it'll use (*SessionVars).ChunkPool.mu to protect the allocator inside the BaseExecutor. It's reasonable because usually all BaseExecutor just used the ChunkPool in session context. However, just from the code, the relationship between the (*SessionVars).ChunkPool.mu and the BaseExecutor.Alloc is not significant.
  2. We expect to remove session context from the BaseExecutor, so we have to remove the GetNewChunkWithCapacity function call in the implementation of BaseExecutor.

And also, we'll need to use a session variable to tell whether the re-use chunk pool optimization is enabled. Also, we have a read-only session variable to tell the users whether last statement used the re-used chunk 🤦 . It's a little complicated.

@YangKeao YangKeao added the type/enhancement The issue or PR belongs to an enhancement. label Dec 21, 2023
@lance6716
Copy link
Contributor

BR/lightning has a []byte pool https://github.com/pingcap/tidb/blob/master/br/pkg/membuf/buffer.go , do you think our usage are similar so we can unify them?

@YangKeao
Copy link
Member Author

BR/lightning has a []byte pool https://github.com/pingcap/tidb/blob/master/br/pkg/membuf/buffer.go , do you think our usage are similar so we can unify them?

For this issue, I'm not going to rewrite chunk.(*allocator), but only refactor variable.ReuseChunkPool, which is used to re-use the same (*allocator) in a session across many different queries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants