Skip to content

Commit

Permalink
feat(query): get the system open file limits and set
Browse files Browse the repository at this point in the history
  • Loading branch information
TszKitLo40 committed Oct 26, 2022
1 parent d180992 commit 39fa62c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/binaries/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ databend-query = { path = "../query/service" }
# Crates.io dependencies
anyhow = { workspace = true }
clap = { workspace = true }
limits-rs = "0.1.0"
openraft = { workspace = true }
sentry = "0.27.0"
serde = { workspace = true }
serde_json = { workspace = true }
sysinfo = "0.26.5"
tokio-stream = "0.1.10"
tonic = "0.8.1"
tracing = "0.1.36"
Expand Down
25 changes: 25 additions & 0 deletions src/binaries/query/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ use databend_query::servers::MySQLHandler;
use databend_query::servers::Server;
use databend_query::servers::ShutdownHandle;
use databend_query::GlobalServices;
use limits_rs::get_own_limits;
use tracing::info;
use tracing::warn;

#[databend_main]
async fn main(_global_tracker: Arc<RuntimeTracker>) -> common_exception::Result<()> {
Expand Down Expand Up @@ -73,6 +75,10 @@ async fn main(_global_tracker: Arc<RuntimeTracker>) -> common_exception::Result<
init_default_metrics_recorder();
set_panic_hook();

#[cfg(not(target_os = "macos"))]
// Try to set max open files.
try_set_max_open_files();

GlobalServices::init(conf.clone()).await?;
let mut shutdown_handle = ShutdownHandle::create()?;

Expand Down Expand Up @@ -251,3 +257,22 @@ fn run_cmd(conf: &Config) -> bool {

true
}

#[cfg(not(target_os = "macos"))]
fn try_set_max_open_files() {
let limits = get_own_limits().unwrap();
let max_open_files_limit = limits.max_open_files.soft;
if let Some(max_open_files) = max_open_files_limit {
if max_open_files < 65535 {
let set = sysinfo::set_open_files_limit(max_open_files.try_into().unwrap());
match set {
true => {
warn!("Open files limit has been set to {}", max_open_files);
}
false => {
warn!("Open files limit set to {} failed", max_open_files);
}
}
}
}
}

0 comments on commit 39fa62c

Please sign in to comment.