Skip to content

Commit cd5777d

Browse files
Preslav LeConvex, Inc.
Preslav Le
authored and
Convex, Inc.
committed
Log running count by client_id in Funrun (#25360)
GitOrigin-RevId: 992bf2af7b08014cc2c7c4211152d80b5b54a6d2
1 parent 9c84ce9 commit cd5777d

File tree

2 files changed

+34
-17
lines changed

2 files changed

+34
-17
lines changed

crates/isolate/src/client.rs

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,8 @@ impl<RT: Runtime, W: IsolateWorker<RT>> IsolateScheduler<RT, W> {
10131013
completed_worker = in_progress_workers.select_next_some() => {
10141014
log_pool_running_count(
10151015
self.worker.config().name,
1016-
in_progress_workers.len()
1016+
in_progress_workers.len(),
1017+
"" // This is a single tenant scheduler used in the backend.
10171018
);
10181019
let Ok(completed_worker) = completed_worker else {
10191020
// Worker has shut down, so we should shut down too.
@@ -1049,7 +1050,13 @@ impl<RT: Runtime, W: IsolateWorker<RT>> IsolateScheduler<RT, W> {
10491050
return;
10501051
}
10511052
in_progress_workers.push(done_receiver);
1052-
log_pool_running_count(self.worker.config().name, in_progress_workers.len());
1053+
// This is a single tenant scheduler used in the backend.
1054+
let client_id = "";
1055+
log_pool_running_count(
1056+
self.worker.config().name,
1057+
in_progress_workers.len(),
1058+
client_id,
1059+
);
10531060
}
10541061
}
10551062
}
@@ -1115,22 +1122,30 @@ impl<RT: Runtime, W: IsolateWorker<RT>> SharedIsolateScheduler<RT, W> {
11151122
}
11161123

11171124
fn handle_completed_worker(&mut self, completed_worker: ActiveWorkerState) {
1118-
match self
1125+
let new_count = match self
11191126
.in_progress_count
11201127
.remove_entry(&completed_worker.client_id)
11211128
{
11221129
Some((client_id, count)) if count > 1 => {
11231130
self.in_progress_count.insert(client_id, count - 1);
1131+
count - 1
11241132
},
11251133
Some((_, 1)) => {
11261134
// Nothing to do; we've already removed the entry above.
1135+
0
11271136
},
11281137
_ => panic!(
11291138
"Inconsistent state in `in_progress_count` map; the count of active workers for \
11301139
client {} must be >= 1",
11311140
completed_worker.client_id
11321141
),
1133-
}
1142+
};
1143+
log_pool_running_count(
1144+
self.worker.config().name,
1145+
new_count,
1146+
&completed_worker.client_id,
1147+
);
1148+
11341149
self.available_workers
11351150
.entry(completed_worker.client_id)
11361151
.or_default()
@@ -1146,10 +1161,6 @@ impl<RT: Runtime, W: IsolateWorker<RT>> SharedIsolateScheduler<RT, W> {
11461161
loop {
11471162
select_biased! {
11481163
completed_worker = self.in_progress_workers.select_next_some() => {
1149-
log_pool_running_count(
1150-
self.worker.config().name,
1151-
self.in_progress_workers.len()
1152-
);
11531164
let Ok(completed_worker): Result<ActiveWorkerState, _> = completed_worker else {
11541165
tracing::warn!("Worker has shut down uncleanly. Shutting down {} scheduler.", self.worker.config().name);
11551166
return;
@@ -1171,10 +1182,16 @@ impl<RT: Runtime, W: IsolateWorker<RT>> SharedIsolateScheduler<RT, W> {
11711182
};
11721183
let (done_sender, done_receiver) = oneshot::channel();
11731184
self.in_progress_workers.push(done_receiver);
1174-
*self
1185+
let entry = self
11751186
.in_progress_count
11761187
.entry(request.client_id.clone())
1177-
.or_default() += 1;
1188+
.or_default();
1189+
*entry += 1;
1190+
log_pool_running_count(
1191+
self.worker.config().name,
1192+
*entry,
1193+
&request.client_id,
1194+
);
11781195
let client_id = request.client_id.clone();
11791196
if self.worker_senders[worker_id]
11801197
.try_send((
@@ -1195,10 +1212,6 @@ impl<RT: Runtime, W: IsolateWorker<RT>> SharedIsolateScheduler<RT, W> {
11951212
);
11961213
return;
11971214
}
1198-
log_pool_running_count(
1199-
self.worker.config().name,
1200-
self.in_progress_workers.len()
1201-
);
12021215
},
12031216
_ = report_stats => {
12041217
let heap_stats = self.aggregate_heap_stats();

crates/isolate/src/metrics.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use metrics::{
2020
register_convex_histogram,
2121
CancelableTimer,
2222
IntoLabel,
23+
MetricLabel,
2324
StaticMetricLabel,
2425
StatusTimer,
2526
Timer,
@@ -54,13 +55,16 @@ pub fn execute_timer(udf_type: &UdfType, npm_version: &Option<Version>) -> Statu
5455
register_convex_gauge!(
5556
ISOLATE_POOL_RUNNING_COUNT_INFO,
5657
"How many isolate workers are currently running work",
57-
&["pool_name"]
58+
&["pool_name", "client_id"]
5859
);
59-
pub fn log_pool_running_count(name: &'static str, count: usize) {
60+
pub fn log_pool_running_count(name: &'static str, count: usize, client_id: &str) {
6061
log_gauge_with_labels(
6162
&ISOLATE_POOL_RUNNING_COUNT_INFO,
6263
count as f64,
63-
vec![StaticMetricLabel::new("pool_name", name)],
64+
vec![
65+
StaticMetricLabel::new("pool_name", name),
66+
MetricLabel::new("client_id", client_id),
67+
],
6468
);
6569
}
6670

0 commit comments

Comments
 (0)