diff --git a/Cargo.toml b/Cargo.toml index d825a03..8abf898 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,3 +6,7 @@ default-members = ["crates/rproxy"] members = [ "crates/rproxy", ] + +[profile.flamegraph] +inherits = "release" +debug = true diff --git a/crates/rproxy/src/metrics/metrics.rs b/crates/rproxy/src/metrics/metrics.rs index 223f28b..3561f15 100644 --- a/crates/rproxy/src/metrics/metrics.rs +++ b/crates/rproxy/src/metrics/metrics.rs @@ -1,13 +1,6 @@ use std::{net::TcpListener, sync::Arc, time::Duration}; -use actix_web::{ - App, - HttpRequest, - HttpResponse, - HttpServer, - middleware::{NormalizePath, TrailingSlash}, - web, -}; +use actix_web::{App, HttpRequest, HttpResponse, HttpServer, middleware::NormalizePath, web}; use awc::http::Method; use prometheus_client::{ metrics::{counter::Counter, family::Family, gauge::Gauge}, @@ -287,7 +280,7 @@ impl Metrics { let server = match HttpServer::new(move || { App::new() .app_data(web::Data::new(self.clone())) - .wrap(NormalizePath::new(TrailingSlash::Trim)) + .wrap(NormalizePath::trim()) .default_service(web::route().to(Self::receive)) }) .workers(1) diff --git a/crates/rproxy/src/proxy_http/proxy_http.rs b/crates/rproxy/src/proxy_http/proxy_http.rs index 87871b0..160a82b 100644 --- a/crates/rproxy/src/proxy_http/proxy_http.rs +++ b/crates/rproxy/src/proxy_http/proxy_http.rs @@ -22,7 +22,7 @@ use actix_web::{ HttpServer, body::BodySize, http::{StatusCode, header}, - middleware::{NormalizePath, TrailingSlash}, + middleware::NormalizePath, web, }; use awc::{ @@ -179,7 +179,7 @@ where App::new() .app_data(this) - .wrap(NormalizePath::new(TrailingSlash::Trim)) + .wrap(NormalizePath::trim()) .default_service(web::route().to(Self::receive)) }) .on_connect(Self::on_connect(metrics, client_connections_count)) @@ -250,10 +250,16 @@ where socket.set_tcp_keepalive( &socket2::TcpKeepalive::new() .with_time( - config.idle_connection_timeout().div_f64(f64::from(TCP_KEEPALIVE_ATTEMPTS)), + config + .idle_connection_timeout() + .checked_div(TCP_KEEPALIVE_ATTEMPTS) + .expect("duration is not zero"), ) .with_interval( - config.idle_connection_timeout().div_f64(f64::from(TCP_KEEPALIVE_ATTEMPTS)), + config + .idle_connection_timeout() + .checked_div(TCP_KEEPALIVE_ATTEMPTS) + .expect("duration is not zero"), ) .with_retries(TCP_KEEPALIVE_ATTEMPTS - 1), )?; @@ -457,11 +463,13 @@ where ) { if cli_req.decompressed_size < cli_req.size { (cli_req.decompressed_body, cli_req.decompressed_size) = + // TODO: remove this clone decompress(cli_req.body.clone(), cli_req.size, cli_req.info.content_encoding()); } if mrr_res.decompressed_size < mrr_res.size { (mrr_res.decompressed_body, mrr_res.decompressed_size) = + // TODO: remove this clone decompress(mrr_res.body.clone(), mrr_res.size, mrr_res.info.content_encoding()); } diff --git a/crates/rproxy/src/proxy_http/proxy_http_inner_rpc.rs b/crates/rproxy/src/proxy_http/proxy_http_inner_rpc.rs index f5da0c8..46af948 100644 --- a/crates/rproxy/src/proxy_http/proxy_http_inner_rpc.rs +++ b/crates/rproxy/src/proxy_http/proxy_http_inner_rpc.rs @@ -47,7 +47,7 @@ impl ProxyHttpInner for ProxyHttpInnerRpc { return false; } - return mirror_errored_requests || jrpc_res.error.is_none() + return mirror_errored_requests || jrpc_res.error.is_none(); } match jrpc_req { diff --git a/crates/rproxy/src/proxy_ws/proxy_ws.rs b/crates/rproxy/src/proxy_ws/proxy_ws.rs index 72fdfb8..8b48731 100644 --- a/crates/rproxy/src/proxy_ws/proxy_ws.rs +++ b/crates/rproxy/src/proxy_ws/proxy_ws.rs @@ -10,14 +10,7 @@ use std::{ }; use actix::{Actor, AsyncContext, WrapFuture}; -use actix_web::{ - App, - HttpRequest, - HttpResponse, - HttpServer, - middleware::{NormalizePath, TrailingSlash}, - web, -}; +use actix_web::{App, HttpRequest, HttpResponse, HttpServer, middleware::NormalizePath, web}; use actix_ws::{MessageStream, Session}; use bytes::{Buf, BufMut, Bytes, BytesMut}; use futures::{ @@ -158,7 +151,7 @@ where App::new() .app_data(this) - .wrap(NormalizePath::new(TrailingSlash::Trim)) + .wrap(NormalizePath::trim()) .default_service(web::route().to(Self::receive)) }) .on_connect(Self::on_connect(metrics, client_connections_count)) diff --git a/crates/rproxy/src/server/server.rs b/crates/rproxy/src/server/server.rs index 12bf1a9..de0b030 100644 --- a/crates/rproxy/src/server/server.rs +++ b/crates/rproxy/src/server/server.rs @@ -28,7 +28,7 @@ impl Server { let resetter = Server::wait_for_reset_signal(canceller.clone()); // spawn metrics service - let metrics = Arc::new(Metrics::new(config.metrics.clone())); + let metrics = Arc::new(Metrics::new(config.metrics)); { let canceller = canceller.clone(); let metrics = metrics.clone();