1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-11-20 08:31:09 +00:00

use one default cpu pool for StaticFiles #174

This commit is contained in:
Nikolay Kim 2018-04-12 15:50:20 -07:00
parent 0b01884fca
commit 2ca0ea70c4
2 changed files with 13 additions and 1 deletions

View file

@ -7,6 +7,8 @@
* Fix end-of-stream handling in parse_payload #173 * Fix end-of-stream handling in parse_payload #173
* Fix StaticFiles generate a lot of threads #174
## 0.5.0 (2018-04-10) ## 0.5.0 (2018-04-10)

View file

@ -6,6 +6,7 @@ use std::fs::{File, DirEntry, Metadata};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut};
use std::time::{SystemTime, UNIX_EPOCH}; use std::time::{SystemTime, UNIX_EPOCH};
use std::sync::Mutex;
#[cfg(unix)] #[cfg(unix)]
use std::os::unix::fs::MetadataExt; use std::os::unix::fs::MetadataExt;
@ -409,6 +410,10 @@ pub struct StaticFiles<S> {
_follow_symlinks: bool, _follow_symlinks: bool,
} }
lazy_static!{
static ref DEFAULT_CPUPOOL: Mutex<CpuPool> = Mutex::new(CpuPool::new(20));
}
impl<S: 'static> StaticFiles<S> { impl<S: 'static> StaticFiles<S> {
/// Create new `StaticFiles` instance for specified base directory. /// Create new `StaticFiles` instance for specified base directory.
@ -430,12 +435,17 @@ impl<S: 'static> StaticFiles<S> {
} }
}; };
// use default CpuPool
let pool = {
DEFAULT_CPUPOOL.lock().unwrap().clone()
};
StaticFiles { StaticFiles {
directory: dir, directory: dir,
accessible: access, accessible: access,
index: None, index: None,
show_index: false, show_index: false,
cpu_pool: CpuPool::new(40), cpu_pool: pool,
default: Box::new(WrapHandler::new( default: Box::new(WrapHandler::new(
|_| HttpResponse::new(StatusCode::NOT_FOUND))), |_| HttpResponse::new(StatusCode::NOT_FOUND))),
_chunk_size: 0, _chunk_size: 0,