mirror of
https://github.com/pezkuwichain/pezkuwi-telemetry.git
synced 2026-06-14 04:51:01 +00:00
Make server able to run old or new binary so that we can compare the actix version with this one
This commit is contained in:
@@ -16,7 +16,7 @@ async fn feed_sent_version_on_connect() {
|
||||
let server = start_server_debug().await;
|
||||
|
||||
// Connect a feed:
|
||||
let (_feed_tx, mut feed_rx) = server.get_core().connect().await.unwrap();
|
||||
let (_feed_tx, mut feed_rx) = server.get_core().connect_feed().await.unwrap();
|
||||
|
||||
// Expect a version response of 31:
|
||||
let feed_messages = feed_rx.recv_feed_messages().await.unwrap();
|
||||
@@ -37,7 +37,7 @@ async fn feed_ping_responded_to_with_pong() {
|
||||
let server = start_server_debug().await;
|
||||
|
||||
// Connect a feed:
|
||||
let (mut feed_tx, mut feed_rx) = server.get_core().connect().await.unwrap();
|
||||
let (mut feed_tx, mut feed_rx) = server.get_core().connect_feed().await.unwrap();
|
||||
|
||||
// Ping it:
|
||||
feed_tx.send_command("ping", "hello!").unwrap();
|
||||
@@ -65,7 +65,7 @@ async fn multiple_feeds_sent_version_on_connect() {
|
||||
// Connect a bunch of feeds:
|
||||
let mut feeds = server
|
||||
.get_core()
|
||||
.connect_multiple(1000)
|
||||
.connect_multiple_feeds(1000)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -107,7 +107,7 @@ async fn lots_of_mute_messages_dont_cause_a_deadlock() {
|
||||
let mut nodes = server
|
||||
.get_shard(shard_id)
|
||||
.unwrap()
|
||||
.connect_multiple(2000) // 1500 of these will be overquota.
|
||||
.connect_multiple_nodes(2000) // 1500 of these will be overquota.
|
||||
.await
|
||||
.expect("nodes can connect");
|
||||
|
||||
@@ -139,7 +139,7 @@ async fn lots_of_mute_messages_dont_cause_a_deadlock() {
|
||||
// receive any messages back.
|
||||
let mut feeds = server
|
||||
.get_core()
|
||||
.connect_multiple(1)
|
||||
.connect_multiple_feeds(1)
|
||||
.await
|
||||
.expect("feeds can connect");
|
||||
|
||||
@@ -168,7 +168,7 @@ async fn feed_add_and_remove_node() {
|
||||
let (mut node_tx, _node_rx) = server
|
||||
.get_shard(shard_id)
|
||||
.unwrap()
|
||||
.connect()
|
||||
.connect_node()
|
||||
.await
|
||||
.expect("can connect to shard");
|
||||
|
||||
@@ -199,7 +199,7 @@ async fn feed_add_and_remove_node() {
|
||||
tokio::time::sleep(Duration::from_millis(500)).await;
|
||||
|
||||
// Connect a feed.
|
||||
let (_feed_tx, mut feed_rx) = server.get_core().connect().await.unwrap();
|
||||
let (_feed_tx, mut feed_rx) = server.get_core().connect_feed().await.unwrap();
|
||||
|
||||
let feed_messages = feed_rx.recv_feed_messages().await.unwrap();
|
||||
assert!(feed_messages.contains(&FeedMessage::AddedChain {
|
||||
@@ -230,7 +230,7 @@ async fn feeds_told_about_chain_rename_and_stay_subscribed() {
|
||||
let (mut node_tx, _node_rx) = server
|
||||
.get_shard(shard_id)
|
||||
.unwrap()
|
||||
.connect()
|
||||
.connect_node()
|
||||
.await
|
||||
.expect("can connect to shard");
|
||||
|
||||
@@ -255,7 +255,7 @@ async fn feeds_told_about_chain_rename_and_stay_subscribed() {
|
||||
node_tx.send_json_text(node_init_msg(1, "Initial chain name", "Node 1")).unwrap();
|
||||
|
||||
// Connect a feed and subscribe to the above chain:
|
||||
let (mut feed_tx, mut feed_rx) = server.get_core().connect().await.unwrap();
|
||||
let (mut feed_tx, mut feed_rx) = server.get_core().connect_feed().await.unwrap();
|
||||
feed_tx.send_command("subscribe", "Initial chain name").unwrap();
|
||||
|
||||
// Feed is told about the chain, and the node on this chain:
|
||||
@@ -316,7 +316,7 @@ async fn feed_add_and_remove_shard() {
|
||||
let (mut node_tx, _node_rx) = server
|
||||
.get_shard(shard_id)
|
||||
.unwrap()
|
||||
.connect()
|
||||
.connect_node()
|
||||
.await
|
||||
.expect("can connect to shard");
|
||||
|
||||
@@ -345,7 +345,7 @@ async fn feed_add_and_remove_shard() {
|
||||
}
|
||||
|
||||
// Connect a feed.
|
||||
let (_feed_tx, mut feed_rx) = server.get_core().connect().await.unwrap();
|
||||
let (_feed_tx, mut feed_rx) = server.get_core().connect_feed().await.unwrap();
|
||||
|
||||
// The feed should be told about both of the chains that we've sent info about:
|
||||
let feed_messages = feed_rx.recv_feed_messages().await.unwrap();
|
||||
@@ -386,7 +386,7 @@ async fn feed_can_subscribe_and_unsubscribe_from_chain() {
|
||||
// Start server, add shard, connect node:
|
||||
let mut server = start_server_debug().await;
|
||||
let shard_id = server.add_shard().await.unwrap();
|
||||
let (mut node_tx, _node_rx) = server.get_shard(shard_id).unwrap().connect().await.unwrap();
|
||||
let (mut node_tx, _node_rx) = server.get_shard(shard_id).unwrap().connect_node().await.unwrap();
|
||||
|
||||
// Send a "system connected" message for a few nodes/chains:
|
||||
for id in 1..=3 {
|
||||
@@ -413,7 +413,7 @@ async fn feed_can_subscribe_and_unsubscribe_from_chain() {
|
||||
}
|
||||
|
||||
// Connect a feed
|
||||
let (mut feed_tx, mut feed_rx) = server.get_core().connect().await.unwrap();
|
||||
let (mut feed_tx, mut feed_rx) = server.get_core().connect_feed().await.unwrap();
|
||||
|
||||
let feed_messages = feed_rx.recv_feed_messages().await.unwrap();
|
||||
assert_contains_matches!(feed_messages, AddedChain { name, node_count: 1 } if name == "Local Testnet 1");
|
||||
|
||||
@@ -11,7 +11,11 @@ sudo sysctl -w kern.maxfiles=50000
|
||||
sudo sysctl -w kern.maxfilesperproc=50000
|
||||
ulimit -n 50000
|
||||
sudo sysctl -w kern.ipc.somaxconn=50000
|
||||
sudo sysctl -w kern.ipc.maxsockbuf=16777216
|
||||
```
|
||||
|
||||
In general, if you run into issues, it may be better to run this on a linux
|
||||
box; MacOS seems to hit limits quicker in general.
|
||||
*/
|
||||
|
||||
use futures::{ StreamExt };
|
||||
@@ -30,8 +34,15 @@ use common::node_types::BlockHash;
|
||||
/// ```sh
|
||||
/// SOAK_TEST_ARGS='--feeds 10 --nodes 100 --shards 4' cargo test -- soak_test --ignored --nocapture
|
||||
/// ```
|
||||
///
|
||||
/// You can also run this test against the pre-sharding actix binary like so:
|
||||
/// ```sh
|
||||
/// TELEMETRY_BIN=~/old_telemetry_binary SOAK_TEST_ARGS='--feeds 100 --nodes 100 --shards 4' cargo test -- soak_test --ignored --nocapture
|
||||
/// ```
|
||||
///
|
||||
/// Both will establish the same total number of connections and same the same messages.
|
||||
#[ignore]
|
||||
#[tokio::test]
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
|
||||
pub async fn soak_test() {
|
||||
let opts = get_soak_test_opts();
|
||||
run_soak_test(opts).await;
|
||||
@@ -54,7 +65,7 @@ async fn run_soak_test(opts: SoakTestOpts) {
|
||||
let mut conns = server
|
||||
.get_shard(shard_id)
|
||||
.unwrap()
|
||||
.connect_multiple(opts.nodes)
|
||||
.connect_multiple_nodes(opts.nodes)
|
||||
.await
|
||||
.expect("node connections failed");
|
||||
nodes.append(&mut conns);
|
||||
@@ -83,7 +94,7 @@ async fn run_soak_test(opts: SoakTestOpts) {
|
||||
// Connect feeds to the core:
|
||||
let mut feeds = server
|
||||
.get_core()
|
||||
.connect_multiple(opts.feeds)
|
||||
.connect_multiple_feeds(opts.feeds)
|
||||
.await
|
||||
.expect("feed connections failed");
|
||||
|
||||
@@ -93,33 +104,42 @@ async fn run_soak_test(opts: SoakTestOpts) {
|
||||
}
|
||||
|
||||
// Start sending "update" messages from nodes at time intervals.
|
||||
let bytes_in = Arc::new(AtomicUsize::new(0));
|
||||
let bytes_in2 = Arc::clone(&bytes_in);
|
||||
let send_handle = tokio::task::spawn(async move {
|
||||
let msg = json!({
|
||||
"id":1,
|
||||
"payload":{
|
||||
"bandwidth_download":576,
|
||||
"bandwidth_upload":576,
|
||||
"msg":"system.interval",
|
||||
"peers":1
|
||||
},
|
||||
"ts":"2021-07-12T10:37:48.330433+01:00"
|
||||
});
|
||||
let msg_bytes: &'static [u8] = Box::new(serde_json::to_vec(&msg).unwrap()).leak();
|
||||
|
||||
loop {
|
||||
let msg = json!({
|
||||
"id":1,
|
||||
"payload":{
|
||||
"bandwidth_download":576,
|
||||
"bandwidth_upload":576,
|
||||
"msg":"system.interval",
|
||||
"peers":1
|
||||
},
|
||||
"ts":"2021-07-12T10:37:48.330433+01:00"
|
||||
});
|
||||
let msg_bytes = serde_json::to_vec(&msg).unwrap();
|
||||
for (node_tx, _) in &mut nodes {
|
||||
node_tx.unbounded_send(SentMessage::Binary(msg_bytes.clone())).unwrap();
|
||||
// every ~1second we aim to have sent messages from all of the nodes. So we cycle through
|
||||
// the node IDs and send a message from each at roughly 1s / number_of_nodes.
|
||||
let mut interval = tokio::time::interval(Duration::from_secs_f64(1.0 / nodes.len() as f64));
|
||||
|
||||
for node_id in (0..nodes.len()).cycle() {
|
||||
interval.tick().await;
|
||||
let node_tx = &mut nodes[node_id].0;
|
||||
node_tx.unbounded_send(SentMessage::StaticBinary(msg_bytes)).unwrap();
|
||||
bytes_in2.fetch_add(msg_bytes.len(), Ordering::Relaxed);
|
||||
}
|
||||
tokio::time::sleep(Duration::from_millis(500)).await;
|
||||
}
|
||||
});
|
||||
|
||||
// Also start receiving messages, counting the bytes received so far.
|
||||
let bytes_out = Arc::new(AtomicUsize::new(0));
|
||||
for (_, mut feed_rx) in feeds {
|
||||
let bytes_out = bytes_out.clone();
|
||||
let bytes_out = Arc::clone(&bytes_out);
|
||||
tokio::task::spawn(async move {
|
||||
while let Some(msg) = feed_rx.next().await {
|
||||
let msg = msg.expect("message coule be received");
|
||||
let msg = msg.expect("message could be received");
|
||||
let num_bytes = msg.len();
|
||||
bytes_out.fetch_add(num_bytes, Ordering::Relaxed);
|
||||
}
|
||||
@@ -128,20 +148,26 @@ async fn run_soak_test(opts: SoakTestOpts) {
|
||||
|
||||
// Periodically report on bytes out
|
||||
tokio::task::spawn(async move {
|
||||
let mut last_bytes = 0;
|
||||
let mut last_now = std::time::Instant::now();
|
||||
let one_mb = 1024.0 * 1024.0;
|
||||
let mut last_bytes_in = 0;
|
||||
let mut last_bytes_out = 0;
|
||||
let mut n = 1;
|
||||
loop {
|
||||
tokio::time::sleep(Duration::from_secs(5)).await;
|
||||
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||
let bytes_in_val = bytes_in.load(Ordering::Relaxed);
|
||||
let bytes_out_val = bytes_out.load(Ordering::Relaxed);
|
||||
|
||||
let curr_now = std::time::Instant::now();
|
||||
let curr_bytes_out = bytes_out.load(Ordering::Relaxed);
|
||||
let secs_elapsed = (curr_now - last_now).as_secs_f64();
|
||||
let kbps: f64 = (curr_bytes_out - last_bytes) as f64 / 1024.0 / secs_elapsed;
|
||||
println!("#{}: MB in/out per measurement: {:.4} / {:.4}, total bytes in/out: {} / {})",
|
||||
n,
|
||||
(bytes_in_val - last_bytes_in) as f64 / one_mb,
|
||||
(bytes_out_val - last_bytes_out) as f64 / one_mb,
|
||||
bytes_in_val,
|
||||
bytes_out_val
|
||||
);
|
||||
|
||||
println!("output kbps: ~{}", kbps);
|
||||
|
||||
last_bytes = curr_bytes_out;
|
||||
last_now = curr_now;
|
||||
n += 1;
|
||||
last_bytes_in = bytes_in_val;
|
||||
last_bytes_out = bytes_out_val;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user