|
@@ -6,7 +6,7 @@ use ntex::http::header::{CONTENT_TYPE, SERVER};
|
|
use ntex::http::{HttpService, KeepAlive, Request, Response, StatusCode};
|
|
use ntex::http::{HttpService, KeepAlive, Request, Response, StatusCode};
|
|
use ntex::service::{Service, ServiceCtx, ServiceFactory};
|
|
use ntex::service::{Service, ServiceCtx, ServiceFactory};
|
|
use ntex::web::{Error, HttpResponse};
|
|
use ntex::web::{Error, HttpResponse};
|
|
-use ntex::{time::Seconds, util::PoolId, util::Ready};
|
|
|
|
|
|
+use ntex::{time::Seconds, util::PoolId};
|
|
|
|
|
|
mod db;
|
|
mod db;
|
|
mod utils;
|
|
mod utils;
|
|
@@ -82,12 +82,9 @@ impl ServiceFactory<Request> for AppFactory {
|
|
async fn main() -> std::io::Result<()> {
|
|
async fn main() -> std::io::Result<()> {
|
|
println!("Starting http server: 127.0.0.1:8080");
|
|
println!("Starting http server: 127.0.0.1:8080");
|
|
|
|
|
|
- let cores = core_affinity::get_core_ids().unwrap();
|
|
|
|
- let total_cores = cores.len();
|
|
|
|
- let cores = std::sync::Arc::new(std::sync::Mutex::new(cores));
|
|
|
|
-
|
|
|
|
ntex::server::build()
|
|
ntex::server::build()
|
|
.backlog(1024)
|
|
.backlog(1024)
|
|
|
|
+ .enable_affinity()
|
|
.bind("techempower", "0.0.0.0:8080", |cfg| {
|
|
.bind("techempower", "0.0.0.0:8080", |cfg| {
|
|
cfg.memory_pool(PoolId::P1);
|
|
cfg.memory_pool(PoolId::P1);
|
|
PoolId::P1.set_read_params(65535, 2048);
|
|
PoolId::P1.set_read_params(65535, 2048);
|
|
@@ -100,17 +97,6 @@ async fn main() -> std::io::Result<()> {
|
|
.payload_read_rate(Seconds::ZERO, Seconds::ZERO, 0)
|
|
.payload_read_rate(Seconds::ZERO, Seconds::ZERO, 0)
|
|
.h1(AppFactory)
|
|
.h1(AppFactory)
|
|
})?
|
|
})?
|
|
- .configure(move |cfg| {
|
|
|
|
- let cores = cores.clone();
|
|
|
|
- cfg.on_worker_start(move |_| {
|
|
|
|
- if let Some(core) = cores.lock().unwrap().pop() {
|
|
|
|
- core_affinity::set_for_current(core);
|
|
|
|
- }
|
|
|
|
- Ready::<_, &str>::Ok(())
|
|
|
|
- });
|
|
|
|
- Ok(())
|
|
|
|
- })?
|
|
|
|
- .workers(total_cores)
|
|
|
|
.run()
|
|
.run()
|
|
.await
|
|
.await
|
|
}
|
|
}
|