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

AutoCompact & CompactWithDeprecateTable Support #165

Merged
merged 62 commits into from
Oct 14, 2024

Conversation

KANIOYH
Copy link
Contributor

@KANIOYH KANIOYH commented Aug 21, 2024

AutoCompact & CompactWithDeprecateable

Add autoCompact support.

AutoCompact can automatically occur in the background. There are not implementation for IO state, only reserve space for it.

This feature adds a memory-based deprecated table (dptable), which marks deprecated data in the vlog based on the UUID of each operation, without the need to retrieve deprecated data through the bptree.

This feature mainly reduces the overhead of accessing the bptree.Reduced by approximately one order of magnitude. bptreeTime:219.758243 ms > dptableTime:24.207176 ms

We need to further discuss the IO status. It is initially believed that disk-level monitoring is superior to API hooks.

disk-level monitoring | maybe useful:github.com/shirou/gopsutil

//output:
[{"device":"C:","mountpoint":"C:","fstype":"NTFS","opts":"rw.compress"} {"device":"D:","mountpoint":"D:","fstype":"NTFS","opts":"rw.compress"} {"device":"E:","mountpoint":"E:","fstype":"NTFS","opts":"rw.compress"} ]
{"path":"E:","fstype":"","total":107380965376,"free":46790828032,"used":60590137344,"usedPercent":56.425398236866755,"inodesTotal":0,"inodesUsed":0,"inodesFree":0,"inodesUsedPercent":0}
map[C::{"readCount":0,"mergedReadCount":0,"writeCount":0,"mergedWriteCount":0,"readBytes":0,"writeBytes":4096,"readTime":0,"writeTime":0,"iopsInProgress":0,"ioTime":0,"weightedIO":0,"name":"C:","serialNumber":"","label":""} ]

Changes

  • Modified the encoding format of records in the vlog to include UUID information.

  • Changed the value format in the bptree to include UUID information.

  • Added a listener coroutine responsible for triggering AutoCompact.

  • Introduced the CompactWithDeprecateable method, which implements compaction based on the dptable.

  • Modified some test functions to cover cases involving compaction.

  • Added relevant options.

Test Reuslt

According to a mixed read-write ratio of 5:1.

Compare

The results of comparing Compact and CompactWithDeprecatedable are as follows:

=== RUN   TestDBCompact/test_compaction
[Compact data]
(shard:0) bptreeTime:219.758243ms       readerTIme:331.78238ms  rewriteTime:96.310796ms all:820.391944ms
(shard:2) bptreeTime:232.646786ms       readerTIme:344.188357ms rewriteTime:91.904951ms all:858.445579ms
(shard:1) bptreeTime:257.153977ms       readerTIme:357.054894ms rewriteTime:82.546513ms all:886.131432ms
--- PASS: TestDBCompact (19.06s) # <-- ignore, it include data preload -->
    --- PASS: TestDBCompact/test_compaction (0.89s)

=== RUN   TestDBCompactWitchDeprecateable/test_compaction
[CompactWithDeprecatedable data]
(shard:2) dptableTime:24.207176ms       reader:297.85245ms      rewriteTime:89.254724ms all:562.317783ms
(shard:0) dptableTime:25.151011ms       reader:314.874621ms     rewriteTime:92.429257ms all:586.549001ms
(shard:1) dptableTime:28.363133ms       reader:368.892013ms     rewriteTime:88.781865ms all:647.749456ms
--- PASS: TestDBCompactWitchDeprecateable (18.73s) # <-- ignore, it include data preload -->
    --- PASS: TestDBCompactWitchDeprecateable/test_compaction (0.65s)

We can easily observe that bptreeTime is significantly higher than dptableTime, as it has a greater access overhead. Notably, the original compact has slightly lower overhead when modifying the B+ tree information a second time. This is likely because after the first read, there is a high probability that the cache entry exists in memory, which is a common characteristic of B+ trees.


TestDBAutoCompact

=== RUN   TestDBAutoCompact
[Compact data]
(shard:2) bptreeTime:  0s       readerTIme:26.373µs     rewriteTime:  0s        all:111.478µs
(shard:1) bptreeTime:  0s       readerTIme:23.372µs     rewriteTime:  0s        all:123.234µs
(shard:0) bptreeTime:  0s       readerTIme:150.454µs    rewriteTime:  0s        all:346.099µs
=== RUN   TestDBAutoCompact/test_compaction
[data in flush] deprecatedNumber: 0 LowerThreshold: 204800 UpperThreshold: 409600
[data in flush] deprecatedNumber: 42444 LowerThreshold: 204800 UpperThreshold: 409600
[data in flush] deprecatedNumber: 87332 LowerThreshold: 204800 UpperThreshold: 409600
[data in flush] deprecatedNumber: 134664 LowerThreshold: 204800 UpperThreshold: 409600
[data in flush] deprecatedNumber: 184440 LowerThreshold: 204800 UpperThreshold: 409600
[data in flush] deprecatedNumber: 226654 LowerThreshold: 204800 UpperThreshold: 409600
ArriveLowerThreshold
[CompactWithDeprecatedable data]
(shard:2) dptableTime:18.524262ms       reader:237.848375ms     rewriteTime:106.529464ms        all:468.550733ms
(shard:0) dptableTime:22.412305ms       reader:296.664449ms     rewriteTime:109.612276ms        all:546.467484ms
(shard:1) dptableTime:25.431771ms       reader:318.471562ms     rewriteTime:120.71244ms all:617.222454ms
[data in flush] deprecatedNumber: 44658 LowerThreshold: 204800 UpperThreshold: 409600
[data in flush] deprecatedNumber: 91759 LowerThreshold: 204800 UpperThreshold: 409600
--- PASS: TestDBAutoCompact (17.19s)
    --- PASS: TestDBAutoCompact/test_compaction (17.15s)
PASS
ok      github.com/lotusdblabs/lotusdb/v2       17.228s
    

KANIOYH and others added 16 commits July 1, 2024 21:55
…autoCompact.

And add default value of  lower and upper threshold in options.
=== RUN   TestDBCompact/test_compaction
shard:1 Function took existTime:395.82922ms,reader:535.043275ms,rewriteTime:790.151805ms,all:1.945597922s
shard:2 Function took existTime:409.16579ms,reader:547.093471ms,rewriteTime:810.14034ms,all:1.996946539s
shard:0 Function took existTime:414.753128ms,reader:547.752194ms,rewriteTime:826.628021ms,all:2.024067234s

=== RUN   TestDBCompactWitchDeprecateable/test_compaction
shard:1 Function took existTime:15.4204ms,reader:563.989168ms,rewriteTime:910.374564ms,all:1.67209614s
shard:0 Function took existTime:21.662887ms,reader:587.597162ms,rewriteTime:996.416705ms,all:1.794619638s
shard:2 Function took existTime:16.989118ms,reader:627.684099ms,rewriteTime:996.287388ms,all:1.833219848s
…e features.

Support printing performance data for two different types of compacts and TestautoCompact.
@KANIOYH KANIOYH closed this Aug 21, 2024
@KANIOYH KANIOYH reopened this Aug 21, 2024
db.go Outdated Show resolved Hide resolved
db.go Outdated Show resolved Hide resolved
vlog.go Show resolved Hide resolved
db.go Outdated Show resolved Hide resolved
db.go Outdated Show resolved Hide resolved
db.go Outdated Show resolved Hide resolved
bptree.go Show resolved Hide resolved
db.go Show resolved Hide resolved
db.go Outdated Show resolved Hide resolved
db.go Outdated Show resolved Hide resolved
db.go Outdated Show resolved Hide resolved
db.go Outdated Show resolved Hide resolved
deprecatedtable.go Outdated Show resolved Hide resolved
diskio.go Show resolved Hide resolved
@roseduan
Copy link
Contributor

roseduan commented Oct 6, 2024

感谢 PR,请修复对应的 comment,并且 rebase 一下代码。

@yanxiaoqi932 yanxiaoqi932 merged commit d2bad43 into lotusdblabs:main Oct 14, 2024
2 checks passed
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.

3 participants