forked from slawlor/ractor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding CI workflow for code-coverage along with benchmarks
This PR adds benchmarks for 1. Actor spawning 2. Actor timing to handle first message + shutdown 3. Actor timing to handle 100K messages Additionally we're adding new CI for (1) code coverage and (2) running the benchmarks automatically
- Loading branch information
Showing
20 changed files
with
416 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[alias] | ||
xtask = "run --package xtask --" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: Code Coverage | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
types: [opened, reopened, synchronize] | ||
|
||
jobs: | ||
coverage: | ||
name: Coverage using xtask | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest] | ||
rust: [stable] | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- name: Checkout sources | ||
uses: actions/checkout@v2 | ||
|
||
- name: Install stable toolchain | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
toolchain: ${{ matrix.rust }} | ||
override: true | ||
components: llvm-tools-preview | ||
|
||
- uses: Swatinem/rust-cache@v1 | ||
|
||
- name: Download grcov | ||
run: | | ||
mkdir -p "${HOME}/.local/bin" | ||
curl -sL https://github.com/mozilla/grcov/releases/download/v0.8.10/grcov-x86_64-unknown-linux-gnu.tar.bz2 | tar jxf - -C "${HOME}/.local/bin" | ||
echo "$HOME/.local/bin" >> $GITHUB_PATH | ||
- name: Run xtask coverage | ||
uses: actions-rs/cargo@v1 | ||
with: | ||
command: run | ||
args: --bin xtask coverage | ||
|
||
|
||
- name: Upload to codecov.io | ||
uses: codecov/codecov-action@v3 | ||
with: | ||
files: coverage/*.lcov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,6 @@ | |
|
||
members = [ | ||
"ractor", | ||
"ractor-playground" | ||
"ractor-playground", | ||
"xtask" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
// Copyright (c) Sean Lawlor | ||
// | ||
// This source code is licensed under both the MIT license found in the | ||
// LICENSE-MIT file in the root directory of this source tree. | ||
|
||
#[macro_use] | ||
extern crate criterion; | ||
|
||
use criterion::{BatchSize, Criterion}; | ||
use ractor::{Actor, ActorHandler, ActorRef}; | ||
|
||
struct BenchActor; | ||
|
||
#[async_trait::async_trait] | ||
impl ActorHandler for BenchActor { | ||
type Msg = (); | ||
|
||
type State = (); | ||
|
||
async fn pre_start(&self, myself: ActorRef<Self>) -> Self::State { | ||
let _ = myself.cast(()); | ||
} | ||
|
||
async fn handle(&self, myself: ActorRef<Self>, _message: Self::Msg, _state: &mut Self::State) { | ||
myself.stop(None); | ||
} | ||
} | ||
|
||
fn create_actors(c: &mut Criterion) { | ||
let small = 100; | ||
let large = 10000; | ||
|
||
let id = format!("Creation of {} actors", small); | ||
let runtime = tokio::runtime::Builder::new_multi_thread().build().unwrap(); | ||
c.bench_function(&id, move |b| { | ||
b.iter_batched( | ||
|| {}, | ||
|()| { | ||
runtime.block_on(async move { | ||
let mut handles = vec![]; | ||
for _ in 0..small { | ||
let (_, handler) = Actor::spawn(None, BenchActor) | ||
.await | ||
.expect("Failed to create test agent"); | ||
handles.push(handler); | ||
} | ||
handles | ||
}) | ||
}, | ||
BatchSize::PerIteration, | ||
); | ||
}); | ||
|
||
let id = format!("Creation of {} actors", large); | ||
let runtime = tokio::runtime::Builder::new_multi_thread().build().unwrap(); | ||
c.bench_function(&id, move |b| { | ||
b.iter_batched( | ||
|| {}, | ||
|()| { | ||
runtime.block_on(async move { | ||
let mut handles = vec![]; | ||
for _ in 0..large { | ||
let (_, handler) = Actor::spawn(None, BenchActor) | ||
.await | ||
.expect("Failed to create test agent"); | ||
handles.push(handler); | ||
} | ||
handles | ||
}) | ||
}, | ||
BatchSize::PerIteration, | ||
); | ||
}); | ||
} | ||
|
||
fn schedule_work(c: &mut Criterion) { | ||
let small = 100; | ||
let large = 1000; | ||
|
||
let id = format!("Waiting on {} actors to process first message", small); | ||
let runtime = tokio::runtime::Builder::new_multi_thread().build().unwrap(); | ||
c.bench_function(&id, move |b| { | ||
b.iter_batched( | ||
|| { | ||
runtime.block_on(async move { | ||
let mut handles = vec![]; | ||
for _ in 0..small { | ||
let (_, handler) = Actor::spawn(None, BenchActor) | ||
.await | ||
.expect("Failed to create test agent"); | ||
handles.push(handler); | ||
} | ||
handles | ||
}) | ||
}, | ||
|handles| { | ||
runtime.block_on(async move { | ||
let _ = futures::future::join_all(handles).await; | ||
}) | ||
}, | ||
BatchSize::PerIteration, | ||
); | ||
}); | ||
|
||
let id = format!("Waiting on {} actors to process first message", large); | ||
let runtime = tokio::runtime::Builder::new_multi_thread().build().unwrap(); | ||
c.bench_function(&id, move |b| { | ||
b.iter_batched( | ||
|| { | ||
runtime.block_on(async move { | ||
let mut handles = vec![]; | ||
for _ in 0..large { | ||
let (_, handler) = Actor::spawn(None, BenchActor) | ||
.await | ||
.expect("Failed to create test agent"); | ||
handles.push(handler); | ||
} | ||
handles | ||
}) | ||
}, | ||
|handles| { | ||
runtime.block_on(async move { | ||
let _ = futures::future::join_all(handles).await; | ||
}) | ||
}, | ||
BatchSize::PerIteration, | ||
); | ||
}); | ||
} | ||
|
||
#[allow(clippy::async_yields_async)] | ||
fn process_messages(c: &mut Criterion) { | ||
const NUM_MSGS: u64 = 100000; | ||
|
||
struct MessagingActor { | ||
num_msgs: u64, | ||
} | ||
|
||
#[async_trait::async_trait] | ||
impl ActorHandler for MessagingActor { | ||
type Msg = (); | ||
|
||
type State = u64; | ||
|
||
async fn pre_start(&self, myself: ActorRef<Self>) -> Self::State { | ||
let _ = myself.cast(()); | ||
0u64 | ||
} | ||
|
||
async fn handle( | ||
&self, | ||
myself: ActorRef<Self>, | ||
_message: Self::Msg, | ||
state: &mut Self::State, | ||
) { | ||
*state += 1; | ||
if *state >= self.num_msgs { | ||
myself.stop(None); | ||
} else { | ||
let _ = myself.cast(()); | ||
} | ||
} | ||
} | ||
|
||
let id = format!("Waiting on {} messages to be processed", NUM_MSGS); | ||
let runtime = tokio::runtime::Builder::new_multi_thread().build().unwrap(); | ||
c.bench_function(&id, move |b| { | ||
b.iter_batched( | ||
|| { | ||
runtime.block_on(async move { | ||
let (_, handle) = Actor::spawn(None, MessagingActor { num_msgs: NUM_MSGS }) | ||
.await | ||
.expect("Failed to create test actor"); | ||
handle | ||
}) | ||
}, | ||
|handle| { | ||
runtime.block_on(async move { | ||
let _ = handle.await; | ||
}) | ||
}, | ||
BatchSize::PerIteration, | ||
); | ||
}); | ||
} | ||
|
||
criterion_group!(actors, create_actors, schedule_work, process_messages); | ||
criterion_main!(actors); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.