Skip to content
This repository was archived by the owner on Feb 6, 2026. It is now read-only.

Commit b78cfaf

Browse files
committed
feat(veritech): limit request pulling to pool availability
1 parent c31dffe commit b78cfaf

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

‎lib/si-pool-noodle/src/pool_noodle.rs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ where
194194
Arc::clone(&self.0)
195195
}
196196

197+
/// Returns the admission semaphore for external backpressure control.
198+
pub fn admission_semaphore(&self) -> Arc<Semaphore> {
199+
self.inner().admission_semaphore.clone()
200+
}
201+
197202
/// This will attempt to get a ready, healthy instance from the pool.
198203
/// If there are no instances, it will give the main loop a chance to fill the pool and try
199204
/// again. It will throw an error if there are no available instances after enough retries.
@@ -281,6 +286,7 @@ where
281286
spec: S,
282287
queue_rx: Mutex<Receiver<PoolNoodleTaskType<I, S>>>,
283288
queue_tx: Sender<PoolNoodleTaskType<I, S>>,
289+
admission_semaphore: Arc<Semaphore>,
284290
}
285291

286292
impl<I, E, S> PoolNoodleInner<I, S>
@@ -305,6 +311,7 @@ where
305311
spec: config.spec,
306312
queue_rx: queue_rx.into(),
307313
queue_tx,
314+
admission_semaphore: Arc::new(Semaphore::new(0)),
308315
}
309316
}
310317

@@ -405,6 +412,7 @@ where
405412
warn!("failed to push to ready queue: {}", id);
406413
}
407414
metric!(counter.pool_noodle.ready = 1);
415+
self.admission_semaphore.add_permits(1);
408416
}
409417
}
410418

‎lib/veritech-server/src/server.rs‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ impl Server {
195195

196196
let inner_future = Self::build_app(
197197
metadata.clone(),
198-
config.veritech_requests_concurrency_limit(),
199198
cyclone_pool,
200199
Arc::new(decryption_key),
201200
config.cyclone_client_execution_timeout(),
@@ -268,7 +267,6 @@ impl Server {
268267
#[allow(clippy::too_many_arguments)]
269268
async fn build_app(
270269
metadata: Arc<ServerMetadata>,
271-
concurrency_limit: usize,
272270
cyclone_pool: PoolNoodle<LocalUdsInstance, LocalUdsInstanceSpec>,
273271
decryption_key: Arc<VeritechDecryptionKey>,
274272
cyclone_client_execution_timeout: Duration,
@@ -299,6 +297,8 @@ impl Server {
299297
.await?
300298
};
301299

300+
let admission_semaphore = cyclone_pool.admission_semaphore();
301+
302302
let state = AppState::new(
303303
metadata,
304304
cyclone_pool,
@@ -324,9 +324,12 @@ impl Server {
324324
.service(handlers::process_request.with_state(state))
325325
.map_response(Response::into_response);
326326

327-
let inner =
328-
naxum::serve_with_incoming_limit(incoming, app.into_make_service(), concurrency_limit)
329-
.with_graceful_shutdown(naxum::wait_on_cancelled(token));
327+
let inner = naxum::serve_with_external_semaphore(
328+
incoming,
329+
app.into_make_service(),
330+
admission_semaphore,
331+
)
332+
.with_graceful_shutdown(naxum::wait_on_cancelled(token));
330333

331334
Ok(Box::new(inner.into_future()))
332335
}

0 commit comments

Comments
 (0)