make number of compute threads configurable
All checks were successful
Build / build (push) Successful in 1m15s
All checks were successful
Build / build (push) Successful in 1m15s
This commit is contained in:
@ -1,4 +1,7 @@
|
||||
use std::env;
|
||||
use std::{
|
||||
env,
|
||||
sync::atomic::{AtomicUsize, Ordering},
|
||||
};
|
||||
|
||||
use axum::{
|
||||
Router,
|
||||
@ -21,6 +24,8 @@ use tokio::{
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
static THREADS: AtomicUsize = AtomicUsize::new(1);
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
env_logger::init();
|
||||
@ -32,6 +37,17 @@ async fn main() {
|
||||
.route("/move", post(get_move))
|
||||
.route("/end", post(end));
|
||||
|
||||
let threads = env::var("THREADS")
|
||||
.ok()
|
||||
.and_then(|threads| {
|
||||
threads
|
||||
.parse()
|
||||
.inspect_err(|err| error!("Unable to parse number of threads: {err}"))
|
||||
.ok()
|
||||
})
|
||||
.unwrap_or(1);
|
||||
THREADS.store(threads, Ordering::Relaxed);
|
||||
|
||||
debug!("Creating listener");
|
||||
let port = env::var("PORT").unwrap_or_else(|_| "8000".into());
|
||||
let listener = TcpListener::bind(format!("0.0.0.0:{port}")).await.unwrap();
|
||||
@ -104,7 +120,7 @@ async fn get_move(request: Json<Request>) -> response::Json<Response> {
|
||||
_ => score_standard,
|
||||
};
|
||||
|
||||
let action_futures = (0..3).map(|_| {
|
||||
let action_futures = (0..THREADS.load(Ordering::Relaxed)).map(|_| {
|
||||
let request = request.clone();
|
||||
let board = board.clone();
|
||||
let mut rng = SmallRng::from_os_rng();
|
||||
|
Reference in New Issue
Block a user