poem
poem copied to clipboard
Slow response
Hello! After add Compression
middleware response is slow.
My application:
use poem::middleware::{CatchPanic, Compression, TowerLayerCompatExt, Tracing};
use poem::{listener::TcpListener, EndpointExt, Route, Server};
use poem_openapi::OpenApiService;
use tower_http::limit::RequestBodyLimitLayer;
#[tokio::main]
async fn main() -> Result<(), std::io::Error> {
tracing_subscriber::fmt().with_max_level(tracing::Level::DEBUG).init();
let api_service = OpenApiService::new(game_server_host::ApiV1, "", "")
.description(env!("CARGO_PKG_DESCRIPTION"))
.server("http://localhost:3000/api/v1");
let json = api_service.spec_endpoint();
let app = Route::new()
.nest("/api/v1", api_service)
.nest("/docs/openapi.json", json)
.with(Compression)
.with(Tracing)
.with(CatchPanic::new())
tracing::debug!("listening on localhost:3000";
Server::new(TcpListener::bind("localhost:3000")).run(app).await
}
}
Without Compression
middleware response time is 5-10ms, with 200-250 ms. What am I doing wrong?
Seems to be related to the brotli
algorithm.
I have disabled the brotli
algorithm because it is too slow, please upgrade to 1.3.42
.
I have disabled the
brotli
algorithm because it is too slow, please upgrade to1.3.42
.
Thank you for quick answer! Might is better to split decompress body and compress into to middleware and add support choice compression algorithm in Compress
? If you like the solution, I'm ready to prepare PR.
@sunli829 @ikrivosheev compression on small content sizes may have a high overhead. Also, brotli
algorithm is CPU-bound. Is there any way to tune parameters in poem
?