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

set sqlite PRAGMAs to improve performance #13

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

matt-codecov
Copy link
Collaborator

@matt-codecov matt-codecov commented Jul 30, 2024

quick changes to SQLite pragmas to improve bulk insert performance:

  • journal_mode=OFF: no transaction journal, we can't roll back (in SQLite). we can still "rollback" by just not persisting/exporting the SQLite database after failed processing
  • cache_size=-200000: set the SQLite page cache size to ~200MB
  • synchronous=OFF: trust the filesystem to perform reads reliably

journal_mode and cache_size together improve bulk insert speed for my 110mb test report by about a second. cache_size increases the RAM usage, but it's capped. i chose 200MB arbitrarily but we can turn this knob later when running on real traffic

with a 200MB page cache, i found RAM usage topped off at ~150MB for my 110mb test report. profile data shows SQLite doesn't do any disk writes until the end when the transaction gets committed, and not a lot of time is spent waiting on disk IO overall. most of the time remaining is spent on index updates and such

Copy link

codecov bot commented Jul 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.21%. Comparing base (c0a4b65) to head (e1ceeb4).

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #13   +/-   ##
=======================================
  Coverage   99.21%   99.21%           
=======================================
  Files          17       17           
  Lines        7249     7252    +3     
=======================================
+ Hits         7192     7195    +3     
  Misses         57       57           

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

Copy link
Contributor

@Swatinem Swatinem left a comment

Choose a reason for hiding this comment

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

we can't roll back (in SQLite). we can still "rollback" by just not persisting/exporting the SQLite database after failed processing

In that case, does it make sense to use transactions at all?

@matt-codecov
Copy link
Collaborator Author

In that case, does it make sense to use transactions at all?

y'know, great question. before merging this, i'll measure that. i think transactions still affect locking behavior and maybe more, but maybe they won't matter

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.

2 participants