Skip to content

Commit

Permalink
some work on making BridgeStream take streams instead of futures (#7)
Browse files Browse the repository at this point in the history
* Stable Libs

Switch to stable libs and stable formatting. Introduce BridgeStream to combine streams
  • Loading branch information
kornstar11 authored and dbcfd committed Dec 19, 2019
1 parent abba512 commit 3639df0
Show file tree
Hide file tree
Showing 10 changed files with 237 additions and 141 deletions.
14 changes: 6 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2018"
# - Update CHANGELOG.md.
# - Update doc URL.
# - Create "v0.1.x" git tag.
version = "0.1.0-alpha.1"
version = "0.1.0"
license = "MIT"
readme = "README.md"
description = """
Expand All @@ -20,19 +20,17 @@ repository = "https://github.com/dbcfd/pcap-async"
[dependencies]
byteorder = "1.3"
failure = "0.1"
failure_derive = "0.1"
futures-preview = { version ="0.3.0-alpha.19" }
futures = "0.3"
libc = "0.2"
log = "0.4"
pin-project = "0.4.0-alpha.9"
pcap-sys = { git = "https://github.com/protectwise/pcap-sys.git", tag = "v0.3.0" }
tokio-executor = "=0.2.0-alpha.6"
tokio-timer = "0.3.0-alpha.6"
pin-project = "0.4"
pcap-sys = "0.1"
tokio = { version = "0.2", features = ["blocking", "rt-threaded", "time"] }

[dev-dependencies]
criterion = "0.2"
env_logger = "0.6"
tokio = "=0.2.0-alpha.6"
tokio = { version = "0.2", features = ["macros", "rt-core"] }

[lib]
path = "src/lib.rs"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ First, add this to your `Cargo.toml`:

```toml
[dependencies]
channel-async = "0.1.0-alpha.1"
pcap-async = "0.1"
```

Next, add this to your crate:
Expand All @@ -36,7 +36,7 @@ use pcap_async::{Config, Handle, PacketStream};
#[tokio::main]
async fn main() {
let handle = Handle::lookup().expect("No handle created");
let mut provider = PacketProvider::new(Config::default(), handle)
let mut provider = PacketStream::new(Config::default(), handle)
.expect("Could not create provider")
.fuse();
while let Some(packets) = provider.next().await {
Expand Down
23 changes: 15 additions & 8 deletions benches/bench_capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use criterion::{criterion_group, criterion_main, Bencher, Criterion};
use futures::StreamExt;
use log::*;
use pcap_async::{Config, Handle, PacketStream, BridgeStream};
use pcap_async::{BridgeStream, Config, Handle, PacketStream};
use std::path::PathBuf;

fn bench_stream_from_large_file(b: &mut Bencher) {
Expand All @@ -15,7 +15,7 @@ fn bench_stream_from_large_file(b: &mut Bencher) {
info!("Benchmarking against {:?}", pcap_path.clone());

b.iter(|| {
let rt = tokio::runtime::Runtime::new().expect("Failed to create runtime");
let mut rt = tokio::runtime::Runtime::new().expect("Failed to create runtime");

let clone_path = pcap_path.clone();

Expand Down Expand Up @@ -63,7 +63,7 @@ fn bench_stream_next_from_large_file_bridge(b: &mut Bencher) {
info!("Benchmarking against {:?}", pcap_path.clone());

b.iter(|| {
let rt = tokio::runtime::Runtime::new().expect("Failed to create runtime");
let mut rt = tokio::runtime::Runtime::new().expect("Failed to create runtime");

let clone_path = pcap_path.clone();

Expand All @@ -76,8 +76,9 @@ fn bench_stream_next_from_large_file_bridge(b: &mut Bencher) {
let mut cfg = Config::default();
cfg.with_max_packets_read(5000);

let packet_provider = BridgeStream::new(Config::default(), vec![handle1.clone(), handle2.clone()])
.expect("Failed to build");
let packet_provider =
BridgeStream::new(Config::default(), vec![handle1.clone(), handle2.clone()])
.expect("Failed to build");
let fut_packets = async move {
let mut packet_provider = packet_provider.boxed();
let mut packets = vec![];
Expand Down Expand Up @@ -106,7 +107,7 @@ fn bench_stream_next_from_large_file(b: &mut Bencher) {
info!("Benchmarking against {:?}", pcap_path.clone());

b.iter(|| {
let rt = tokio::runtime::Runtime::new().expect("Failed to create runtime");
let mut rt = tokio::runtime::Runtime::new().expect("Failed to create runtime");

let clone_path = pcap_path.clone();

Expand Down Expand Up @@ -136,7 +137,8 @@ fn bench_stream_next_from_large_file(b: &mut Bencher) {
}

fn bench_stream_next_bridge(c: &mut Criterion) {
let benchmark = criterion::Benchmark::new("4sics-bridge", bench_stream_next_from_large_file_bridge);
let benchmark =
criterion::Benchmark::new("4sics-bridge", bench_stream_next_from_large_file_bridge);

c.bench(
"stream_next",
Expand All @@ -159,7 +161,12 @@ fn bench_stream_next(c: &mut Criterion) {
);
}

criterion_group!(benches, bench_stream, bench_stream_next, bench_stream_next_bridge);
criterion_group!(
benches,
bench_stream,
bench_stream_next,
bench_stream_next_bridge
);

// Benchmark: cargo bench --verbose

Expand Down
4 changes: 2 additions & 2 deletions lefthook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ format:
1_install:
run: rustup component add rustfmt
2_cargo_fmt:
run: cargo +nightly fmt --all
run: cargo +${RUST_VERSION:-stable} fmt --all

pre-push:
piped: true
commands:
1_install:
run: rustup component add rustfmt
2_fmt:
run: cargo +nightly fmt --all -- --check
run: cargo +${RUST_VERSION:-stable} fmt --all -- --check
Loading

0 comments on commit 3639df0

Please sign in to comment.