Skip to content

Commit b883f12

Browse files
committed
Add a template worker
A new dummy TemplateWorker for development and documentation purposes.
1 parent 73d8499 commit b883f12

4 files changed

Lines changed: 64 additions & 1 deletion

File tree

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ among available system CPU cores to fully utilize system resources.
4848

4949
* Run linter, `cargo clippy`.
5050

51+
# Adding a new worker
52+
53+
If your goal is to implement a new worker, take a look at `TemplateWorker`.
54+
It's a dummy worker implementation, the sole purpose of which is to show all
55+
parts that have to be touched to wire up a custom worker. Copy the template
56+
over under a new name, and you'll get a decent ground for development.
57+
5158
\[1\]: https://en.wikipedia.org/wiki/Poisson_point_process
5259

5360
\[2\]: "Open versus closed: A cautionary tale". Schroeder, B., Wierman, A. and

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ pub enum Workload {
4444
/// How often to invoke a syscall.
4545
arrival_rate: f64,
4646
},
47+
48+
/// For documentation purposes
49+
Template {},
4750
}
4851

4952
/// Distribution for number of ports to listen on

src/worker/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ use rand_distr::{Uniform, Zipf};
44

55
use crate::{Distribution, Worker, Workload, WorkloadConfig};
66

7-
use self::{endpoints::EndpointWorker, processes::ProcessesWorker, syscalls::SyscallsWorker};
7+
use self::{
8+
endpoints::EndpointWorker, processes::ProcessesWorker, syscalls::SyscallsWorker,
9+
template::TemplateWorker,
10+
};
811

912
pub mod endpoints;
1013
pub mod processes;
1114
pub mod syscalls;
15+
pub mod template;
1216

1317
pub fn new_worker(
1418
workload: WorkloadConfig,
@@ -44,5 +48,6 @@ pub fn new_worker(
4448
))
4549
}
4650
Workload::Syscalls { .. } => Box::new(SyscallsWorker::new(workload, cpu, process)),
51+
Workload::Template { .. } => Box::new(TemplateWorker::new(workload, cpu, process)),
4752
}
4853
}

src/worker/template.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
use std::fmt::Display;
2+
3+
use core_affinity::CoreId;
4+
use log::info;
5+
6+
use crate::{BaseConfig, Worker, WorkerError, WorkloadConfig};
7+
8+
struct TemplateWorkload {
9+
restart_interval: u64,
10+
}
11+
12+
pub struct TemplateWorker {
13+
config: BaseConfig,
14+
workload: TemplateWorkload,
15+
}
16+
17+
impl TemplateWorker {
18+
pub fn new(workload: WorkloadConfig, cpu: CoreId, process: usize) -> Self {
19+
let WorkloadConfig {
20+
restart_interval,
21+
workload: _,
22+
} = workload;
23+
24+
TemplateWorker {
25+
config: BaseConfig { cpu, process },
26+
workload: TemplateWorkload { restart_interval },
27+
}
28+
}
29+
}
30+
31+
impl Worker for TemplateWorker {
32+
fn run_payload(&self) -> Result<(), WorkerError> {
33+
info!("{self}");
34+
35+
let TemplateWorkload { restart_interval } = self.workload;
36+
37+
// Do something here
38+
info!("{restart_interval}");
39+
40+
Ok(())
41+
}
42+
}
43+
44+
impl Display for TemplateWorker {
45+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
46+
write!(f, "{}", self.config)
47+
}
48+
}

0 commit comments

Comments
 (0)