Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set max number of connections for peer db #2506

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion servers/src/grin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,11 @@ impl Server {
config.clone(),
));

let peer_db_env = Arc::new(store::new_named_env(config.db_root.clone(), "peer".into()));
let peer_db_env = Arc::new(store::new_named_env(
config.db_root.clone(),
"peer".into(),
config.p2p_config.peer_max_count,
));
let p2p_server = Arc::new(p2p::Server::new(
peer_db_env,
config.p2p_config.capabilities,
Expand Down
9 changes: 7 additions & 2 deletions store/src/lmdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ pub fn option_to_not_found<T>(res: Result<Option<T>, Error>, field_name: &str) -
/// Be aware of transactional semantics in lmdb
/// (transactions are per environment, not per database).
pub fn new_env(path: String) -> lmdb::Environment {
new_named_env(path, "lmdb".into())
new_named_env(path, "lmdb".into(), None)
}

/// TODO - We probably need more flexibility here, 500GB probably too big for peers...
/// Create a new LMDB env under the provided directory with the provided name.
pub fn new_named_env(path: String, name: String) -> lmdb::Environment {
pub fn new_named_env(path: String, name: String, max_readers: Option<u32>) -> lmdb::Environment {
let full_path = [path, name].join("/");
fs::create_dir_all(&full_path)
.expect("Unable to create directory 'db_root' to store chain_data");
Expand All @@ -78,6 +78,11 @@ pub fn new_named_env(path: String, name: String) -> lmdb::Environment {
.unwrap_or_else(|e| {
panic!("Unable to allocate LMDB space: {:?}", e);
});
if let Some(max_readers) = max_readers {
env_builder
.set_maxreaders(max_readers)
.expect("Unable set max_readers");
}
unsafe {
env_builder
.open(&full_path, lmdb::open::NOTLS, 0o600)
Expand Down