Skip to content

Commit

Permalink
Add memory and flops stats to NodeTelemetry (#1358)
Browse files Browse the repository at this point in the history
Co-authored-by: duc-nx <>
  • Loading branch information
duc-nx authored Feb 19, 2025
1 parent 9a050e6 commit f372fdb
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 6 deletions.
83 changes: 80 additions & 3 deletions clients/cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions clients/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ native-tls = "0.2"
serde ={ version = "1.0.217", features = ["derive"]}
serde_json = { version = "1.0.138"}
regex = "1.5"
sysinfo = "0.33.1"

nexus-core = { git = "https://github.com/nexus-xyz/nexus-zkvm", branch = "neo", package = "nexus-core" }
nexus-vm = { git = "https://github.com/nexus-xyz/nexus-zkvm", branch = "neo", package = "nexus-vm" }
Expand Down
1 change: 1 addition & 0 deletions clients/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mod node_id_manager;
mod orchestrator_client;
mod setup;
mod utils;
mod memory_stats;

// use setup::SetupResult;

Expand Down
34 changes: 34 additions & 0 deletions clients/cli/src/memory_stats.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use std::process;
use sysinfo::System;

// We encode the memory usage to i32 type at client
pub fn bytes_to_mb_i32(bytes: u64) -> i32 {
// Convert to MB with 3 decimal places of precision
// Multiply by 1000 to preserve 3 decimal places
((bytes as f64 * 1000.0) / 1_048_576.0).round() as i32
}

// At server, we decode the memory usage from i32 to f32 to get correct memory usage
#[allow(dead_code)]
pub fn mb_i32_to_f32(mb: i32) -> f32 {
// Convert back to f32, dividing by 1000 to get the correct value
(mb as f32) / 1000.0
}

pub fn get_memory_info() -> (i32, i32) {
let mut system = System::new_all();
system.refresh_all();

let current_pid = process::id();
let current_process = system
.process(sysinfo::Pid::from(current_pid as usize))
.expect("Failed to get current process");

let program_memory = current_process.memory();
let total_memory = system.total_memory();

(
bytes_to_mb_i32(program_memory),
bytes_to_mb_i32(total_memory),
)
}
11 changes: 8 additions & 3 deletions clients/cli/src/orchestrator_client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::config;
use crate::flops::measure_flops;
use crate::memory_stats::get_memory_info;
use crate::nexus_orchestrator::{
GetProofTaskRequest, GetProofTaskResponse, NodeType, SubmitProofRequest,
};
Expand Down Expand Up @@ -119,15 +121,18 @@ impl OrchestratorClient {
proof_hash: &str,
proof: Vec<u8>,
) -> Result<(), Box<dyn std::error::Error>> {
let (program_memory, total_memory) = get_memory_info();
let flops = measure_flops();

let request = SubmitProofRequest {
node_id: node_id.to_string(),
node_type: NodeType::CliProver as i32,
proof_hash: proof_hash.to_string(),
proof,
node_telemetry: Some(crate::nexus_orchestrator::NodeTelemetry {
flops_per_sec: Some(1),
memory_used: Some(1),
memory_capacity: Some(1),
flops_per_sec: Some(flops as i32),
memory_used: Some(program_memory),
memory_capacity: Some(total_memory),
location: Some("US".to_string()),
}),
};
Expand Down

0 comments on commit f372fdb

Please sign in to comment.