|
@@ -1,10 +1,9 @@
|
|
|
#[global_allocator]
|
|
|
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
|
|
|
|
|
|
-use std::{future::Future, io, pin::Pin, task::Context, task::Poll};
|
|
|
+use std::{future::Future, io, pin::Pin, task::ready, task::Context, task::Poll};
|
|
|
|
|
|
-use ntex::util::{ready, PoolId, Ready};
|
|
|
-use ntex::{fn_service, http::h1, io::Io, io::RecvError};
|
|
|
+use ntex::{fn_service, http::h1, io::Io, io::RecvError, util::PoolId};
|
|
|
use sonic_rs::Serialize;
|
|
|
|
|
|
mod utils;
|
|
@@ -79,13 +78,10 @@ impl Future for App {
|
|
|
async fn main() -> io::Result<()> {
|
|
|
println!("Started 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));
|
|
|
-
|
|
|
// start http server
|
|
|
ntex::server::build()
|
|
|
.backlog(1024)
|
|
|
+ .enable_affinity()
|
|
|
.bind("techempower", "0.0.0.0:8080", |cfg| {
|
|
|
cfg.memory_pool(PoolId::P1);
|
|
|
PoolId::P1.set_read_params(65535, 2048);
|
|
@@ -96,17 +92,6 @@ async fn main() -> io::Result<()> {
|
|
|
codec: h1::Codec::default(),
|
|
|
})
|
|
|
})?
|
|
|
- .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()
|
|
|
.await
|
|
|
}
|