pdc-core

Crates.iopdc-core
lib.rspdc-core
version0.1.2
sourcesrc
created_at2022-02-15 22:55:14.233799
updated_at2022-04-26 15:09:14.67167
descriptionA network load testing library
homepage
repositoryhttps://gitlab.com/liamwarfield/pdc
max_upload_size
id532967
size56,172
Liam Warfield (liamwarfield)

documentation

https://docs.rs/pdc-core

README

pdc-core

pdc-core is library that gives access to high proformance load testing primatives.

pdc-core exposes most of its functionality via the TrafficGenerator and Scenario traits. A TrafficGenerator does what it says on the tin, it generates some type of network traffic. TrafficGenerator's have two different modes: track a load curve, or max traffic (firehose). Generators don't necessarily have to send HTTP traffic either. Load data is exposed through crossbeam chanels.

A Scenario's job is fairly simple. Given an elapsed time T (ms), a Scenario should produce a target rate R (requests/sec).

pdc-core provides functionality out of the box via handy implementations like ReqwestGenerator and exponentialScenario.

use pdc_core::generator::reqwest_generator::ReqwestGenerator;
use pdc_core::generator::TrafficGenerator;
use pdc_core::scenario::ConstantScenario;
use reqwest;
use std::str::FromStr;
use std::thread;

// generate 10000 packets per second for 100000 ms (100 sec)
let scene = ConstantScenario {
    rate: 10000.,
    duration: 100000,
};

let max_tcp_connections = 300;
let warmup = true;
let method = reqwest::Method::from_str("GET").unwrap();
let req = reqwest::Request::new(
    method,
    reqwest::Url::from_str("http://127.0.0.1:8080").unwrap(),
);

// Create a generator backed by reqwest
let mut generator = ReqwestGenerator::new(scene, max_tcp_connections, warmup, req);

// Create a Reciever to get data while the generator is running
let num_sent = generator.get_sent_packets_channel();

thread::spawn(move || {
    generator.run_scenario();
});

// Continuesly print out the number of packets sent.
loop {
    if let Ok(n) = num_sent.try_recv() {
        println!("{}", n);
    } else {
        thread::sleep(std::time::Duration::from_millis(100));
    }
}
Commit count: 73

cargo fmt