@@ -287,6 +287,7 @@ pub(crate) struct ConnectionConfig {
287
287
pub ( crate ) authenticator : Option < Arc < dyn AuthenticatorProvider > > ,
288
288
pub ( crate ) address_translator : Option < Arc < dyn AddressTranslator > > ,
289
289
pub ( crate ) write_coalescing_delay : Option < WriteCoalescingDelay > ,
290
+ pub ( crate ) pending_request_channel_size : Option < usize > ,
290
291
291
292
pub ( crate ) keepalive_interval : Option < Duration > ,
292
293
pub ( crate ) keepalive_timeout : Option < Duration > ,
@@ -322,17 +323,44 @@ impl ConnectionConfig {
322
323
authenticator : self . authenticator . clone ( ) ,
323
324
address_translator : self . address_translator . clone ( ) ,
324
325
write_coalescing_delay : self . write_coalescing_delay . clone ( ) ,
326
+ pending_request_channel_size : self . pending_request_channel_size ,
327
+
325
328
keepalive_interval : self . keepalive_interval ,
326
329
keepalive_timeout : self . keepalive_timeout ,
327
330
tablet_sender : self . tablet_sender . clone ( ) ,
328
331
identity : self . identity . clone ( ) ,
329
332
}
330
333
}
334
+
335
+ /// Set the size of the pending request channel for each connection.
336
+ ///
337
+ /// # Arguments
338
+ ///
339
+ /// * `size` - The maximum number of pending requests per connection.
340
+ ///
341
+ /// # Notes
342
+ ///
343
+ /// - This is different from cpp-driver's implementation, which uses a per-RequestProcessor queue.
344
+ /// - The default is 2048, a balanced value between performance and memory usage.
345
+ /// - Adjust based on your specific workload and system resources.
346
+ ///
347
+ /// # Example
348
+ ///
349
+ /// ```
350
+ /// let session = SessionBuilder::new()
351
+ /// .connection_config(
352
+ /// ConnectionConfig::new()
353
+ /// .with_pending_request_channel_size(4096)
354
+ /// )
355
+ /// .build()
356
+ /// .await?;
357
+ /// ```
358
+ pub fn with_pending_request_channel_size ( mut self , size : usize ) -> Self {
359
+ self . pending_request_channel_size = Some ( size) ;
360
+ self
361
+ }
331
362
}
332
363
333
- /// Configuration used for new connections, customized for a specific endpoint.
334
- ///
335
- /// Created from [ConnectionConfig] using [ConnectionConfig::to_host_connection_config].
336
364
#[ derive( Clone ) ]
337
365
pub ( crate ) struct HostConnectionConfig {
338
366
pub ( crate ) local_ip_address : Option < IpAddr > ,
@@ -349,6 +377,7 @@ pub(crate) struct HostConnectionConfig {
349
377
pub ( crate ) authenticator : Option < Arc < dyn AuthenticatorProvider > > ,
350
378
pub ( crate ) address_translator : Option < Arc < dyn AddressTranslator > > ,
351
379
pub ( crate ) write_coalescing_delay : Option < WriteCoalescingDelay > ,
380
+ pub ( crate ) pending_request_channel_size : Option < usize > ,
352
381
353
382
pub ( crate ) keepalive_interval : Option < Duration > ,
354
383
pub ( crate ) keepalive_timeout : Option < Duration > ,
@@ -357,6 +386,13 @@ pub(crate) struct HostConnectionConfig {
357
386
pub ( crate ) identity : SelfIdentity < ' static > ,
358
387
}
359
388
389
+ #[ cfg( test) ]
390
+ impl HostConnectionConfig {
391
+ fn is_tls ( & self ) -> bool {
392
+ self . tls_config . is_some ( )
393
+ }
394
+ }
395
+
360
396
#[ cfg( test) ]
361
397
impl Default for HostConnectionConfig {
362
398
fn default ( ) -> Self {
@@ -382,6 +418,7 @@ impl Default for HostConnectionConfig {
382
418
tablet_sender : None ,
383
419
384
420
identity : SelfIdentity :: default ( ) ,
421
+ pending_request_channel_size : Some ( 2048 ) ,
385
422
}
386
423
}
387
424
}
@@ -411,19 +448,11 @@ impl Default for ConnectionConfig {
411
448
tablet_sender : None ,
412
449
413
450
identity : SelfIdentity :: default ( ) ,
451
+ pending_request_channel_size : Some ( 2048 ) ,
414
452
}
415
453
}
416
454
}
417
455
418
- impl HostConnectionConfig {
419
- fn is_tls ( & self ) -> bool {
420
- self . tls_config . is_some ( )
421
- }
422
- }
423
-
424
- // Used to listen for fatal error in connection
425
- pub ( crate ) type ErrorReceiver = tokio:: sync:: oneshot:: Receiver < ConnectionError > ;
426
-
427
456
impl Connection {
428
457
// Returns new connection and ErrorReceiver which can be used to wait for a fatal error
429
458
/// Opens a connection and makes it ready to send/receive CQL frames on it,
@@ -451,7 +480,7 @@ impl Connection {
451
480
}
452
481
453
482
// TODO: What should be the size of the channel?
454
- let ( sender, receiver) = mpsc:: channel ( 1024 ) ;
483
+ let ( sender, receiver) = mpsc:: channel ( config . pending_request_channel_size . unwrap_or ( 1024 ) ) ;
455
484
let ( error_sender, error_receiver) = tokio:: sync:: oneshot:: channel ( ) ;
456
485
// Unbounded because it allows for synchronous pushes
457
486
let ( orphan_notification_sender, orphan_notification_receiver) = mpsc:: unbounded_channel ( ) ;
0 commit comments