Skip to content

Commit

Permalink
minor improvments for simian army
Browse files Browse the repository at this point in the history
  • Loading branch information
fulmicoton committed Dec 8, 2023
1 parent baf224c commit 9d39e1b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
13 changes: 13 additions & 0 deletions quickwit/quickwit-common/src/rate_limiter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,19 @@ impl RateLimiter {
}
}

pub fn acquire_with_duration(&mut self, num_permits: u64) -> Option<Duration> {
if self.acquire_inner(num_permits) {
return None;
}
self.refill(Instant::now());
if self.acquire_inner(num_permits) {
return None;
}
let missing = num_permits - self.available_permits;
let wait = Duration::from_micros(missing * self.refill_period_micros / self.refill_amount);
Some(wait)
}

pub fn acquire_bytes(&mut self, bytes: ByteSize) -> bool {
self.acquire(bytes.as_u64())
}
Expand Down
4 changes: 4 additions & 0 deletions quickwit/quickwit-rest-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ pub mod error;
pub mod models;
pub mod rest_client;

// re-exports
pub use quickwit_config::ConfigFormat;
pub use reqwest::Url;

pub(crate) struct BatchLineReader {
buf_reader: BufReader<Box<dyn AsyncRead + Send + Sync + Unpin>>,
buffer: Vec<u8>,
Expand Down
3 changes: 2 additions & 1 deletion quickwit/quickwit-rest-client/src/rest_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,12 @@ impl<'a> IndexClient<'a> {

pub async fn create(
&self,
body: Bytes,
index_config: &str,
config_format: ConfigFormat,
overwrite: bool,
) -> Result<IndexMetadata, Error> {
let header_map = header_from_config_format(config_format);
let body = bytes::Bytes::from(index_config.to_string());
let response = self
.transport
.send(
Expand Down

0 comments on commit 9d39e1b

Please sign in to comment.