Skip to content

Commit

Permalink
feat(server): use the num_cpus crate to configure the number of threa…
Browse files Browse the repository at this point in the history
…ds for the pool
  • Loading branch information
gsquire committed Oct 19, 2017
1 parent e784b0f commit c8255a6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ travis-ci = { repository = "steveklabnik/simple-server" }
http = "0.1.0"
httparse = "1.2.3"
log = "0.3"
num_cpus = "1"
scoped_threadpool = "0.1.7"

[dev-dependencies]
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ extern crate log;

extern crate http;
extern crate httparse;
extern crate num_cpus;
extern crate scoped_threadpool;

pub use http::Request;
Expand Down Expand Up @@ -117,7 +118,8 @@ impl Server {
/// }
/// ```
pub fn listen(&self, host: &str, port: &str) {
let mut pool = Pool::new(4);
let logical_cores = num_cpus::get() as u32;
let mut pool = Pool::new(logical_cores);
let listener =
TcpListener::bind(format!("{}:{}", host, port)).expect("Error starting the server.");

Expand Down

0 comments on commit c8255a6

Please sign in to comment.