|
@@ -3,11 +3,9 @@
|
|
|
static GLOBAL: snmalloc_rs::SnMalloc = snmalloc_rs::SnMalloc;
|
|
|
// static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
|
|
|
|
|
|
-use std::sync::{Arc, Mutex};
|
|
|
-
|
|
|
use ntex::http::header::{CONTENT_TYPE, SERVER};
|
|
|
use ntex::http::{HttpService, KeepAlive, Request, Response, StatusCode};
|
|
|
-use ntex::service::{Service, ServiceFactory, ServiceCtx};
|
|
|
+use ntex::service::{Service, ServiceCtx, ServiceFactory};
|
|
|
use ntex::web::{Error, HttpResponse};
|
|
|
use ntex::{time::Seconds, util::BoxFuture, util::PoolId};
|
|
|
|
|
@@ -89,22 +87,8 @@ impl ServiceFactory<Request> for AppFactory {
|
|
|
async fn main() -> std::io::Result<()> {
|
|
|
println!("Starting http server: 127.0.0.1:8080");
|
|
|
|
|
|
- let cores = core_affinity::get_core_ids().unwrap();
|
|
|
- let total_cores = cores.len();
|
|
|
- let cores = Arc::new(Mutex::new(cores));
|
|
|
-
|
|
|
ntex::server::build()
|
|
|
.backlog(1024)
|
|
|
- .configure(move |cfg| {
|
|
|
- let cores = cores.clone();
|
|
|
- cfg.on_worker_start(move |_| {
|
|
|
- if let Some(core) = cores.lock().unwrap().pop() {
|
|
|
- // Pin this worker to a single CPU core.
|
|
|
- core_affinity::set_for_current(core);
|
|
|
- }
|
|
|
- std::future::ready(Ok::<_, &'static str>(()))
|
|
|
- })
|
|
|
- })?
|
|
|
.bind("techempower", "0.0.0.0:8080", |cfg| {
|
|
|
cfg.memory_pool(PoolId::P1);
|
|
|
PoolId::P1.set_read_params(65535, 2048);
|
|
@@ -115,7 +99,7 @@ async fn main() -> std::io::Result<()> {
|
|
|
.client_timeout(Seconds(0))
|
|
|
.h1(AppFactory)
|
|
|
})?
|
|
|
- .workers(total_cores)
|
|
|
+ .workers(num_cpus::get_physical())
|
|
|
.run()
|
|
|
.await
|
|
|
}
|