Improved testing capabilities and fixed missing finished status in multithreading
This commit is contained in:
+6
-2
@@ -1,4 +1,5 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <threads.h>
|
#include <threads.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -7,7 +8,6 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "multiprocessing.h"
|
#include "multiprocessing.h"
|
||||||
#include "pipeline.h"
|
|
||||||
#include "queue.h"
|
#include "queue.h"
|
||||||
#include "scanner.h"
|
#include "scanner.h"
|
||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
@@ -87,11 +87,15 @@ int send_chunks_multithreaded(void *pipeline_context) {
|
|||||||
&context->condition_not_empty_loader,
|
&context->condition_not_empty_loader,
|
||||||
&context->condition_not_full_loader, &context->loader_done);
|
&context->condition_not_full_loader, &context->loader_done);
|
||||||
if (current_chunk == NULL) {
|
if (current_chunk == NULL) {
|
||||||
|
send_status(client->file_descriptor, FINISHED);
|
||||||
client_disconnect(client);
|
client_disconnect(client);
|
||||||
client_delete(client);
|
client_delete(client);
|
||||||
return thrd_success;
|
return thrd_success;
|
||||||
}
|
}
|
||||||
send_chunk(client, current_chunk, use_compression);
|
if (send_chunk(client, current_chunk, use_compression) != 0) {
|
||||||
|
perror("Something unexpected happend while sending the chunk");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
chunk_destroy(current_chunk);
|
chunk_destroy(current_chunk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,8 +21,6 @@ NET_LIMIT_CMD = f"sudo tc qdisc add dev {NETWORK_INTERFACE} root netem rate {NET
|
|||||||
NET_RESET_CMD = f"sudo tc qdisc del dev {NETWORK_INTERFACE} root".split()
|
NET_RESET_CMD = f"sudo tc qdisc del dev {NETWORK_INTERFACE} root".split()
|
||||||
|
|
||||||
# --- Build the client command prefix with throttling ---
|
# --- Build the client command prefix with throttling ---
|
||||||
# This uses systemd-run to wrap the original client command with I/O limits.
|
|
||||||
# The entire command must be run with sudo.
|
|
||||||
CLIENT_CMD_PREFIX = [
|
CLIENT_CMD_PREFIX = [
|
||||||
"sudo",
|
"sudo",
|
||||||
"systemd-run",
|
"systemd-run",
|
||||||
@@ -48,16 +46,30 @@ TEST_CASES = [
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
results = []
|
|
||||||
|
|
||||||
print("🚀 Starting benchmark...")
|
def run_suite(env_name, apply_limits):
|
||||||
print(f"Limiting Disk I/O: Reads <= {READ_BPS_MAX}, Writes <= {WRITE_BPS_MAX}")
|
results = []
|
||||||
print("Limiting Network: Simulating low bandwidth and high latency")
|
print(f"\n{'=' * 60}")
|
||||||
|
print(f"🚀 Starting Suite: {env_name}")
|
||||||
|
print(f"{'=' * 60}")
|
||||||
|
|
||||||
|
if apply_limits:
|
||||||
|
print(
|
||||||
|
f"Applying Disk I/O Limits: Reads <= {READ_BPS_MAX}, Writes <= {WRITE_BPS_MAX}"
|
||||||
|
)
|
||||||
|
print(f"Applying Network Limits: {NET_LIMIT}, {NET_DELAY} delay")
|
||||||
|
client_prefix = CLIENT_CMD_PREFIX
|
||||||
|
else:
|
||||||
|
print("Running Baseline (No limits applied)")
|
||||||
|
client_prefix = [] # Run normally without systemd-run/limits
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# # SETUP: Apply network limit
|
# SETUP: Apply or ensure clean network limits
|
||||||
print("Applying network limits...")
|
if apply_limits:
|
||||||
subprocess.run(NET_LIMIT_CMD, check=True)
|
subprocess.run(NET_LIMIT_CMD, check=True)
|
||||||
|
else:
|
||||||
|
# Silently attempt to clear any leftover rules just to ensure a clean baseline
|
||||||
|
subprocess.run(NET_RESET_CMD, capture_output=True)
|
||||||
|
|
||||||
for case in TEST_CASES:
|
for case in TEST_CASES:
|
||||||
name = case["name"]
|
name = case["name"]
|
||||||
@@ -72,14 +84,16 @@ try:
|
|||||||
server_process = subprocess.Popen(
|
server_process = subprocess.Popen(
|
||||||
SERVER_CMD, stdout=subprocess.DEVNULL, stderr=None
|
SERVER_CMD, stdout=subprocess.DEVNULL, stderr=None
|
||||||
)
|
)
|
||||||
time.sleep(5) # Allow server to bind to port
|
time.sleep(0.5) # Allow server to bind to port
|
||||||
|
|
||||||
# 2. Build and run the client
|
# 2. Build and run the client
|
||||||
client_cmd = CLIENT_CMD_PREFIX + base_client_cmd + flags
|
client_cmd = client_prefix + base_client_cmd + flags
|
||||||
print(f" Running client: {' '.join(client_cmd)}")
|
print(f" Running client: {' '.join(client_cmd)}")
|
||||||
|
|
||||||
start_time = time.monotonic()
|
start_time = time.monotonic()
|
||||||
client_result = subprocess.run(client_cmd, text=True, capture_output=True)
|
client_result = subprocess.run(
|
||||||
|
client_cmd, text=True, capture_output=True
|
||||||
|
)
|
||||||
end_time = time.monotonic()
|
end_time = time.monotonic()
|
||||||
|
|
||||||
duration = end_time - start_time
|
duration = end_time - start_time
|
||||||
@@ -87,6 +101,7 @@ try:
|
|||||||
if client_result.returncode == 0:
|
if client_result.returncode == 0:
|
||||||
results.append(
|
results.append(
|
||||||
{
|
{
|
||||||
|
"environment": env_name,
|
||||||
"name": name,
|
"name": name,
|
||||||
"status": "Success",
|
"status": "Success",
|
||||||
"time": f"{duration:.4f}s",
|
"time": f"{duration:.4f}s",
|
||||||
@@ -106,6 +121,7 @@ try:
|
|||||||
)
|
)
|
||||||
results.append(
|
results.append(
|
||||||
{
|
{
|
||||||
|
"environment": env_name,
|
||||||
"name": name,
|
"name": name,
|
||||||
"status": "Failed",
|
"status": "Failed",
|
||||||
"time": "N/A",
|
"time": "N/A",
|
||||||
@@ -117,6 +133,7 @@ try:
|
|||||||
print(" ⚠️ Timeout (exceeded 15s)")
|
print(" ⚠️ Timeout (exceeded 15s)")
|
||||||
results.append(
|
results.append(
|
||||||
{
|
{
|
||||||
|
"environment": env_name,
|
||||||
"name": name,
|
"name": name,
|
||||||
"status": "Timeout",
|
"status": "Timeout",
|
||||||
"time": "N/A",
|
"time": "N/A",
|
||||||
@@ -126,7 +143,13 @@ try:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f" ❌ Error: {e}")
|
print(f" ❌ Error: {e}")
|
||||||
results.append(
|
results.append(
|
||||||
{"name": name, "status": "Error", "time": "N/A", "error": str(e)}
|
{
|
||||||
|
"environment": env_name,
|
||||||
|
"name": name,
|
||||||
|
"status": "Error",
|
||||||
|
"time": "N/A",
|
||||||
|
"error": str(e),
|
||||||
|
}
|
||||||
)
|
)
|
||||||
finally:
|
finally:
|
||||||
# Clean up the server for this test case
|
# Clean up the server for this test case
|
||||||
@@ -141,25 +164,52 @@ try:
|
|||||||
|
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
print(f"❌ Error running system limit command: {' '.join(e.cmd)}")
|
print(f"❌ Error running system limit command: {' '.join(e.cmd)}")
|
||||||
print("Are you running this script with 'sudo'?")
|
print("Are you running this script with 'sudo' privileges?")
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
# TEARDOWN: Remove network limits
|
# TEARDOWN: Remove network limits if they were applied
|
||||||
print("\nCleaning up...")
|
if apply_limits:
|
||||||
|
print("\nCleaning up limits for this suite...")
|
||||||
try:
|
try:
|
||||||
print("Removing network limit...")
|
|
||||||
subprocess.run(NET_RESET_CMD, check=True, capture_output=True)
|
subprocess.run(NET_RESET_CMD, check=True, capture_output=True)
|
||||||
|
print("Network limits removed.")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"⚠️ Could not reset network settings: {e}")
|
print(f"⚠️ Could not reset network settings: {e}")
|
||||||
print("Cleanup complete.")
|
|
||||||
|
|
||||||
# Print comparison table
|
return results
|
||||||
print("\n" + "=" * 80)
|
|
||||||
print(f"{'fastSync BENCHMARK RESULTS':^80}")
|
|
||||||
print("=" * 80)
|
# --- Main Execution ---
|
||||||
print(f"{'Configuration':<45} | {'Status':<10} | {'Time':<10} | {'Details/Error':<20}")
|
all_results = []
|
||||||
print("-" * 80)
|
|
||||||
for res in results:
|
# 1. Run Baseline (No Limits)
|
||||||
|
all_results.extend(run_suite("Unlimited", apply_limits=False))
|
||||||
|
|
||||||
|
# # 2. Run Throttled (With Limits)
|
||||||
|
all_results.extend(run_suite("Throttled", apply_limits=True))
|
||||||
|
|
||||||
|
# --- Print Comparison Table ---
|
||||||
|
print("\n" + "=" * 105)
|
||||||
|
print(f"{'fastSync BENCHMARK RESULTS (COMPARISON)':^105}")
|
||||||
|
print("=" * 105)
|
||||||
|
print(
|
||||||
|
f"{'Configuration':<45} | {'Environment':<12} | {'Status':<10} | {'Time':<10} | {'Details/Error':<20}"
|
||||||
|
)
|
||||||
|
print("-" * 105)
|
||||||
|
|
||||||
|
# Sort results by test case name first, then environment to easily compare
|
||||||
|
# This groups the baseline and throttled results for the same test next to each other
|
||||||
|
# sorted_results = sorted(
|
||||||
|
# all_results,
|
||||||
|
# key=lambda x: (
|
||||||
|
# TEST_CASES.index(
|
||||||
|
# next(item for item in TEST_CASES if item["name"] == x["name"])
|
||||||
|
# ),
|
||||||
|
# x["environment"],
|
||||||
|
# ),
|
||||||
|
# )
|
||||||
|
|
||||||
|
for res in all_results:
|
||||||
status_symbol = (
|
status_symbol = (
|
||||||
"✅"
|
"✅"
|
||||||
if res["status"] == "Success"
|
if res["status"] == "Success"
|
||||||
@@ -167,6 +217,6 @@ for res in results:
|
|||||||
)
|
)
|
||||||
status_str = f"{status_symbol} {res['status']}"
|
status_str = f"{status_symbol} {res['status']}"
|
||||||
print(
|
print(
|
||||||
f"{res['name']:<45} | {status_str:<10} | {res['time']:<10} | {res['error']:<20}"
|
f"{res['name']:<45} | {res['environment']:<12} | {status_str:<10} | {res['time']:<10} | {res['error']:<20}"
|
||||||
)
|
)
|
||||||
print("=" * 80)
|
print("=" * 105)
|
||||||
|
|||||||
Reference in New Issue
Block a user