Skip to content

Commit

Permalink
Revert rlimit customization changes (those are overkill)
Browse files Browse the repository at this point in the history
Signed-off-by: Valerian Saliou <valerian@valeriansaliou.name>
  • Loading branch information
valeriansaliou committed Mar 27, 2019
1 parent 0c8d6ad commit f6400c6
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 34 deletions.
1 change: 0 additions & 1 deletion CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Sonic Configuration
**[server]**

* `log_level` (type: _string_, allowed: `debug`, `info`, `warn`, `error`, default: `error`) — Verbosity of logging, set it to `error` in production
* `limit_open_files` (type: _integer_, allowed: numbers, default: `1024`) — Maximum number of open files for the process (raise this limit if you run a large deployment; check that your system security limits allow this)

**[channel]**

Expand Down
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ lazy_static = "1.3"
serde = "1.0"
serde_derive = "1.0"
graceful = "0.1"
libc = "0.2"
rand = "0.6"
unicode-segmentation = "1.2"
rocksdb = { version = "0.12", features = ["lz4"] }
Expand Down
2 changes: 0 additions & 2 deletions config.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

log_level = "error"

limit_open_files = 1024


[channel]

Expand Down
3 changes: 0 additions & 3 deletions src/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ pub struct Config {
pub struct ConfigServer {
#[serde(default = "defaults::server_log_level")]
pub log_level: String,

#[serde(default = "defaults::server_limit_open_files")]
pub limit_open_files: u64,
}

#[derive(Deserialize)]
Expand Down
4 changes: 0 additions & 4 deletions src/config/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ pub fn server_log_level() -> String {
"error".to_string()
}

pub fn server_limit_open_files() -> u64 {
1024
}

pub fn channel_inet() -> SocketAddr {
"[::1]:1491".parse().unwrap()
}
Expand Down
23 changes: 1 addition & 22 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ extern crate fst_levenshtein;
extern crate fst_regex;
extern crate graceful;
extern crate hashbrown;
extern crate libc;
extern crate linked_hash_set;
extern crate rand;
extern crate regex_syntax;
Expand All @@ -42,7 +41,6 @@ mod stopwords;
mod store;
mod tasker;

use std::io;
use std::ops::Deref;
use std::str::FromStr;
use std::thread;
Expand Down Expand Up @@ -141,24 +139,6 @@ fn ensure_states() {
let (_, _) = (APP_ARGS.deref(), APP_CONF.deref());
}

fn ensure_limits() {
// Raise file descriptor limit for the process to the maximum allowed by the system
// Notice: this is required for large Sonic servers to open many FST files at once
let limit = libc::rlimit {
rlim_cur: APP_CONF.server.limit_open_files,
rlim_max: APP_CONF.server.limit_open_files,
};

unsafe {
if libc::setrlimit(libc::RLIMIT_NOFILE, &limit) != 0 {
panic!(
"failed setting open files limit: {}",
io::Error::last_os_error()
);
}
}
}

fn main() {
let _logger = ConfigLogger::init(
LevelFilter::from_str(&APP_CONF.server.log_level).expect("invalid log level"),
Expand All @@ -168,9 +148,8 @@ fn main() {

info!("starting up");

// Ensure all states & limits are bound
// Ensure all states are bound
ensure_states();
ensure_limits();

// Spawn tasker (background thread)
thread::spawn(spawn_tasker);
Expand Down

1 comment on commit f6400c6

@valeriansaliou
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found out that setting the NOFILE limit when starting Sonic via systemd succeeds at setting soft & hard rlimits.

Please sign in to comment.