Skip to content

Commit 20d2f9d

Browse files
committed
add SQLD_CONNECTION_CREATION_TIMEOUT_SEC and SQLD_DISABLE_INTELLIGENT_THROTTLING env vars
1 parent 2188b01 commit 20d2f9d

File tree

9 files changed

+44
-4
lines changed

9 files changed

+44
-4
lines changed

libsql-server/src/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ pub struct DbConfig {
101101
pub snapshot_at_shutdown: bool,
102102
pub encryption_config: Option<EncryptionConfig>,
103103
pub max_concurrent_requests: u64,
104+
pub disable_intelligent_throttling: bool,
105+
pub connection_creation_timeout: Option<Duration>,
104106
}
105107

106108
impl Default for DbConfig {
@@ -119,6 +121,8 @@ impl Default for DbConfig {
119121
snapshot_at_shutdown: false,
120122
encryption_config: None,
121123
max_concurrent_requests: 128,
124+
disable_intelligent_throttling: false,
125+
connection_creation_timeout: None,
122126
}
123127
}
124128
}

libsql-server/src/connection/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ pub trait MakeConnection: Send + Sync + 'static {
206206
timeout: Option<Duration>,
207207
max_total_response_size: u64,
208208
max_concurrent_requests: u64,
209+
disable_intelligent_throttling: bool,
209210
) -> MakeThrottledConnection<Self>
210211
where
211212
Self: Sized,
@@ -216,6 +217,7 @@ pub trait MakeConnection: Send + Sync + 'static {
216217
timeout,
217218
max_total_response_size,
218219
max_concurrent_requests,
220+
disable_intelligent_throttling,
219221
)
220222
}
221223

@@ -281,6 +283,7 @@ pub struct MakeThrottledConnection<F> {
281283
max_total_response_size: u64,
282284
waiters: AtomicUsize,
283285
max_concurrent_requests: u64,
286+
disable_intelligent_throttling: bool,
284287
}
285288

