Skip to content

Commit

Permalink
differentiate of the two throttling cases in stats: across connection…
Browse files Browse the repository at this point in the history
…s or per ip addr
  • Loading branch information
lijunwangs committed Apr 22, 2024
1 parent 49f441a commit 7b6d3cb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
9 changes: 4 additions & 5 deletions streamer/src/nonblocking/quic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,20 +233,19 @@ async fn run_server(
if let Ok(Some(connection)) = timeout_connection {
let remote_address = connection.remote_address();

let do_rate_limiting = true;
// first check overall connection rate limit:
if do_rate_limiting && !overall_connection_rate_limiter.check(&remote_address.ip()) {
stats.connection_throttled.fetch_add(1, Ordering::Relaxed);
if !overall_connection_rate_limiter.check(&remote_address.ip()) {
stats.connection_throttled_across_all.fetch_add(1, Ordering::Relaxed);
continue;
}

info!("Got a connection {remote_address:?}");
if do_rate_limiting && !rate_limiter.check(&remote_address.ip()) {
if !rate_limiter.check(&remote_address.ip()) {
info!(
"Reject connection from {:?} -- rate limiting exceeded",
remote_address
);
stats.connection_throttled.fetch_add(1, Ordering::Relaxed);
stats.connection_throttled_per_ipaddr.fetch_add(1, Ordering::Relaxed);
continue;
}
tokio::spawn(setup_connection(
Expand Down
12 changes: 9 additions & 3 deletions streamer/src/quic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ pub struct StreamStats {
pub(crate) connection_setup_error_locally_closed: AtomicUsize,
pub(crate) connection_removed: AtomicUsize,
pub(crate) connection_remove_failed: AtomicUsize,
pub(crate) connection_throttled: AtomicUsize,
pub(crate) connection_throttled_across_all: AtomicUsize,
pub(crate) connection_throttled_per_ipaddr: AtomicUsize,
pub(crate) throttled_streams: AtomicUsize,
pub(crate) stream_load_ema: AtomicUsize,
pub(crate) stream_load_ema_overflow: AtomicUsize,
Expand Down Expand Up @@ -320,8 +321,13 @@ impl StreamStats {
i64
),
(
"connection_throttled",
self.connection_throttled.swap(0, Ordering::Relaxed),
"connection_throttled_across_all",
self.connection_throttled_across_all.swap(0, Ordering::Relaxed),
i64
),
(
"connection_throttled_per_ipaddr",
self.connection_throttled_per_ipaddr.swap(0, Ordering::Relaxed),
i64
),
(
Expand Down

0 comments on commit 7b6d3cb

Please sign in to comment.