Skip to content

Commit 4a5cd54

Browse files
jsdwvovacha
andauthored
Backend: add parallel cpu benchmarks processing (#603)
* Add parallel cpu benchmarks processing * Expose Parallel Hashrate Score in UI (as 'Parallel CPU speed') * Remove unused variable and fix cfg(debug) * Fix tests after removing old_chain_name * Update Dockerfile * bullseye for both images --------- Co-authored-by: Volodymyr Brazhnyk <volbr@pm.me>
1 parent 6357763 commit 4a5cd54

11 files changed

Lines changed: 39 additions & 16 deletions

File tree

backend/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
FROM docker.io/paritytech/ci-linux:production as builder
1+
FROM docker.io/paritytech/ci-unified:bullseye-1.88.0-2025-06-27-v202507221446 AS builder
22

33
ARG PROFILE=release
44
WORKDIR /app
55

66
COPY . .
77

8-
RUN cargo build --${PROFILE} --bins
8+
RUN cargo build --${PROFILE} --bins -j 2
99

1010
# MAIN IMAGE FOR PEOPLE TO PULL --- small one#
11-
FROM docker.io/debian:buster-slim
11+
FROM docker.io/debian:bullseye-slim
1212
LABEL maintainer="Parity Technologies"
1313
LABEL description="Substrate Telemetry Backend shard/core binaries, static build"
1414

backend/common/src/node_message.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ pub struct NodeHwBench {
9898
pub memory_memcpy_score: u64,
9999
pub disk_sequential_write_score: Option<u64>,
100100
pub disk_random_write_score: Option<u64>,
101+
pub parallel_cpu_hashrate_score: Option<u64>,
102+
//// Dev note: this exists but isn't needed yet:
103+
// pub parallel_cpu_cores: Option<usize>,
101104
}
102105

103106
impl Payload {

backend/common/src/node_types.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ pub struct NodeHwBench {
7373
pub disk_sequential_write_score: Option<u64>,
7474
/// Random disk write speed in MB/s.
7575
pub disk_random_write_score: Option<u64>,
76+
/// The parallel CPU speed, as measured in how many MB/s it can hash using the BLAKE2b-256 hash.
77+
pub parallel_cpu_hashrate_score: Option<u64>,
78+
//// Dev note: this exists but isn't needed yet:
79+
// /// The number of cores used for the parallel CPU benchmark.
80+
// pub parallel_cpu_cores: Option<usize>,
7681
}
7782

7883
/// A couple of node statistics.

backend/telemetry_core/src/feed_message.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ pub struct ChainStats {
246246
pub linux_distro: Ranking<String>,
247247
pub is_virtual_machine: Ranking<bool>,
248248
pub cpu_hashrate_score: Ranking<(u32, Option<u32>)>,
249+
pub parallel_cpu_hashrate_score: Ranking<(u32, Option<u32>)>,
249250
pub memory_memcpy_score: Ranking<(u32, Option<u32>)>,
250251
pub disk_sequential_write_score: Ranking<(u32, Option<u32>)>,
251252
pub disk_random_write_score: Ranking<(u32, Option<u32>)>,

backend/telemetry_core/src/state/chain.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ impl Chain {
213213
memory_memcpy_score: hwbench.memory_memcpy_score,
214214
disk_sequential_write_score: hwbench.disk_sequential_write_score,
215215
disk_random_write_score: hwbench.disk_random_write_score,
216+
parallel_cpu_hashrate_score: hwbench.parallel_cpu_hashrate_score,
216217
};
217218
let old_hwbench = node.update_hwbench(new_hwbench);
218219
// The `hwbench` for this node has changed, send an updated "add node".

backend/telemetry_core/src/state/chain_stats.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ pub struct ChainStatsCollator {
149149
disk_sequential_write_score: Counter<(u32, Option<u32>)>,
150150
disk_random_write_score: Counter<(u32, Option<u32>)>,
151151
cpu_vendor: Counter<String>,
152+
parallel_cpu_hashrate_score: Counter<(u32, Option<u32>)>,
152153
}
153154

154155
impl ChainStatsCollator {
@@ -241,6 +242,14 @@ impl ChainStatsCollator {
241242
.as_ref(),
242243
op,
243244
);
245+
246+
self.parallel_cpu_hashrate_score.modify(
247+
hwbench
248+
.and_then(|hwbench| hwbench.parallel_cpu_hashrate_score)
249+
.map(|score| bucket_score(score, REFERENCE_CPU_SCORE))
250+
.as_ref(),
251+
op,
252+
);
244253
}
245254

246255
pub fn generate(&self) -> ChainStats {
@@ -261,6 +270,7 @@ impl ChainStatsCollator {
261270
.generate_ranking_ordered(),
262271
disk_random_write_score: self.disk_random_write_score.generate_ranking_ordered(),
263272
cpu_vendor: self.cpu_vendor.generate_ranking_top(10),
273+
parallel_cpu_hashrate_score: self.parallel_cpu_hashrate_score.generate_ranking_top(10),
264274
}
265275
}
266276
}

backend/telemetry_core/src/state/state.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ impl<'a> AddNodeResult<'a> {
7979
pub struct NodeAddedToChain<'a> {
8080
/// The ID assigned to this node.
8181
pub id: NodeId,
82-
/// The old label of the chain.
83-
pub old_chain_label: Box<str>,
8482
/// The new label of the chain.
8583
pub new_chain_label: &'a str,
8684
/// The node that was added.
@@ -97,8 +95,6 @@ pub struct RemovedNode {
9795
pub chain_node_count: usize,
9896
/// Has the chain label been updated?
9997
pub has_chain_label_changed: bool,
100-
/// The old label of the chain.
101-
pub old_chain_label: Box<str>,
10298
/// Genesis hash of the chain to be updated.
10399
pub chain_genesis_hash: BlockHash,
104100
/// The new label of the chain.
@@ -164,7 +160,6 @@ impl State {
164160
);
165161

166162
let node = Node::new(node_details);
167-
let old_chain_label = chain.label().into();
168163

169164
match chain.add_node(node) {
170165
chain::AddNodeResult::Overquota => AddNodeResult::ChainOverQuota,
@@ -174,7 +169,6 @@ impl State {
174169
AddNodeResult::NodeAddedToChain(NodeAddedToChain {
175170
id: NodeId(chain_id, id),
176171
node: chain.get_node(id).expect("node added above"),
177-
old_chain_label,
178172
new_chain_label: chain.label(),
179173
chain_node_count: chain.node_count(),
180174
has_chain_label_changed: chain_renamed,
@@ -186,7 +180,6 @@ impl State {
186180
/// Remove a node
187181
pub fn remove_node(&mut self, NodeId(chain_id, chain_node_id): NodeId) -> Option<RemovedNode> {
188182
let chain = self.chains.get_mut(chain_id)?;
189-
let old_chain_label = chain.label().into();
190183

191184
// Actually remove the node
192185
let remove_result = chain.remove_node(chain_node_id);
@@ -204,7 +197,6 @@ impl State {
204197
}
205198

206199
Some(RemovedNode {
207-
old_chain_label,
208200
new_chain_label,
209201
chain_node_count,
210202
chain_genesis_hash,
@@ -320,12 +312,11 @@ mod test {
320312
};
321313

322314
assert_eq!(add_node_result.id, NodeId(0.into(), 0.into()));
323-
assert_eq!(&*add_node_result.old_chain_label, "");
324315
assert_eq!(&*add_node_result.new_chain_label, "Chain One");
325316
assert_eq!(add_node_result.chain_node_count, 1);
326317
assert_eq!(add_node_result.has_chain_label_changed, true);
327318

328-
let add_result = state.add_node(chain1_genesis, node("A", "Chain One"));
319+
let add_result = state.add_node(chain1_genesis, node("A", "Chain Two"));
329320

330321
let add_node_result = match add_result {
331322
AddNodeResult::ChainOnDenyList => panic!("Chain not on deny list"),
@@ -334,7 +325,7 @@ mod test {
334325
};
335326

336327
assert_eq!(add_node_result.id, NodeId(0.into(), 1.into()));
337-
assert_eq!(&*add_node_result.old_chain_label, "Chain One");
328+
// Chain One and Chain Two as common, so Chain One is kept.
338329
assert_eq!(&*add_node_result.new_chain_label, "Chain One");
339330
assert_eq!(add_node_result.chain_node_count, 2);
340331
assert_eq!(add_node_result.has_chain_label_changed, false);

backend/telemetry_shard/src/json_message/node_message.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ pub struct NodeHwBench {
211211
pub memory_memcpy_score: u64,
212212
pub disk_sequential_write_score: Option<u64>,
213213
pub disk_random_write_score: Option<u64>,
214+
pub parallel_cpu_hashrate_score: Option<u64>,
215+
//// This exists but isn't needed at the moment:
216+
// pub parallel_cpu_cores: Option<usize>,
214217
}
215218

216219
impl From<NodeHwBench> for node_types::NodeHwBench {
@@ -220,6 +223,7 @@ impl From<NodeHwBench> for node_types::NodeHwBench {
220223
memory_memcpy_score: hwbench.memory_memcpy_score,
221224
disk_sequential_write_score: hwbench.disk_sequential_write_score,
222225
disk_random_write_score: hwbench.disk_random_write_score,
226+
parallel_cpu_hashrate_score: hwbench.parallel_cpu_hashrate_score,
223227
}
224228
}
225229
}
@@ -231,6 +235,7 @@ impl From<NodeHwBench> for internal::NodeHwBench {
231235
memory_memcpy_score: msg.memory_memcpy_score,
232236
disk_sequential_write_score: msg.disk_sequential_write_score,
233237
disk_random_write_score: msg.disk_random_write_score,
238+
parallel_cpu_hashrate_score: msg.parallel_cpu_hashrate_score,
234239
}
235240
}
236241
}

backend/telemetry_shard/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,14 +323,14 @@ where
323323
// Deserialize from JSON, warning in debug mode if deserialization fails:
324324
let node_message: json_message::NodeMessage = match serde_json::from_slice(&bytes) {
325325
Ok(node_message) => node_message,
326-
#[cfg(debug)]
326+
#[cfg(debug_assertions)]
327327
Err(e) => {
328328
let bytes: &[u8] = bytes.get(..512).unwrap_or_else(|| &bytes);
329329
let msg_start = std::str::from_utf8(bytes).unwrap_or_else(|_| "INVALID UTF8");
330330
log::warn!("Failed to parse node message ({msg_start}): {e}");
331331
continue;
332332
},
333-
#[cfg(not(debug))]
333+
#[cfg(not(debug_assertions))]
334334
Err(_) => {
335335
continue;
336336
}

frontend/src/common/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ export type ChainStats = {
131131
linux_distro: Maybe<Ranking<string>>;
132132
linux_kernel: Maybe<Ranking<string>>;
133133
cpu_hashrate_score: Maybe<Ranking<Range>>;
134+
parallel_cpu_hashrate_score: Maybe<Ranking<Range>>;
134135
memory_memcpy_score: Maybe<Ranking<Range>>;
135136
disk_sequential_write_score: Maybe<Ranking<Range>>;
136137
disk_random_write_score: Maybe<Ranking<Range>>;

0 commit comments

Comments
 (0)