mirror of
https://github.com/actix/actix-extras.git
synced 2025-06-30 03:44:27 +02:00
refactor edfault cpu pool
This commit is contained in:
@ -15,7 +15,7 @@ mod h1writer;
|
||||
mod h2;
|
||||
mod h2writer;
|
||||
pub(crate) mod helpers;
|
||||
mod settings;
|
||||
pub(crate) mod settings;
|
||||
pub(crate) mod shared;
|
||||
mod srv;
|
||||
pub(crate) mod utils;
|
||||
|
@ -1,11 +1,12 @@
|
||||
use std::cell::{Cell, RefCell, RefMut, UnsafeCell};
|
||||
use std::fmt::Write;
|
||||
use std::rc::Rc;
|
||||
use std::{fmt, mem, net};
|
||||
use std::{env, fmt, mem, net};
|
||||
|
||||
use bytes::BytesMut;
|
||||
use futures_cpupool::{Builder, CpuPool};
|
||||
use futures_cpupool::CpuPool;
|
||||
use http::StatusCode;
|
||||
use parking_lot::Mutex;
|
||||
use time;
|
||||
|
||||
use super::channel::Node;
|
||||
@ -15,6 +16,26 @@ use super::KeepAlive;
|
||||
use body::Body;
|
||||
use httpresponse::{HttpResponse, HttpResponseBuilder, HttpResponsePool};
|
||||
|
||||
/// Env variable for default cpu pool size
|
||||
const ENV_CPU_POOL_VAR: &str = "ACTIX_CPU_POOL";
|
||||
|
||||
lazy_static! {
|
||||
pub(crate) static ref DEFAULT_CPUPOOL: Mutex<CpuPool> = {
|
||||
let default = match env::var(ENV_CPU_POOL_VAR) {
|
||||
Ok(val) => {
|
||||
if let Ok(val) = val.parse() {
|
||||
val
|
||||
} else {
|
||||
error!("Can not parse ACTIX_CPU_POOL value");
|
||||
20
|
||||
}
|
||||
}
|
||||
Err(_) => 20,
|
||||
};
|
||||
Mutex::new(CpuPool::new(default))
|
||||
};
|
||||
}
|
||||
|
||||
/// Various server settings
|
||||
pub struct ServerSettings {
|
||||
addr: Option<net::SocketAddr>,
|
||||
@ -106,7 +127,8 @@ impl ServerSettings {
|
||||
unsafe {
|
||||
let val = &mut *self.cpu_pool.get();
|
||||
if val.is_none() {
|
||||
*val = Some(Builder::new().pool_size(2).create());
|
||||
let pool = DEFAULT_CPUPOOL.lock().clone();
|
||||
*val = Some(pool);
|
||||
}
|
||||
val.as_ref().unwrap()
|
||||
}
|
||||
|
Reference in New Issue
Block a user