Skip to content

Commit

Permalink
latency ringbuffer to datetime
Browse files Browse the repository at this point in the history
  • Loading branch information
jr1221 committed Sep 28, 2024
1 parent 17e0c83 commit bfa7f30
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions scylla-server/src/processors/mqtt_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::{
time::{Duration, SystemTime},
};

use chrono::TimeDelta;
use prisma_client_rust::bigdecimal::ToPrimitive;
use protobuf::Message;
use ringbuffer::RingBuffer;
Expand Down Expand Up @@ -128,7 +129,7 @@ impl MqttProcessor {
let mut view_interval = tokio::time::interval(Duration::from_secs(3));

let mut latency_interval = tokio::time::interval(Duration::from_millis(250));
let mut latency_ringbuffer = ringbuffer::AllocRingBuffer::<i64>::new(20);
let mut latency_ringbuffer = ringbuffer::AllocRingBuffer::<TimeDelta>::new(20);

let mut upload_counter: u8 = 0;

Expand All @@ -153,7 +154,7 @@ impl MqttProcessor {
Some(msg) => msg,
None => continue
};
latency_ringbuffer.push((chrono::offset::Utc::now() - msg.timestamp).num_milliseconds());
latency_ringbuffer.push(chrono::offset::Utc::now() - msg.timestamp);
self.send_db_msg(msg.clone()).await;
self.send_socket_msg(msg, &mut upload_counter);
},
Expand Down Expand Up @@ -181,7 +182,7 @@ impl MqttProcessor {
let avg_latency = if latency_ringbuffer.is_empty() {
0
} else {
latency_ringbuffer.iter().sum::<i64>() / latency_ringbuffer.len().to_i64().unwrap_or_default()
latency_ringbuffer.iter().sum::<TimeDelta>().num_milliseconds() / latency_ringbuffer.len().to_i64().unwrap_or_default()
};

let client_data = ClientData {
Expand Down
2 changes: 1 addition & 1 deletion scylla-server/src/proto/serverdata.proto
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
syntax = "proto3";

package serverdata.v1;
package serverdata.v2;

message ServerData {
// ensure old type is reserved
Expand Down

0 comments on commit bfa7f30

Please sign in to comment.