Skip to content

Commit

Permalink
Fix and customization of internal queue size
Browse files Browse the repository at this point in the history
  • Loading branch information
Flowneee committed Sep 23, 2023
1 parent 02546a3 commit 3ce3801
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [0.0.9] - 2023-09-23
### Added
- `dispatcher_internal_queue_size` parameter to builder, allowing to customize size of internal queue between dispatcher and connection.

### Fixed
- Increased size of internal queue between dispatcher and connection, which should significantly increase performance (previously it was degrading rapidly with a lot of parallel requests).


## [0.0.8] - 2023-09-05
### Added
- Data-manipulation operations (insert, update, upsert, replace, delete) now return `DmoResponse` with row, returned by operation ([#7](https://github.com/Flowneee/tarantool-rs/issues/7));
Expand Down
8 changes: 1 addition & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "tarantool-rs"
description = "Asyncronous tokio-based client for Tarantool"
version = "0.0.8"
version = "0.0.9"
edition = "2021"
authors = ["Andrey Kononov [email protected]"]
license = "MIT"
Expand Down Expand Up @@ -40,7 +40,6 @@ serde_json = "1"
tokio = { version = "1", features = ["full"] }
tracing-test = { version = "0.2", features = ["no-env-filter"] }
tarantool-test-container = { path = "tarantool-test-container" }
rusty_tarantool = "*"

[[example]]
name = "cli_client"
Expand All @@ -61,8 +60,3 @@ harness = false
[[bench]]
name = "compare"
harness = false

[workspace]
members = [
"tarantool-test-container",
]
20 changes: 19 additions & 1 deletion src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ use crate::{
transport::Dispatcher,
};

const DEFAULT_DISPATCHER_INTERNAL_QUEUE_SIZE: usize = 500;
const DEFAULT_SQL_STATEMENT_CACHE_CAPACITY: usize = 500;

/// Interval parameters for background reconnection.
#[derive(Clone, Debug, PartialEq)]
pub enum ReconnectInterval {
Expand Down Expand Up @@ -64,6 +67,7 @@ pub struct ConnectionBuilder {
connect_timeout: Option<Duration>,
reconnect_interval: Option<ReconnectInterval>,
sql_statement_cache_capacity: usize,
dispatcher_internal_queue_size: usize,
}

impl Default for ConnectionBuilder {
Expand All @@ -76,7 +80,8 @@ impl Default for ConnectionBuilder {
transaction_isolation_level: Default::default(),
connect_timeout: None,
reconnect_interval: Some(ReconnectInterval::default()),
sql_statement_cache_capacity: 100,
sql_statement_cache_capacity: DEFAULT_SQL_STATEMENT_CACHE_CAPACITY,
dispatcher_internal_queue_size: DEFAULT_DISPATCHER_INTERNAL_QUEUE_SIZE,
}
}
}
Expand Down Expand Up @@ -188,4 +193,17 @@ impl ConnectionBuilder {
self.sql_statement_cache_capacity = capacity;
self
}

/// Sets size of the internal queue between connection and dispatcher.
///
/// This queue contains all requests, made from [`Connection`]s/[`Stream`]s/etc.
/// Increasing its size can help if you have a lot of requests, made concurrently
/// and frequently, however this will increase memory consumption slightly.
///
/// By default set to 500, which should be reasonable compromise between memory
/// (about 50 KB) and performance.
pub fn dispatcher_internal_queue_size(&mut self, size: usize) -> &mut Self {
self.dispatcher_internal_queue_size = size;
self
}
}

0 comments on commit 3ce3801

Please sign in to comment.