pingcap / pingcap/tiflash

Refine memory allocation for MPP Hash Join

Open
#1,400 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type/enhancement
Dominant language
C++
Stars
1k
Forks
423
Avg merge
1d 15h
Merged PRs (30d)
24

Description

For now Allocator will use a MMAP_THRESHOLD to decide if we need to manually do mmap or mremap.

Clickhouse makes the MMAP_THRESHOLD 64MB. And here gives their reason:

mmap/munmap is very slow and does not scale. It gives about 1000 iterations per second regardless the number of threads. Suppose you want to allocate chunk of memory and then fill it with data and process. Let's make this chunk large enough, so the cost of mmap/munmap will be neglible to the cost of data processing. The size 64MB is selected under assumption that we can process data with speed up to several tens of gigabytes per second.

The assumption is that 64 MB is large enough to amortize the cost of page faults. If it's not the case, better to increase the threshold globally.

While in TiFlash MPP workload, there are massive allocation during Hash Join build stage because of hashtable rehashing. In this case, page fault will take about 10% of CPU time. Here's an example of TPCH 100 Q9:
image

We found that if we tune up the threshold value to a higher value like 64GB, page fault will reduce a lot:
image

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Allocator and its MMAP_THRESHOLD decision, then examine memory allocation during the MPP Hash Join build stage. Reproduce or profile the TPCH 100 Q9 workload described in the issue and compare page-fault CPU time. Done means the allocation threshold is refined and page faults are substantially reduced for this workload.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.