add plot for message sizes

This commit is contained in:
Youngjoon Lee 2024-05-14 14:03:48 +09:00
parent e9a35ca178
commit c231fd3460
No known key found for this signature in database
GPG Key ID: 09B750B5BD6F08A2
3 changed files with 19 additions and 0 deletions

View File

@ -1,5 +1,9 @@
import argparse
import matplotlib.pyplot as plt
import pandas as pd
import seaborn
from simulation import Simulation
if __name__ == "__main__":
@ -11,4 +15,13 @@ if __name__ == "__main__":
sim = Simulation(args.num_nodes, args.num_mix_layers)
sim.run(until=args.running_time)
df = pd.DataFrame(sim.p2p.message_sizes, columns=["message_size"])
print(df.describe())
plt.figure(figsize=(10, 6))
seaborn.boxplot(y=df["message_size"])
plt.title("Message size distribution")
plt.ylabel("Message Size (bytes)")
plt.show()
print("Simulation complete!")

View File

@ -9,6 +9,7 @@ class P2p:
def __init__(self, env: simpy.Environment):
self.env = env
self.nodes = []
self.message_sizes = []
def add_node(self, nodes):
self.nodes.extend(nodes)
@ -16,6 +17,8 @@ class P2p:
# TODO: This should accept only bytes, but SphinxPacket is also accepted until we implement the Sphinx serde
def broadcast(self, msg: SphinxPacket | bytes):
self.log("Broadcasting a msg: %d bytes" % len(msg))
self.message_sizes.append(len(msg))
yield self.env.timeout(1)
# TODO: gossipsub or something similar
for node in self.nodes:

View File

@ -8,3 +8,6 @@ scipy==1.11.4
black==23.12.1
sympy==1.12
simpy==4.1.1
pandas==2.2.2
matplotlib==3.8.4
seaborn==0.13.2