Skip to content

Commit ad7c150

Browse files
committed
invoker set
1 parent 4183203 commit ad7c150

7 files changed

Lines changed: 242 additions & 201 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/judge/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ hyper = "0.13.7"
4848
futures-util = "0.3.5"
4949
event-listener = "2.4.0"
5050
async-channel = "1.4.2"
51+
parking_lot = "0.11.0"
5152

5253
[features]
5354
k8s = ["kube", "k8s-openapi"]

src/judge/src/controller.rs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub trait JudgeResponseCallbacks: Send + Sync {
7474

7575
#[derive(Clone)]
7676
pub struct Controller {
77-
invoker_set: Arc<InvokerSet>,
77+
invoker_set: InvokerSet,
7878
problem_loader: Arc<problem_loader::Loader>,
7979
toolchains_dir: Arc<Path>,
8080
_config: Arc<crate::config::JudgeConfig>,
@@ -102,15 +102,17 @@ impl Controller {
102102
None => get_num_cpus(),
103103
};
104104
info!("Using {} workers", worker_count);
105-
let mut invoker_set =
106-
InvokerSet::new(&config).context("failed to initialize InvokerSet")?;
107-
for _ in 0..worker_count {
108-
invoker_set
109-
.add_managed_worker()
110-
.await
111-
.context("failed to start a worker")?;
112-
}
113-
let invoker_set = Arc::new(invoker_set);
105+
106+
let invoker_set = {
107+
let mut builder = InvokerSet::builder(&config);
108+
for _ in 0..worker_count {
109+
builder
110+
.add_managed_worker()
111+
.await
112+
.context("failed to start a worker")?;
113+
}
114+
builder.build()
115+
};
114116

115117
let temp_dir = tempfile::TempDir::new().context("can not find temporary dir")?;
116118

@@ -158,10 +160,13 @@ impl Controller {
158160

159161
debug!(lowered_judge_request = ?low_req, "created a lowered judge request");
160162

161-
// TODO currently the process of finding a worker is unfair
162-
// we should fix it e.g. using a semaphore which permits finding
163-
// worker.
164-
let worker = self.invoker_set.find_free_worker().await;
163+
let (judge_events_tx, judge_events_rx) = async_channel::bounded(1);
164+
let engine = self.invoker_set.clone();
165+
let judge_cx = crate::request_handler::JudgeContext {
166+
events_tx: judge_events_tx,
167+
invoker: rpc::Client::new(rpc::box_engine(engine), "http://does-not-matter".to_string()),
168+
};
169+
165170
// TODO: can we split into LoweredJudgeRequest and Extensions?
166171
let mut responses = worker
167172
.send(Request::Judge(low_req))

0 commit comments

Comments
 (0)