-
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.
feat: added base structure for benchmark
- Loading branch information
1 parent
123eaa8
commit 845456e
Showing
11 changed files
with
239 additions
and
0 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,6 @@ | ||
FROM rust AS builder | ||
WORKDIR /mnt | ||
RUN --mount=type=bind,source=./code,target=/mnt cargo build --release --target-dir /tmp | ||
|
||
FROM debian:bookworm-slim | ||
COPY --from=builder /tmp/release/benchmark /usr/local/bin/benchmark |
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 @@ | ||
# DOG benchmark setup |
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,21 @@ | ||
[package] | ||
name = "libp2p-dog-benchmark" | ||
edition = "2021" | ||
rust-version = "1.83" | ||
description = "A benchmark of the DOG protocol for libp2p" | ||
version = "0.1.0" | ||
license = "Apache-2.0" | ||
|
||
[package.metadata.release] | ||
release = false | ||
|
||
[dependencies] | ||
libp2p = { workspace = true, features = ["noise", "tcp", "yamux", "tokio", "macros"] } | ||
libp2p-dog = { path = "../../dog" } | ||
tokio = { workspace = true, features = ["full"] } | ||
clap = { version = "4.5.16", features = ["derive"] } | ||
tracing = { workspace = true } | ||
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } | ||
|
||
[lints] | ||
workspace = true |
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,16 @@ | ||
use clap::Parser; | ||
|
||
#[derive(Parser, Debug)] | ||
pub(crate) struct Args { | ||
#[arg(short, long, default_value_t = 0)] | ||
pub port: u16, | ||
|
||
#[arg(long, value_delimiter = ',', default_value = "")] | ||
pub peers: Vec<String>, | ||
} | ||
|
||
impl Args { | ||
pub(crate) fn new() -> Args { | ||
Args::parse() | ||
} | ||
} |
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,26 @@ | ||
use std::str::FromStr; | ||
|
||
use libp2p::Multiaddr; | ||
|
||
use crate::args::Args; | ||
|
||
#[derive(Debug)] | ||
pub(crate) struct Config { | ||
pub addr: Multiaddr, | ||
pub peers: Vec<Multiaddr>, | ||
} | ||
|
||
impl Config { | ||
pub(crate) fn new(args: &Args) -> Self { | ||
let addr = Multiaddr::from_str(&format!("/ip4/127.0.0.1/tcp/{}", args.port)) | ||
.expect("Failed to parse address"); | ||
|
||
let peers = args | ||
.peers | ||
.iter() | ||
.map(|peer| Multiaddr::from_str(peer).expect("Failed to parse peer")) | ||
.collect(); | ||
|
||
Self { addr, peers } | ||
} | ||
} |
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,10 @@ | ||
use tracing_subscriber::filter::{EnvFilter, LevelFilter}; | ||
use tracing_subscriber::fmt; | ||
|
||
pub(crate) fn init() { | ||
let filter = EnvFilter::builder() | ||
.with_default_directive(LevelFilter::DEBUG.into()) | ||
.from_env_lossy(); | ||
|
||
fmt().with_env_filter(filter).init(); | ||
} |
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,32 @@ | ||
use std::error::Error; | ||
|
||
use libp2p::swarm::dial_opts::DialOpts; | ||
|
||
mod args; | ||
mod config; | ||
mod logging; | ||
mod swarm; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn Error>> { | ||
logging::init(); | ||
|
||
let args = args::Args::new(); | ||
|
||
let config = config::Config::new(&args); | ||
|
||
let mut swarm = swarm::new_swarm(&config); | ||
|
||
swarm.listen_on(config.addr)?; | ||
|
||
for peer_addr in &config.peers { | ||
swarm.dial( | ||
DialOpts::unknown_peer_id() | ||
.address(peer_addr.clone()) | ||
.allocate_new_port() | ||
.build(), | ||
)?; | ||
} | ||
|
||
loop {} | ||
} |
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,26 @@ | ||
use std::time::Duration; | ||
|
||
use libp2p::{noise, tcp, yamux, Swarm, SwarmBuilder}; | ||
|
||
use crate::config::Config; | ||
|
||
pub(crate) fn new_swarm(config: &Config) -> Swarm<libp2p_dog::Behaviour> { | ||
SwarmBuilder::with_new_identity() | ||
.with_tokio() | ||
.with_tcp( | ||
tcp::Config::default().nodelay(true), | ||
noise::Config::new, | ||
yamux::Config::default, | ||
) | ||
.unwrap() | ||
.with_behaviour(|key| { | ||
libp2p_dog::Behaviour::new( | ||
libp2p_dog::TransactionAuthenticity::Signed(key.clone()), | ||
libp2p_dog::Config::default(), | ||
) | ||
.expect("Failed to create dog behaviour") | ||
}) | ||
.unwrap() | ||
.with_swarm_config(|cfg| cfg.with_idle_connection_timeout(Duration::from_secs(u64::MAX))) | ||
.build() | ||
} |
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,3 @@ | ||
# Config folder | ||
|
||
Please refer to the benchmark [README](../README.md) for more information on the configuration files. |
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,42 @@ | ||
- name: Build benchmark container | ||
hosts: "{{ groups['machines'][0] }}" | ||
|
||
tasks: | ||
- name: Copy source code to remote machine | ||
synchronize: | ||
src: "{{ playbook_dir }}/../code" | ||
dest: /home/{{ ansible_ssh_user }} | ||
mode: push | ||
delete: true | ||
|
||
- name: Upload Dockerfile | ||
copy: | ||
src: "{{ playbook_dir }}/../Dockerfile" | ||
dest: /home/{{ ansible_ssh_user }} | ||
|
||
- name: Build container | ||
shell: | | ||
docker build -t dog-benchmark:latest -f /home/{{ ansible_ssh_user }}/Dockerfile . | ||
docker save dog-benchmark:latest > container.tar | ||
- name: Copy container to local machine | ||
synchronize: | ||
src: container.tar | ||
dest: /tmp | ||
mode: pull | ||
delete: true | ||
|
||
- name: Upload benchmark container | ||
hosts: all | ||
|
||
tasks: | ||
- name: Copy container to remote machines | ||
synchronize: | ||
src: /tmp/container.tar | ||
dest: /tmp | ||
mode: push | ||
delete: true | ||
|
||
- name: Load container | ||
shell: | | ||
docker load < /tmp/container.tar |
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,56 @@ | ||
- name: Establish hosts authenticity | ||
hosts: all | ||
gather_facts: false | ||
|
||
tasks: | ||
- name: Establish hosts authenticity | ||
become: false | ||
shell: | | ||
ssh-keygen -R {{ ansible_host }} 2>/dev/null || true | ||
ssh-keyscan -t rsa,ecdsa,ed25519 {{ ansible_host }} | grep -v "^#" >> ~/.ssh/known_hosts | ||
delegate_to: localhost | ||
|
||
- name: Initialize all machines | ||
hosts: all | ||
become: true | ||
|
||
vars: | ||
ansible_ssh_user: root | ||
|
||
tasks: | ||
- name: Update APT packages | ||
apt: | ||
autoclean: true | ||
clean: true | ||
update_cache: true | ||
upgrade: full | ||
|
||
- name: Install SNAP package manager | ||
apt: | ||
name: snapd | ||
state: present | ||
|
||
- name: Update SNAP packages | ||
command: snap refresh | ||
|
||
- name: Create user | ||
user: | ||
generate_ssh_key: true | ||
name: bob | ||
shell: /bin/bash | ||
|
||
- name: Add SSH keys to authorized_keys | ||
authorized_key: | ||
user: bob | ||
key: "{{ item }}" | ||
with_file: | ||
- "{{ playbook_dir }}/../config/ssh-public-keys.txt" | ||
|
||
- name: Install Docker | ||
shell: curl -sSL https://get.docker.com/ | sh | ||
|
||
- name: Add user to Docker group | ||
user: | ||
name: bob | ||
groups: docker | ||
append: true |