Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
conduwuit
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
🥺
conduwuit
Commits
7e579f8d
Commit
7e579f8d
authored
3 years ago
by
Jonathan de Jong
Browse files
Options
Downloads
Patches
Plain Diff
change to fraction-based approach
parent
0f2dc9a2
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/database.rs
+9
-10
9 additions, 10 deletions
src/database.rs
src/database/abstraction/sqlite.rs
+7
-11
7 additions, 11 deletions
src/database/abstraction/sqlite.rs
with
16 additions
and
21 deletions
src/database.rs
+
9
−
10
View file @
7e579f8d
...
...
@@ -53,8 +53,8 @@ pub struct Config {
sqlite_wal_clean_second_interval
:
u32
,
#[serde(default
=
"default_sqlite_wal_clean_second_timeout"
)]
sqlite_wal_clean_second_timeout
:
u32
,
#[serde(default
=
"default_sqlite_spillover_reap_
chunk
"
)]
sqlite_spillover_reap_
chunk
:
u32
,
#[serde(default
=
"default_sqlite_spillover_reap_
fraction
"
)]
sqlite_spillover_reap_
fraction
:
u32
,
#[serde(default
=
"default_sqlite_spillover_reap_interval_secs"
)]
sqlite_spillover_reap_interval_secs
:
u32
,
#[serde(default
=
"default_max_request_size"
)]
...
...
@@ -125,12 +125,12 @@ fn default_sqlite_wal_clean_second_timeout() -> u32 {
2
}
fn
default_sqlite_spillover_reap_
chunk
()
->
u32
{
5
fn
default_sqlite_spillover_reap_
fraction
()
->
u32
{
2
}
fn
default_sqlite_spillover_reap_interval_secs
()
->
u32
{
1
0
6
0
}
fn
default_max_request_size
()
->
u32
{
...
...
@@ -558,10 +558,9 @@ pub fn flush_wal(&self) -> Result<()> {
#[cfg(feature
=
"sqlite"
)]
pub
async
fn
start_spillover_reap_task
(
engine
:
Arc
<
Engine
>
,
config
:
&
Config
)
{
let
chunk_size
=
match
config
.sqlite_spillover_reap_chunk
{
0
=>
None
,
// zero means no chunking, reap everything
a
@
_
=>
Some
(
a
),
};
use
std
::
convert
::
TryInto
;
let
fraction_factor
=
config
.sqlite_spillover_reap_fraction
.max
(
1
)
.try_into
()
.unwrap
(
/* We just converted it to be at least 1 */
);
let
interval_secs
=
config
.sqlite_spillover_reap_interval_secs
as
u64
;
let
weak
=
Arc
::
downgrade
(
&
engine
);
...
...
@@ -577,7 +576,7 @@ pub async fn start_spillover_reap_task(engine: Arc<Engine>, config: &Config) {
i
.tick
()
.await
;
if
let
Some
(
arc
)
=
Weak
::
upgrade
(
&
weak
)
{
arc
.reap_spillover
(
chunk_size
);
arc
.reap_spillover
_by_fraction
(
fraction_factor
);
}
else
{
break
;
}
...
...
This diff is collapsed.
Click to expand it.
src/database/abstraction/sqlite.rs
+
7
−
11
View file @
7e579f8d
...
...
@@ -9,6 +9,7 @@
use
std
::{
collections
::
BTreeMap
,
future
::
Future
,
num
::
NonZeroU32
,
ops
::
Deref
,
path
::{
Path
,
PathBuf
},
pin
::
Pin
,
...
...
@@ -241,19 +242,14 @@ pub fn flush_wal(self: &Arc<Self>) -> Result<()> {
.map_err
(
Into
::
into
)
}
// Reaps (at most) X amount of connections if `amount` is Some.
// If none, reaps all currently idle connections.
pub
fn
reap_spillover
(
&
self
,
amount
:
Option
<
u32
>
)
{
// Reaps (at most) (.len() / `fraction`) (rounded down, min 1) connections.
pub
fn
reap_spillover_by_fraction
(
&
self
,
fraction
:
NonZeroU32
)
{
let
mut
reaped
=
0
;
if
let
Some
(
amount
)
=
amount
{
for
_
in
0
..
amount
{
if
self
.pool.spills
.try_take
()
.is_some
()
{
reaped
+=
1
;
}
}
}
else
{
while
let
Some
(
_
)
=
self
.pool.spills
.try_take
()
{
let
amount
=
((
self
.pool.spills
.1
.len
()
as
u32
)
/
fraction
)
.max
(
1
);
for
_
in
0
..
amount
{
if
self
.pool.spills
.try_take
()
.is_some
()
{
reaped
+=
1
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment