Skip to content

Commit

Permalink
more efficient logging
Browse files Browse the repository at this point in the history
  • Loading branch information
cswinter committed Feb 19, 2024
1 parent 7c50d3d commit 0453932
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions src/logging_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,17 @@ impl BackgroundWorker {
async fn flush(&self) {
let buffer = mem::take(&mut *self.events.lock().unwrap());
for (table, rows) in buffer.into_iter() {
fn bytes_in_row(row: &HashMap<String, f64>) -> usize {
row.iter()
.map(|(k, v)| k.len() + v.to_string().len())
.sum::<usize>()
}
let bytes = rows.iter().map(bytes_in_row).sum::<usize>();
let nrows = rows.len();
let data_batch = DataBatch { table: table.clone(), rows };
let serialized = bincode::serialize(&data_batch).unwrap();
log::debug!(
"Pushing {} events to {} ({} bytes)",
rows.len(),
nrows,
table,
bytes
serialized.len(),
);

let data_batch = DataBatch { table, rows };
let body = bincode::serialize(&data_batch).unwrap();
bincode::deserialize::<DataBatch>(&body[..]).unwrap();

let result = self.client.post(&self.url).body(body).send().await;
let result = self.client.post(&self.url).body(serialized).send().await;
match result {
Err(err) => {
log::warn!(
Expand Down

0 comments on commit 0453932

Please sign in to comment.