This commit is contained in:
Alexey
2026-07-13 12:20:24 +03:00
parent feb51cbf57
commit 73afeccae1
14 changed files with 105 additions and 151 deletions
+14 -21
View File
@@ -170,11 +170,9 @@ impl DirectBufferBudget {
}
fn set_target_bytes(&self, target: u64) {
let target = align_down(
target
.clamp(self.target_floor_bytes(), self.hard_limit_bytes)
as usize,
) as u64;
let target =
align_down(target.clamp(self.target_floor_bytes(), self.hard_limit_bytes) as usize)
as u64;
let previous = self.target_bytes.swap(target, Ordering::AcqRel);
if target < previous {
let generation = self
@@ -196,8 +194,7 @@ impl DirectBufferBudget {
/// Records a session that had to bypass the adaptive target at minimum size.
pub(crate) fn increment_minimum_fallback(&self) {
self.minimum_fallback_total
.fetch_add(1, Ordering::Relaxed);
self.minimum_fallback_total.fetch_add(1, Ordering::Relaxed);
}
/// Records a session rejected because the absolute ceiling was exhausted.
@@ -369,7 +366,9 @@ pub(crate) fn spawn_direct_buffer_budget_controller(
budget.update_system_sample(sample);
let snapshot = budget.snapshot();
let denied_delta = snapshot.promotion_denied_total.saturating_sub(previous_denied);
let denied_delta = snapshot
.promotion_denied_total
.saturating_sub(previous_denied);
previous_denied = snapshot.promotion_denied_total;
let fallback_delta = snapshot
.minimum_fallback_total
@@ -404,9 +403,7 @@ pub(crate) fn spawn_direct_buffer_budget_controller(
pool_snapshot.allocated,
pool_snapshot.allocated.saturating_sub(pool_snapshot.pooled),
);
stats.set_buffer_pool_replaced_nonstandard_total(
pool_snapshot.replaced_nonstandard,
);
stats.set_buffer_pool_replaced_nonstandard_total(pool_snapshot.replaced_nonstandard);
let headroom_target = if sample.total_bytes == 0 {
snapshot.hard_limit_bytes
@@ -454,11 +451,8 @@ fn connection_fill_pct(stats: &Stats, max_connections: u32) -> Option<u8> {
return None;
}
Some(
((stats
.get_current_connections_total()
.saturating_mul(100))
/ u64::from(max_connections))
.min(100) as u8,
((stats.get_current_connections_total().saturating_mul(100)) / u64::from(max_connections))
.min(100) as u8,
)
}
@@ -485,8 +479,7 @@ async fn read_system_memory_sample() -> SystemMemorySample {
let cgroup_v2_max = read_cgroup_limit("/sys/fs/cgroup/memory.max").await;
let cgroup_v2_current = read_u64_file("/sys/fs/cgroup/memory.current").await;
let cgroup_v1_max = read_cgroup_limit("/sys/fs/cgroup/memory/memory.limit_in_bytes").await;
let cgroup_v1_current =
read_u64_file("/sys/fs/cgroup/memory/memory.usage_in_bytes").await;
let cgroup_v1_current = read_u64_file("/sys/fs/cgroup/memory/memory.usage_in_bytes").await;
let cgroup_max = cgroup_v2_max.or(cgroup_v1_max);
let cgroup_current = cgroup_v2_current.or(cgroup_v1_current);
@@ -495,9 +488,9 @@ async fn read_system_memory_sample() -> SystemMemorySample {
(host, Some(limit)) => host.min(limit),
(host, None) => host,
};
let cgroup_available = cgroup_max.zip(cgroup_current).map(|(limit, current)| {
limit.saturating_sub(current)
});
let cgroup_available = cgroup_max
.zip(cgroup_current)
.map(|(limit, current)| limit.saturating_sub(current));
let available = match (host_available, cgroup_available) {
(0, Some(value)) => value,
(host, Some(value)) => host.min(value),
+15 -15
View File
@@ -346,21 +346,21 @@ where
Duration::from_secs(1800)
};
let relay_result = crate::proxy::relay::relay_direct_adaptive(
client_reader,
client_writer,
tg_reader,
tg_writer,
config.general.direct_relay_copy_buf_c2s_bytes,
config.general.direct_relay_copy_buf_s2c_bytes,
config.server.max_connections,
user,
Arc::clone(&stats),
config.access.user_data_quota.get(user).copied(),
traffic_lease,
relay_activity_timeout,
session_cancel.clone(),
Arc::clone(&shared.direct_buffer_budget),
);
client_reader,
client_writer,
tg_reader,
tg_writer,
config.general.direct_relay_copy_buf_c2s_bytes,
config.general.direct_relay_copy_buf_s2c_bytes,
config.server.max_connections,
user,
Arc::clone(&stats),
config.access.user_data_quota.get(user).copied(),
traffic_lease,
relay_activity_timeout,
session_cancel.clone(),
Arc::clone(&shared.direct_buffer_budget),
);
tokio::pin!(relay_result);
let relay_result = loop {
if let Some(cutover) =
+1 -1
View File
@@ -84,8 +84,8 @@ fn watchdog_delta(current: u64, previous: u64) -> u64 {
current.saturating_sub(previous)
}
mod io;
mod adaptive_copy;
mod io;
pub(crate) use self::adaptive_copy::relay_direct_adaptive;
+2 -7
View File
@@ -488,13 +488,8 @@ fn apply_global_pressure_demotion(
return;
}
*controller = SessionAdaptiveController::new(target);
let sizes = direct_copy_buffers_for_tier_with_ceilings(
target,
base.0,
base.1,
ceilings.0,
ceilings.1,
);
let sizes =
direct_copy_buffers_for_tier_with_ceilings(target, base.0, base.1, ceilings.0, ceilings.1);
set_desired_sizes(c2s_state, s2c_state, sizes);
lease.set_tier(target.as_u8() as usize);
budget.increment_global_pressure_demotion();
+1 -3
View File
@@ -9,10 +9,8 @@ use dashmap::DashMap;
use tokio::sync::{OwnedSemaphorePermit, Semaphore, mpsc};
use tokio_util::sync::CancellationToken;
use crate::proxy::direct_buffer_budget::{DirectBufferBudget, fallback_direct_buffer_hard_limit};
use crate::proxy::handshake::{AuthProbeSaturationState, AuthProbeState};
use crate::proxy::direct_buffer_budget::{
DirectBufferBudget, fallback_direct_buffer_hard_limit,
};
use crate::proxy::middle_relay::{DesyncDedupRotationState, RelayIdleCandidateRegistry};
use crate::proxy::traffic_limiter::TrafficLimiter;