Skip to content
This repository was archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
⚡ Randomize orchestrator selection
Browse files Browse the repository at this point in the history
  • Loading branch information
TilBlechschmidt committed Mar 25, 2021
1 parent c3923d6 commit 895c3c3
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion core/src/services/manager/tasks/create_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use chrono::offset::Utc;
use futures::TryFutureExt;
use lazy_static::lazy_static;
use log::{debug, warn};
use rand::seq::SliceRandom;
use rand::thread_rng;
use redis::{aio::ConnectionLike, pipe, AsyncCommands};
use regex::Regex;
use std::time::Duration;
Expand Down Expand Up @@ -187,7 +189,7 @@ mod subtasks {
) -> Result<(), RequestError> {
let queue_timeout = Timeout::Queue.get(con).await;

let queues: Vec<String> = helpers::match_orchestrators(con, capabilities)
let mut queues: Vec<String> = helpers::match_orchestrators(con, capabilities)
.await?
.iter()
.map(|orchestrator_id| keys::orchestrator::slots::available(orchestrator_id))
Expand All @@ -197,6 +199,9 @@ mod subtasks {
return Err(RequestError::NoOrchestratorAvailable);
}

// Ensure some degree of load balancing for orchestrators
queues.shuffle(&mut thread_rng());

let response: Option<(String, String)> = con
.blpop(queues, queue_timeout)
.map_err(RequestError::RedisError)
Expand Down

0 comments on commit 895c3c3

Please sign in to comment.