From c59b87ff9c29547cf5b2308efbb936e80d4688e6 Mon Sep 17 00:00:00 2001 From: Dmitrii Dolgov <9erthalion6@gmail.com> Date: Fri, 14 Jun 2024 12:16:31 +0200 Subject: [PATCH 1/3] Keep connections open Currently the server side of network worker drops a connection after fnishing with it. Keep them open. --- src/worker/network.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/worker/network.rs b/src/worker/network.rs index e1010bb..2787797 100644 --- a/src/worker/network.rs +++ b/src/worker/network.rs @@ -10,6 +10,7 @@ use std::{ fmt::Display, io::{prelude::*, BufReader}, net::TcpListener, + thread, }; use crate::{BaseConfig, Worker, WorkerError, Workload, WorkloadConfig}; @@ -49,7 +50,16 @@ impl NetworkWorker { for stream in listener.incoming() { let mut stream = stream.unwrap(); - loop { + + // As a simplest solution to keep a connection open, spawn a + // thread. It's not the best one though, as we waste resources. + // For the purpose of only keeping connections open we could e.g. + // spawn only two threads, where the first one receives connections + // add add streams into the list of active, and the second iterates + // through streams and replies. This way the connections will have + // large latency, but for the purpose of networking workload it + // doesn't matter. + thread::spawn(move || loop { let mut buf_reader = BufReader::new(&stream); let mut buffer = String::new(); @@ -65,7 +75,6 @@ impl NetworkWorker { match stream.write_all(response.as_bytes()) { Ok(_) => { // Response is sent, handle the next one - break; } Err(e) => { trace!("ERROR: sending response, {}", e); @@ -77,7 +86,7 @@ impl NetworkWorker { trace!("ERROR: reading a line, {}", e) } } - } + }); } Ok(()) From 404e055412e772045c54d3f49ea1558e0439a891 Mon Sep 17 00:00:00 2001 From: Dmitrii Dolgov <9erthalion6@gmail.com> Date: Fri, 2 Aug 2024 16:26:30 +0200 Subject: [PATCH 2/3] Update src/worker/network.rs Wording Co-authored-by: Jouko Virtanen --- src/worker/network.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/worker/network.rs b/src/worker/network.rs index 2787797..0d35181 100644 --- a/src/worker/network.rs +++ b/src/worker/network.rs @@ -55,7 +55,7 @@ impl NetworkWorker { // thread. It's not the best one though, as we waste resources. // For the purpose of only keeping connections open we could e.g. // spawn only two threads, where the first one receives connections - // add add streams into the list of active, and the second iterates + // and adds streams into the list of active, and the second iterates // through streams and replies. This way the connections will have // large latency, but for the purpose of networking workload it // doesn't matter. From 057ceff53d54a8941fd4ae3e465dc342e59af531 Mon Sep 17 00:00:00 2001 From: Dmitrii Dolgov <9erthalion6@gmail.com> Date: Fri, 2 Aug 2024 16:26:39 +0200 Subject: [PATCH 3/3] Update src/worker/network.rs Wording Co-authored-by: Jouko Virtanen --- src/worker/network.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/worker/network.rs b/src/worker/network.rs index 0d35181..105c5c4 100644 --- a/src/worker/network.rs +++ b/src/worker/network.rs @@ -57,7 +57,7 @@ impl NetworkWorker { // spawn only two threads, where the first one receives connections // and adds streams into the list of active, and the second iterates // through streams and replies. This way the connections will have - // large latency, but for the purpose of networking workload it + // high latency, but for the purpose of networking workload it // doesn't matter. thread::spawn(move || loop { let mut buf_reader = BufReader::new(&stream);