about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBaitinq <[email protected]>2024-07-22 22:55:03 +0200
committerBaitinq <[email protected]>2024-07-22 22:55:03 +0200
commitf672efa31d83da04866b849a28cf803c438dde84 (patch)
treefbcbe5a2af54087c95409ac493016fca3f967489
parentfs-tracer: handle close syscall and properly serialize reqs (diff)
downloadfs-tracer-f672efa31d83da04866b849a28cf803c438dde84.tar.gz
fs-tracer-f672efa31d83da04866b849a28cf803c438dde84.tar.bz2
fs-tracer-f672efa31d83da04866b849a28cf803c438dde84.zip
fs-tracer: use time based batching
-rw-r--r--fs-tracer/src/main.rs11
1 files changed, 7 insertions, 4 deletions
diff --git a/fs-tracer/src/main.rs b/fs-tracer/src/main.rs
index 1f9626c..e7a85bf 100644
--- a/fs-tracer/src/main.rs
+++ b/fs-tracer/src/main.rs
@@ -14,6 +14,7 @@ use std::sync::{
     atomic::{AtomicBool, Ordering},
     Arc,
 };
+use std::time::{Duration, Instant};
 
 #[tokio::main]
 async fn main() -> Result<(), anyhow::Error> {
@@ -110,6 +111,9 @@ async fn main() -> Result<(), anyhow::Error> {
 
     drop(resolved_files_send);
 
+    let batch_timeout = Duration::from_secs(40);
+    let mut last_sent_time = Instant::now();
+
     let mut resolved_files_for_request: Vec<FSTracerFile> = vec![];
     for elt in &resolved_files_recv {
         info!("HELLO123!");
@@ -117,20 +121,19 @@ async fn main() -> Result<(), anyhow::Error> {
             continue;
         }
         resolved_files_for_request.push(elt);
-        if resolved_files_for_request.len() < 40 {
-            //TODO: This is not good, maybe time
-            //based?
+        if last_sent_time.elapsed() < batch_timeout {
             continue;
         }
 
         info!("SENDING REQUEST!");
         send_request(&url, &fs_tracer_api_key, &resolved_files_for_request);
         resolved_files_for_request.clear();
+        last_sent_time = Instant::now();
     }
 
     info!("All threads stopped, exiting now...");
 
-    if !resolved_files_for_request.len() > 1 {
+    if !resolved_files_for_request.len() > 0 {
         send_request(&url, &fs_tracer_api_key, &resolved_files_for_request);
     }