Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions actix-http/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Revise compression middleware to perform compression cooperatively, periodically yielding control to other tasks instead of offloading compression to a background thread.

## 3.4.0

### Added
Expand Down
5 changes: 5 additions & 0 deletions actix-http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,8 @@ required-features = ["http2", "rustls-0_21"]
name = "response-body-compression"
harness = false
required-features = ["compress-brotli", "compress-gzip", "compress-zstd"]

[[bench]]
name = "compression-chunk-size"
harness = false
required-features = ["compress-brotli", "compress-gzip", "compress-zstd"]
51 changes: 51 additions & 0 deletions actix-http/benches/compression-chunk-size.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#![allow(clippy::uninlined_format_args)]

use actix_http::{body, encoding::Encoder, ContentEncoding, ResponseHead, StatusCode};
use criterion::{criterion_group, criterion_main, Criterion};

const BODY: &[u8] = include_bytes!("../../Cargo.lock");

const CHUNK_SIZES: [usize; 7] = [512, 1024, 2048, 4096, 8192, 16384, 32768];

const CONTENT_ENCODING: [ContentEncoding; 4] = [
ContentEncoding::Deflate,
ContentEncoding::Gzip,
ContentEncoding::Zstd,
ContentEncoding::Brotli,
];

fn compression_responses(c: &mut Criterion) {
static_assertions::const_assert!(BODY.len() > CHUNK_SIZES[6]);

let mut group = c.benchmark_group("time to compress chunk");

for content_encoding in CONTENT_ENCODING {
for chunk_size in CHUNK_SIZES {
group.bench_function(
format!("{}-{}", content_encoding.as_str(), chunk_size),
|b| {
let rt = actix_rt::Runtime::new().unwrap();
b.iter(|| {
rt.block_on(async move {
let encoder = Encoder::response(
content_encoding,
&mut ResponseHead::new(StatusCode::OK),
&BODY[..chunk_size],
)
.with_encode_chunk_size(chunk_size);
body::to_bytes_limited(encoder, chunk_size + 256)
.await
.unwrap()
.unwrap();
});
});
},
);
}
}

group.finish();
}

criterion_group!(benches, compression_responses);
criterion_main!(benches);
Loading