poem-web / poem

A full-featured and easy-to-use web framework with the Rust programming language.
Apache License 2.0
3.36k stars 268 forks source link

Slow response #388

Open ikrivosheev opened 1 year ago

ikrivosheev commented 1 year ago

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?

sunli829 commented 1 year ago

Seems to be related to the brotli algorithm.

sunli829 commented 1 year ago

I have disabled the brotli algorithm because it is too slow, please upgrade to 1.3.42.

ikrivosheev commented 1 year ago

I have disabled the brotli algorithm because it is too slow, please upgrade to 1.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.