Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pingora-cache/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ ahash = { workspace = true }
hex = "0.4"
httparse = { workspace = true }
strum = { version = "0.26", features = ["derive"] }
rand = "0.8"
rand = "0.9"

[dev-dependencies]
tokio-test = "0.4"
Expand Down
2 changes: 1 addition & 1 deletion pingora-cache/src/eviction/lru.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ impl<const N: usize> EvictionManager for Manager<N> {
let dir_path = Path::new(&dir_path);
let final_path = dir_path.join(format!("{}.{i}", FILE_NAME));
// create a temporary filename using a randomized u32 hash to minimize the chance of multiple writers writing to the same tmp file
let random_suffix: u32 = rand::thread_rng().gen();
let random_suffix: u32 = rand::rng().random();
let temp_path =
dir_path.join(format!("{}.{i}.{:08x}.tmp", FILE_NAME, random_suffix));
let mut file = File::create(&temp_path)
Expand Down
2 changes: 1 addition & 1 deletion pingora-cache/src/eviction/simple_lru.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ impl EvictionManager for Manager {

let final_file_path = dir_path.join(FILE_NAME);
// create a temporary filename using a randomized u32 hash to minimize the chance of multiple writers writing to the same tmp file
let random_suffix: u32 = rand::thread_rng().gen();
let random_suffix: u32 = rand::rng().random();
let temp_file_path = dir_path.join(format!("{}.{:08x}.tmp", FILE_NAME, random_suffix));
let mut file = File::create(&temp_file_path).or_err_with(InternalError, || {
format!("fail to create temporary file {}", temp_file_path.display())
Expand Down
2 changes: 1 addition & 1 deletion pingora-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ parking_lot = { version = "0.12", features = ["arc_lock"] }
socket2 = { version = ">=0.4, <1.0.0", features = ["all"] }
flate2 = { version = "1", features = ["zlib-ng"], default-features = false }
sfv = "0.10.4"
rand = "0.8"
rand = "0.9"
ahash = { workspace = true }
unicase = "2"
brotli = "3"
Expand Down
4 changes: 2 additions & 2 deletions pingora-core/src/connectors/l4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::upstreams::peer::Peer;
use async_trait::async_trait;
use log::debug;
use pingora_error::{Context, Error, ErrorType::*, OrErr, Result};
use rand::seq::SliceRandom;
use rand::seq::IndexedRandom;
use std::net::SocketAddr as InetSocketAddr;
#[cfg(unix)]
use std::os::unix::io::AsRawFd;
Expand Down Expand Up @@ -222,7 +222,7 @@ pub(crate) fn bind_to_random<P: Peer>(
1 => Some(ips[0]),
_ => {
// pick a random bind ip
ips.choose(&mut rand::thread_rng()).copied()
ips.choose(&mut rand::rng()).copied()
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions pingora-core/src/connectors/offload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ impl OffloadRuntime {
}

pub fn get_runtime(&self, hash: u64) -> &Handle {
let mut rng = rand::thread_rng();
let mut rng = rand::rng();

// choose a shard based on hash and a random thread with in that shard
// e.g. say thread_per_shard=2, shard 1 thread 1 is 1 * 2 + 1 = 3
// [[th0, th1], [th2, th3], ...]
let shard = hash as usize % self.shards;
let thread_in_shard = rng.gen_range(0..self.thread_per_shard);
let thread_in_shard = rng.random_range(0..self.thread_per_shard);
let pools = self.pools.get_or_init(|| self.init_pools());
&pools[shard * self.thread_per_shard + thread_in_shard].0
}
Expand Down
2 changes: 1 addition & 1 deletion pingora-limits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ path = "src/lib.rs"
ahash = { workspace = true }

[dev-dependencies]
rand = "0.8"
rand = "0.9"
dashmap = "5"
dhat = "0"
float-cmp = "0.9.0"
Expand Down
6 changes: 3 additions & 3 deletions pingora-limits/benches/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ static ALLOC: dhat::Alloc = dhat::Alloc;
use ahash::RandomState;
use dashmap::DashMap;
use pingora_limits::estimator::Estimator;
use rand::distributions::Uniform;
use rand::{thread_rng, Rng};
use rand::distr::Uniform;
use rand::{rng, Rng};
use std::collections::HashMap;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
Expand Down Expand Up @@ -82,7 +82,7 @@ fn run_bench<T: Counter>(
distribution: &Uniform<u32>,
test_name: &str,
) {
let mut rng = thread_rng();
let mut rng = rng();
let before = Instant::now();
for _ in 0..samples {
let event: u32 = rng.sample(distribution);
Expand Down
2 changes: 1 addition & 1 deletion pingora-load-balancing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pingora-ketama = { version = "0.7.0", path = "../pingora-ketama" }
pingora-runtime = { version = "0.7.0", path = "../pingora-runtime" }
arc-swap = "1"
fnv = "1"
rand = "0.8"
rand = "0.9"
tokio = { workspace = true }
futures = "0"
log = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions pingora-load-balancing/src/selection/algorithms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl SelectionAlgorithm for Random {
}
fn next(&self, _key: &[u8]) -> u64 {
use rand::Rng;
let mut rng = rand::thread_rng();
rng.gen()
let mut rng = rand::rng();
rng.random()
}
}
2 changes: 1 addition & 1 deletion pingora-lru/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ path = "src/lib.rs"
hashbrown = "0"
parking_lot = "0"
arrayvec = "0"
rand = "0.8"
rand = "0.9"

[dev-dependencies]
lru = { workspace = true }
Expand Down
10 changes: 5 additions & 5 deletions pingora-lru/benches/bench_lru.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use rand::distributions::WeightedIndex;
use rand::distr::WeightedIndex;
use rand::prelude::*;
use std::sync::Arc;
use std::thread;
Expand Down Expand Up @@ -42,7 +42,7 @@ fn main() {
}

// single thread
let mut rng = thread_rng();
let mut rng = rand::rng();
let dist = WeightedIndex::new(WEIGHTS).unwrap();

let before = Instant::now();
Expand Down Expand Up @@ -82,7 +82,7 @@ fn main() {
for i in 0..THREADS {
let lru = lru.clone();
let handler = thread::spawn(move || {
let mut rng = thread_rng();
let mut rng = rand::rng();
let dist = WeightedIndex::new(WEIGHTS).unwrap();
let before = Instant::now();
for _ in 0..ITERATIONS {
Expand All @@ -106,7 +106,7 @@ fn main() {
for i in 0..THREADS {
let plru = plru.clone();
let handler = thread::spawn(move || {
let mut rng = thread_rng();
let mut rng = rand::rng();
let dist = WeightedIndex::new(WEIGHTS).unwrap();
let before = Instant::now();
for _ in 0..ITERATIONS {
Expand All @@ -128,7 +128,7 @@ fn main() {
for i in 0..THREADS {
let plru = plru.clone();
let handler = thread::spawn(move || {
let mut rng = thread_rng();
let mut rng = rand::rng();
let dist = WeightedIndex::new(WEIGHTS).unwrap();
let before = Instant::now();
for _ in 0..ITERATIONS {
Expand Down
2 changes: 1 addition & 1 deletion pingora-proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ h2 = { workspace = true }
once_cell = { workspace = true }
clap = { version = "4", features = ["derive"] }
regex = "1"
rand = "0.8"
rand = "0.9"

[dev-dependencies]
reqwest = { version = "0.11", features = [
Expand Down
4 changes: 2 additions & 2 deletions pingora-proxy/src/proxy_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1287,8 +1287,8 @@ pub mod range_filter {
// and it must not match the body content.
fn generate_boundary() -> String {
use rand::Rng;
let mut rng: rand::prelude::ThreadRng = rand::thread_rng();
format!("{:016x}", rng.gen::<u64>())
let mut rng: rand::rngs::ThreadRng = rand::rng();
format!("{:016x}", rng.random::<u64>())
}
pub fn calculate_multipart_length(&self) -> usize {
let mut total_length = 0;
Expand Down
2 changes: 1 addition & 1 deletion pingora-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ name = "pingora_runtime"
path = "src/lib.rs"

[dependencies]
rand = "0.8"
rand = "0.9"
tokio = { workspace = true, features = ["rt-multi-thread", "sync", "time"] }
once_cell = { workspace = true }
thread_local = "1"
Expand Down
8 changes: 4 additions & 4 deletions pingora-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ pub fn current_handle() -> Handle {
if let Some(pools) = CURRENT_HANDLE.get() {
// safety: the CURRENT_HANDLE is set when the pool is being initialized in init_pools()
let pools = pools.get().unwrap();
let mut rng = rand::thread_rng();
let index = rng.gen_range(0..pools.len());
let mut rng = rand::rng();
let index = rng.random_range(0..pools.len());
pools[index].clone()
} else {
// not NoStealRuntime, just check the current tokio runtime
Expand Down Expand Up @@ -153,9 +153,9 @@ impl NoStealRuntime {

/// Return the &[Handle] of a random thread of this runtime
pub fn get_runtime(&self) -> &Handle {
let mut rng = rand::thread_rng();
let mut rng = rand::rng();

let index = rng.gen_range(0..self.threads);
let index = rng.random_range(0..self.threads);
self.get_runtime_at(index)
}

Expand Down
Loading