poem icon indicating copy to clipboard operation
poem copied to clipboard

Slow response

Open ikrivosheev opened this issue 2 years ago • 3 comments

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?

ikrivosheev avatar Sep 10 '22 18:09 ikrivosheev

Seems to be related to the brotli algorithm.

sunli829 avatar Sep 11 '22 02:09 sunli829

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

sunli829 avatar Sep 11 '22 03:09 sunli829

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.

ikrivosheev avatar Sep 11 '22 09:09 ikrivosheev

@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?

xamgore avatar Oct 07 '22 21:10 xamgore