286289
impl<F> MakeThrottledConnection<F> {
@@ -290,6 +293,7 @@ impl<F> MakeThrottledConnection<F> {
290293
timeout: Option<Duration>,
291294
max_total_response_size: u64,
292295
max_concurrent_requests: u64,
296+
disable_intelligent_throttling: bool,
293297
) -> Self {
294298
Self {
295299
semaphore,
@@ -298,12 +302,16 @@ impl<F> MakeThrottledConnection<F> {
298302
max_total_response_size,
299303
waiters: AtomicUsize::new(0),
300304
max_concurrent_requests,
305+
disable_intelligent_throttling,
301306
}
302307
}
303308

304309
// How many units should be acquired from the semaphore,
305310
// depending on current memory pressure.
306311
fn units_to_take(&self) -> u32 {
312+
if self.disable_intelligent_throttling {
313+
return 1;
314+
}
307315
let total_response_size = crate::query_result_builder::TOTAL_RESPONSE_SIZE
308316
.load(std::sync::atomic::Ordering::Relaxed) as u64;
309317
if total_response_size * 2 > self.max_total_response_size {
@@ -522,6 +530,7 @@ pub mod test {
522530
Some(Duration::from_millis(100)),
523531
u64::MAX,
524532
u64::MAX,
533+
false,
525534
);
526535

527536
let mut conns = Vec::with_capacity(10);

libsql-server/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,8 @@ where
634634
max_concurrent_connections: Arc::new(Semaphore::new(self.max_concurrent_connections)),
635635
max_concurrent_requests: self.db_config.max_concurrent_requests,
636636
encryption_config: self.db_config.encryption_config.clone(),
637+
disable_intelligent_throttling: self.db_config.disable_intelligent_throttling,
638+
connection_creation_timeout: self.db_config.connection_creation_timeout,
637639
};
638640

639641
let (metastore_conn_maker, meta_store_wal_manager) =

libsql-server/src/main.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,13 @@ struct Cli {
248248
#[clap(long, default_value = "128", env = "SQLD_MAX_CONCURRENT_REQUESTS")]
249249
max_concurrent_requests: u64,
250250

251+
// disable throttling logic which adjust concurrency limits based on memory-pressure conditions
252+
#[clap(long, env = "SQLD_DISABLE_INTELLIGENT_THROTTLING")]
253+
disable_intelligent_throttling: bool,
254+
255+
#[clap(long, env = "SQLD_CONNECTION_CREATION_TIMEOUT_SEC")]
256+
connection_creation_timeout_sec: Option<u64>,
257+
251258
/// Allow meta store to recover config from filesystem from older version, if meta store is
252259
/// empty on startup
253260
#[clap(long, env = "SQLD_ALLOW_METASTORE_RECOVERY")]
@@ -421,6 +428,10 @@ fn make_db_config(config: &Cli) -> anyhow::Result<DbConfig> {
421428
snapshot_at_shutdown: config.snapshot_at_shutdown,
422429
encryption_config: encryption_config.clone(),
423430
max_concurrent_requests: config.max_concurrent_requests,
431+
disable_intelligent_throttling: config.disable_intelligent_throttling,
432+
connection_creation_timeout: config
433+
.connection_creation_timeout_sec
434+
.map(|x| Duration::from_secs(x)),
424435
})
425436
}
426437

libsql-server/src/namespace/configurator/helpers.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,12 @@ pub(super) async fn make_primary_connection_maker(
180180
.await?
181181
.throttled(
182182
base_config.max_concurrent_connections.clone(),
183-
Some(DB_CREATE_TIMEOUT),
183+
base_config
184+
.connection_creation_timeout
185+
.or(Some(DB_CREATE_TIMEOUT)),
184186
base_config.max_total_response_size,
185187
base_config.max_concurrent_requests,
188+
base_config.disable_intelligent_throttling,
186189
),
187190
);
188191

libsql-server/src/namespace/configurator/libsql_primary.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,12 @@ pub(super) async fn libsql_primary_common(
118118
}
119119
.throttled(
120120
base_config.max_concurrent_connections.clone(),
121-
Some(DB_CREATE_TIMEOUT),
121+
base_config
122+
.connection_creation_timeout
123+
.or(Some(DB_CREATE_TIMEOUT)),
122124
base_config.max_total_response_size,
123125
base_config.max_concurrent_requests,
126+
base_config.disable_intelligent_throttling,
124127
);
125128
let connection_maker = Arc::new(connection_maker);
126129

libsql-server/src/namespace/configurator/libsql_replica.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,12 @@ impl ConfigureNamespace for LibsqlReplicaConfigurator {
170170
)
171171
.throttled(
172172
self.base.max_concurrent_connections.clone(),
173-
Some(DB_CREATE_TIMEOUT),
173+
self.base
174+
.connection_creation_timeout
175+
.or(Some(DB_CREATE_TIMEOUT)),
174176
self.base.max_total_response_size,
175177
self.base.max_concurrent_requests,
178+
self.base.disable_intelligent_throttling,
176179
),
177180
);
178181

libsql-server/src/namespace/configurator/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ pub struct BaseNamespaceConfig {
4646
pub(crate) max_concurrent_connections: Arc<Semaphore>,
4747
pub(crate) max_concurrent_requests: u64,
4848
pub(crate) encryption_config: Option<EncryptionConfig>,
49+
pub(crate) disable_intelligent_throttling: bool,
50+
pub(crate) connection_creation_timeout: Option<Duration>,
4951
}
5052

5153
#[derive(Clone)]

libsql-server/src/namespace/configurator/replica.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,12 @@ impl ConfigureNamespace for ReplicaConfigurator {
253253
)
254254
.throttled(
255255
self.base.max_concurrent_connections.clone(),
256-
Some(DB_CREATE_TIMEOUT),
256+
self.base
257+
.connection_creation_timeout
258+
.or(Some(DB_CREATE_TIMEOUT)),
257259
self.base.max_total_response_size,
258260
self.base.max_concurrent_requests,
261+
self.base.disable_intelligent_throttling,
259262
),
260263
);
261264

0 commit comments

Comments
 (0)