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

sync2: dbset: use single connection for each sync session #6446

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

ivan4th
Copy link
Contributor

@ivan4th ivan4th commented Nov 11, 2024


Motivation

Using single connection for multiple SQL queries which are executed
during sync avoids noticeable overhead due to SQLite connection pool
delays.

Description

This makes derived DBSet used for each peer sync to use a dedicated connection,
without requesting the connection from pool multiple times.

Also, this change fixes memory overuse in DBSet. When initializing
DBSet from a database table, there's no need to use an FPTree with big
preallocated pool for the new entries that are added during recent sync.

There was an issue with Advance() crashing on a derived DBSet, which
is fixed, too.

This adds a possibility to take a connection from the pool to use it
via the Executor interface, and return it later when it's no longer
needed. This avoids connection pool overhead in cases when a lot of
quries need to be made, but the use of read transactions is not
needed.

Using read transactions instead of simple connections has the side
effect of blocking WAL checkpoints.
Using single connection for multiple SQL queries which are executed
during sync avoids noticeable overhead due to SQLite connection pool
delays.

Also, this change fixes memory overuse in DBSet. When initializing
DBSet from a database table, there's no need to use an FPTree with big
preallocated pool for the new entries that are added during recent sync.
Copy link

codecov bot commented Nov 11, 2024

Codecov Report

Attention: Patch coverage is 72.30769% with 36 lines in your changes missing coverage. Please review.

Project coverage is 79.9%. Comparing base (f711c61) to head (9e585e5).
Report is 15 commits behind head on develop.

Files with missing lines Patch % Lines
sql/database.go 54.8% 10 Missing and 4 partials ⚠️
sync2/multipeer/split_sync.go 63.6% 7 Missing and 1 partial ⚠️
sync2/dbset/dbset.go 73.9% 5 Missing and 1 partial ⚠️
sync2/multipeer/multipeer.go 73.3% 4 Missing ⚠️
sync2/rangesync/dumbset.go 40.0% 3 Missing ⚠️
sync2/multipeer/setsyncbase.go 95.6% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##           develop   #6446     +/-   ##
=========================================
- Coverage     79.9%   79.9%   -0.1%     
=========================================
  Files          352     352             
  Lines        46096   46148     +52     
=========================================
+ Hits         36865   36894     +29     
- Misses        7142    7162     +20     
- Partials      2089    2092      +3     

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


🚨 Try these New Features:

@spacemesh-bors spacemesh-bors bot changed the base branch from feature/long-db-conns to develop November 17, 2024 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant