Skip to content

Commit

Permalink
Set max number of connections for peer db (#2506)
Browse files Browse the repository at this point in the history
Use max_peers value for that if set. By default LMDB limit is 126, which is not enough for less than 200 peers on my node.
  • Loading branch information
hashmap authored and ignopeverell committed Feb 1, 2019
1 parent 987fa03 commit 267c706
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
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

0 comments on commit 267c706

Please sign in to comment.