Skip to content

Conversation

@THUMarkLau
Copy link
Contributor

See IOTDB-3164.

This PR is one part of the compaction memory management. It does the following jobs:

  • Allocate memory before cross space compaction, and release the memory after the execution.
  • Remove the RewriteCompactionFileSelector, which is deduplicated with RewriteCrossSpaceCompactionSelector.

To complete the compaction memory management, we need to complete the following jobs:

  • Manage the memory usage of unsequence inner space compaction, which uses read point performer.
  • Design and implement the memory estimator for read chunk performer.
  • Manage the memory usage of sequence inner space comapction, which uses read chunk performer.

@THUMarkLau THUMarkLau requested review from HTHou and qiaojialin August 8, 2022 09:08
@coveralls
Copy link

coveralls commented Aug 8, 2022

Coverage Status

Coverage increased (+0.02%) to 42.338% when pulling ad73693 on IOTDB-3164-O into 37d6cfe on master.

@THUMarkLau
Copy link
Contributor Author

I use IoTDB benchmark tests changed after the performance, and the master (commit: a8f757d) are compared. The result of the comparison is shown in the figure below. In terms of average performance, the write performance after the change decreases by about 2.8%.

master branch
e173a42189cf91925f9f73475afac2b

with memory management for cross space compaction
dd9c26571d2659edfb92e40e6d87df9

this.dataRegionId = dataRegionId;
this.timePartition = timePartition;
this.tsFileManager = tsFileManager;
this.memoryBudget = config.getCrossCompactionMemoryBudget();
Copy link
Member

Choose a reason for hiding this comment

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

apply this memory from the storage engine, not from the whole system

Copy link
Contributor Author

Choose a reason for hiding this comment

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

reslove


/** How much memory (in byte) can be used by a single merge task. */
private long crossCompactionMemoryBudget = (long) (Runtime.getRuntime().maxMemory() * 0.1);
private long crossCompactionMemoryBudget = (long) (allocateMemoryForWrite * 0.1D);
Copy link
Member

Choose a reason for hiding this comment

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

The default variable is

private double compactionProportion = 0.2;

Suggested change
private long crossCompactionMemoryBudget = (long) (allocateMemoryForWrite * 0.1D);
private long crossCompactionMemoryBudget = (long) (allocateMemoryForWrite * 0.2D);


private static long memorySizeForWrite = config.getAllocateMemoryForWrite();
private static long memorySizeForWrite =
(long) (config.getAllocateMemoryForWrite() * config.getMemtableProportion());
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
(long) (config.getAllocateMemoryForWrite() * config.getMemtableProportion());
(long) (config.getAllocateMemoryForStorageEngine() * config.getWriteProportion());


/** How much memory (in byte) can be used by a single merge task. */
private long crossCompactionMemoryBudget = (long) (Runtime.getRuntime().maxMemory() * 0.1);
private long crossCompactionMemoryBudget = (long) (allocateMemoryForWrite * 0.1D);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
private long crossCompactionMemoryBudget = (long) (allocateMemoryForWrite * 0.1D);
private long compactionMemoryBudget = (long) (allocateMemoryForStorageEngine * compactionProportion);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This param is removed

@qiaojialin
Copy link
Member

@Override
protected void doCompaction() {
try {
SystemInfo.getInstance().addCompactionMemoryCost(memoryCost);
Copy link
Member

Choose a reason for hiding this comment

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

what if the allocateMemory throw interrupt exception without succeeding in adding?

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 move allocateMemory in a seperate try-catch block.

@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug D 2 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 11 Code Smells

89.5% 89.5% Coverage
0.0% 0.0% Duplication


public void addCompactionMemoryCost(long memoryCost) throws InterruptedException {
long originSize = this.compactionMemoryCost.get();
while (originSize + memoryCost > memorySizeForCompaction
Copy link
Member

Choose a reason for hiding this comment

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

If there are two tasks call this method concurrently,
Task1 originSize = 10;
Task2 originSize = 10;
Task1.compactionMemoryCost.compacreAndSet(10, 10+30) = 40;
Task2 compareAndSet is always false, and Task2 sleeps forever.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The originSize is updated in the while block.

Copy link
Contributor

@HTHou HTHou left a comment

Choose a reason for hiding this comment

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

LGTM

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants