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

[db] Remove duplicate keys when WriteBatch #4155

Merged
merged 6 commits into from
Mar 6, 2024

Conversation

envestcc
Copy link
Member

@envestcc envestcc commented Feb 28, 2024

Description

In the scenario of 500 TPS, the CommitBlock time is relatively long (2~3s), and most of the time is spent on db.WriteBatch, requiring optimization.

After testing and analysis, there are many duplicate redundant operations in WriteBatch (2w operations for only 6~8k keys). Therefore, before executing the write operation of db, we deduplicate the keys, keeping only the last operation for each key.

Ultimately, the CommitBlock time was optimized to around 200ms.

Type of change

Please delete options that are not relevant.

  • Code refactor or improvement

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • make test

Test Configuration:

  • Firmware version:
  • Hardware:
  • Toolchain:
  • SDK:

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Copy link

codecov bot commented Feb 28, 2024

Codecov Report

Attention: Patch coverage is 90.00000% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 76.39%. Comparing base (e1f0636) to head (51214dc).
Report is 185 commits behind head on master.

Files Patch % Lines
db/db_bolt.go 90.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4155      +/-   ##
==========================================
+ Coverage   75.38%   76.39%   +1.01%     
==========================================
  Files         303      340      +37     
  Lines       25923    28971    +3048     
==========================================
+ Hits        19541    22132    +2591     
- Misses       5360     5732     +372     
- Partials     1022     1107      +85     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

db/db_bolt.go Outdated
}
}
boltdbMtc.WithLabelValues(b.path, "entrySize").Set(float64(kvsb.Size()))
boltdbMtc.WithLabelValues(b.path, "entryMapSize").Set(float64(len(entryMap)))
Copy link
Collaborator

Choose a reason for hiding this comment

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

uniqueEntrySize

if e != nil {
return e
}
k := doubleKey{ns: write.Namespace(), key: string(write.Key())}
Copy link
Collaborator

Choose a reason for hiding this comment

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

only handle writeType batch.Put and batch.Delete

db/db_bolt.go Outdated
if e != nil {
return e
}
// though range entryMap is random, but it doesn't matter which key is processed first
Copy link
Member

Choose a reason for hiding this comment

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

will the random sequence cause the nondeterministic md5 value of Snapshot file? For example, will the binary file(*.db) be same between bucket.Put(A,{}) -> bucket.Put(B,{}) and bucket.Put(B,{}) -> bucket.Put(A,{})?

Copy link

sonarcloud bot commented Mar 6, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
4.6% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

@envestcc envestcc merged commit 05b11f7 into iotexproject:master Mar 6, 2024
3 of 5 checks passed
@envestcc envestcc deleted the pr-uniqkey branch March 6, 2024 11:33
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