Skip to content

Commit

Permalink
Set default open files to 5000
Browse files Browse the repository at this point in the history
  • Loading branch information
Phuong Nguyen committed Nov 15, 2022
1 parent 07b9c03 commit 29e446b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -339,3 +339,4 @@ These environment variables will be useful if there was ever a snag hit:

- `NEAR_RPC_TIMEOUT_SECS`: The default is 10 seconds, but this is the amount of time beforing timing out waiting for a RPC service when talking to the sandbox or any other network such as testnet.
- `NEAR_SANDBOX_BIN_PATH`: Set this to our own prebuilt `neard-sandbox` bin path if we want to use a non-default version of the sandbox or configure nearcore with our own custom features that we want to test in workspaces.
- `NEAR_SANDBOX_MAX_FILES`: Set the max amount of files that can be opened at a time in the sandbox. If none is specified, the default size of 5000 will be used. The actual near chain will use over 10,000 in pratice, but for testing this should be much lower since we do not have a constantly running blockchain unless our tests take up that much time.
19 changes: 14 additions & 5 deletions workspaces/src/network/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ impl SandboxServer {
.map_err(|e| SandboxErrorCode::InitFailure.custom(e))?;
info!(target: "workspaces", "sandbox init: {:?}", output);

// Override `store` in config.json to alleviate issues with having too many files open:
override_store_config(&home_dir)?;

let child = sandbox::run(&home_dir, self.rpc_port, self.net_port)
Expand Down Expand Up @@ -113,6 +114,13 @@ fn supress_sandbox_logs_if_required() {
}

fn override_store_config(home_dir: &PathBuf) -> Result<()> {
let max_files = match std::env::var("NEAR_SANDBOX_MAX_FILES") {
Ok(val) => (&val)
.parse::<u64>()
.map_err(|err| ErrorKind::DataConversion.custom(err))?,
Err(_err) => 5000,
};

let config =
File::open(home_dir.join("config.json")).map_err(|err| ErrorKind::Io.custom(err))?;
let config = BufReader::new(config);
Expand All @@ -125,17 +133,18 @@ fn override_store_config(home_dir: &PathBuf) -> Result<()> {
let (key, val) = entry.remove_entry();
let mut val: HashMap<String, serde_json::Value> =
serde_json::from_value(val).map_err(|err| ErrorKind::DataConversion.custom(err))?;
val.insert("max_open_files".into(), 10.into());
val.insert("max_open_files".into(), max_files.into());

config.insert(
key,
serde_json::to_value(val).map_err(|err| ErrorKind::DataConversion.custom(err))?,
);
}
_ => panic!("Store not present"),
// Entry::Vacant(entry) => {
// entry.insert(serde_json::json!({}));
// }
Entry::Vacant(entry) => {
entry.insert(serde_json::json!({
"max_open_files": max_files,
}));
}
}

Ok(())
Expand Down

0 comments on commit 29e446b

Please sign in to comment.