p0: remove SharedArena from connection hot path (wasted 16KB/conn + pointless alloc_str writes)
swadhinbiswas committed 3 months ago
ee12950
1 parent f7229e3
commit ee12950
1 file changed
+3 -9
Showing 1 changed file+3-9
▼crates/justapi-core/src/server/mod.rs
+3-9
| @@ -14,7 +14,9 @@ use tokio::net::TcpListener; | ||
14 | 14 | #[cfg(feature = "compression")] |
15 | 15 | use crate::compress::CompressionMiddleware; |
16 | 16 | use crate::health::HealthRegistry; |
17 | -use crate::memory::{BufferPool, SharedArena}; | |
17 | +use crate::memory::BufferPool; | |
18 | +#[cfg(test)] | |
19 | +use crate::memory::SharedArena; | |
18 | 20 | use crate::metrics::{self, Metrics}; |
19 | 21 | use crate::middleware::{ |
20 | 22 | ApiKeyAuth, Cors, JwtAuth, MiddlewareChain, OAuth2Password, RateLimiter, SecurityHeaders, |
| @@ -1297,15 +1299,12 @@ async fn serve_connection( | ||
1297 | 1299 | // (connection-flood / slowloris resource exhaustion). |
1298 | 1300 | let _permit = conn_semaphore.acquire_owned().await.expect("connection semaphore closed"); |
1299 | 1301 | let io = TokioIo::new(stream); |
1300 | - let arena = Arc::new(SharedArena::new()); | |
1301 | 1302 | let token_clone = shutdown.clone(); |
1302 | 1303 | let spawn_metrics = metrics.clone(); |
1303 | 1304 | let conn_metrics = metrics.clone(); |
1304 | 1305 | conn_metrics.connection_opened(); |
1305 | 1306 | let svc = service_fn(move |mut req| { |
1306 | - arena.reset(); | |
1307 | 1307 | let chain = chain.clone(); |
1308 | - let arena = arena.clone(); | |
1309 | 1308 | let static_dir = static_dir.clone(); |
1310 | 1309 | let static_mounts = static_mounts.clone(); |
1311 | 1310 | let metrics = spawn_metrics.clone(); |
| @@ -1315,7 +1314,6 @@ async fn serve_connection( | ||
1315 | 1314 | async move { |
1316 | 1315 | let path = req.uri().path().to_string(); |
1317 | 1316 | let method = req.method().clone(); |
1318 | - let _arena_path = arena.alloc_str(&path); | |
1319 | 1317 | let start = std::time::Instant::now(); |
1320 | 1318 | req.extensions_mut().insert(peer_addr); |
1321 | 1319 | |
| @@ -1996,11 +1994,8 @@ async fn serve_with_tls( | ||
1996 | 1994 | match acceptor.accept(stream).await { |
1997 | 1995 | Ok(tls_stream) => { |
1998 | 1996 | let io = TokioIo::new(tls_stream); |
1999 | - let arena = Arc::new(SharedArena::new()); | |
2000 | 1997 | let svc = service_fn(move |mut req| { |
2001 | - arena.reset(); | |
2002 | 1998 | let chain = chain.clone(); |
2003 | - let arena = arena.clone(); | |
2004 | 1999 | let static_dir = static_dir.clone(); |
2005 | 2000 | let static_mounts = static_mounts.clone(); |
2006 | 2001 | let metrics = spawn_metrics.clone(); |
| @@ -2009,7 +2004,6 @@ async fn serve_with_tls( | ||
2009 | 2004 | let ws_handler = ws_handler.clone(); |
2010 | 2005 | async move { |
2011 | 2006 | let path = req.uri().path().to_string(); |
2012 | - let _arena_path = arena.alloc_str(&path); | |
2013 | 2007 | let start = std::time::Instant::now(); |
2014 | 2008 | req.extensions_mut().insert(peer_addr); |
2015 | 2009 | |
2016 | 2010 | |