pdc_core/lib.rs
1//! # pdc-core
2//!
3//! pdc-core is library that gives access to high proformance load testing primatives.
4//!
5//! `pdc-core` exposes most of its functionality via the `TrafficGenerator` and `Scenario` traits.
6//! A `TrafficGenerator` does what it says on the tin, it generates some type of network traffic.
7//! `TrafficGenerator`'s have two different modes: track a load curve, or max traffic (firehose).
8//! Generators don't necessarily have to send HTTP traffic either.
9//!
10//! A `Scenario`'s job is fairly simple. Given an elapsed time T (ms), a `Scenario` should produce a target
11//! rate R (requests/sec).
12//!
13//! `pdc-core` provides functionality out of the box via handy implementations like
14//! [`ReqwestGenerator`](struct@crate::generator::reqwest_generator::ReqwestGenerator) and [`ConstantScenario`](struct@crate::scenario::ConstantScenario)
15//! ```
16//! use pdc_core::generator::reqwest_generator::ReqwestGenerator;
17//! use pdc_core::generator::TrafficGenerator;
18//! use pdc_core::scenario::ConstantScenario;
19//! use reqwest;
20//! use std::str::FromStr;
21//! use std::thread;
22//!
23//!
24//! // generate 10000 packets per second for 100000 ms (100 sec)
25//! let scene = ConstantScenario {
26//! rate: 10000.,
27//! duration: 100000,
28//! };
29//!
30//! let max_tcp_connections = 300;
31//! let worker_count = 6;
32//! let warmup = true;
33//! let method = reqwest::Method::from_str("GET").unwrap();
34//! let req = reqwest::Request::new(
35//! method,
36//! reqwest::Url::from_str("http://127.0.0.1:8080").unwrap(),
37//! );
38//!
39//! // Create a generator backed by reqwest
40//! let mut generator = ReqwestGenerator::new(scene, max_tcp_connections, worker_count, warmup, req);
41//!
42//! // Create a Reciever to get data while the generator is running
43//! let num_sent = generator.get_sent_packets_channel();
44//!
45//! thread::spawn(move || {
46//! generator.run_scenario();
47//! });
48//!
49//! // Continuesly print out the number of packets sent.
50//! loop {
51//! if let Ok(n) = num_sent.try_recv() {
52//! println!("{}", n);
53//! } else {
54//! thread::sleep(std::time::Duration::from_millis(100));
55//! }
56//! }
57//!```
58
59pub mod generator;
60pub mod scenario;