mirror of
https://github.com/logos-blockchain/logos-blockchain-specs.git
synced 2026-01-08 08:03:13 +00:00
add plot for message sizes
This commit is contained in:
parent
e9a35ca178
commit
c231fd3460
@ -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!")
|
||||
@ -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:
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user