fn build_a_bucket(limit: usize) -> Result<LeakyBucket> {
        let refill = max((limit as f64 / 10.0).round() as usize, 1); // minimum of 1 per second
        let tokens = max((limit as f64 / 2.0).round() as usize, 1);
        let interval = if refill == 1 { 1000 } else { 100 }; // 1 second if refill is 1

        Ok(LeakyBucket::builder()
            .refill_interval(Duration::from_millis(interval)) // add tokens every 0.1s
            .refill_amount(refill) // ex: 100 req/s -> 10 tokens per 0.1s
            .tokens(tokens) // reduce initial burst, 2 is arbitrary, but felt good
            .max(limit)
            .build()?)
    }
/// build a LeakyBucket, given a rate limit (as requests per second)
build a LeakyBucket, given a rate limit (as requests per second)
build a LeakyBucket given a rate limit ( as requests per second )
fn build_a_bucket(limit: usize) -> Result<LeakyBucket> {
        let refill = max((limit as f64 / 10.0).round() as usize, 1); // minimum of 1 per second
        let tokens = max((limit as f64 / 2.0).round() as usize, 1);
        let interval = if refill == 1 { 1000 } else { 100 }; // 1 second if refill is 1
        Ok(LeakyBucket::builder()
            .refill_interval(Duration::from_millis(interval)) // add tokens every 0.1s
            .refill_amount(refill) // ex: 100 req/s -> 10 tokens per 0.1s
            .tokens(tokens) // reduce initial burst, 2 is arbitrary, but felt good
            .max(limit)
            .build()?)
    }
fn build_a_bucket ( limit : usize ) -> Result < LeakyBucket > { let refill = max ( ( limit as f64 / 10.0 ) . round ( ) as usize , 1 ) ; // minimum of 1 per second let tokens = max ( ( limit as f64 / 2.0 ) . round ( ) as usize , 1 ) ; let interval = if refill == 1 { 1000 } else { 100 } ; // 1 second if refill is 1 Ok ( LeakyBucket :: builder ( ) . refill_interval ( Duration :: from_millis ( interval ) ) // add tokens every 0.1s . refill_amount ( refill ) // ex: 100 req/s -> 10 tokens per 0.1s . tokens ( tokens ) // reduce initial burst, 2 is arbitrary, but felt good . max ( limit ) . build ( ) ? ) }
build a LeakyBucket, given a rate limit (as requests per second)
build a LeakyBucket given a rate limit ( as requests per second )
limit
usize