mirror of
https://github.com/logos-blockchain/logos-blockchain-specs.git
synced 2026-01-08 08:03:13 +00:00
refactor plot to show only uidirectional bandwidth if it is per conn
This commit is contained in:
parent
27ad7f2b77
commit
86e9b91084
@ -12,62 +12,62 @@ from mixnet.sim.state import NodeState
|
||||
class MeteredRemoteSimplexConnection(SimplexConnection):
|
||||
framework: Framework
|
||||
latency: float
|
||||
outputs: Queue
|
||||
conn: Queue
|
||||
inputs: Queue
|
||||
output_task: Awaitable
|
||||
output_meters: list[int]
|
||||
input_task: Awaitable
|
||||
input_meters: list[int]
|
||||
output_node_states: list[NodeState]
|
||||
input_node_states: list[NodeState]
|
||||
send_queue: Queue
|
||||
mid_queue: Queue
|
||||
recv_queue: Queue
|
||||
send_task: Awaitable
|
||||
send_meters: list[int]
|
||||
recv_task: Awaitable
|
||||
recv_meters: list[int]
|
||||
send_node_states: list[NodeState]
|
||||
recv_node_states: list[NodeState]
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
config: NetworkConfig,
|
||||
framework: Framework,
|
||||
output_node_states: list[NodeState],
|
||||
input_node_states: list[NodeState],
|
||||
send_node_states: list[NodeState],
|
||||
recv_node_states: list[NodeState],
|
||||
):
|
||||
self.framework = framework
|
||||
self.latency = config.random_latency()
|
||||
self.outputs = framework.queue()
|
||||
self.conn = framework.queue()
|
||||
self.inputs = framework.queue()
|
||||
self.output_meters = []
|
||||
self.output_task = framework.spawn(self.__run_output_task())
|
||||
self.input_meters = []
|
||||
self.input_task = framework.spawn(self.__run_input_task())
|
||||
self.output_node_states = output_node_states
|
||||
self.input_node_states = input_node_states
|
||||
self.send_queue = framework.queue()
|
||||
self.mid_queue = framework.queue()
|
||||
self.recv_queue = framework.queue()
|
||||
self.send_meters = []
|
||||
self.send_task = framework.spawn(self.__run_send_task())
|
||||
self.recv_meters = []
|
||||
self.recv_task = framework.spawn(self.__run_recv_task())
|
||||
self.send_node_states = send_node_states
|
||||
self.recv_node_states = recv_node_states
|
||||
|
||||
async def send(self, data: bytes) -> None:
|
||||
await self.outputs.put(data)
|
||||
await self.send_queue.put(data)
|
||||
ms = math.floor(self.framework.now() * 1000)
|
||||
self.output_node_states[ms] = NodeState.SENDING
|
||||
self.send_node_states[ms] = NodeState.SENDING
|
||||
|
||||
async def recv(self) -> bytes:
|
||||
data = await self.inputs.get()
|
||||
data = await self.recv_queue.get()
|
||||
ms = math.floor(self.framework.now() * 1000)
|
||||
self.output_node_states[ms] = NodeState.RECEIVING
|
||||
self.send_node_states[ms] = NodeState.RECEIVING
|
||||
return data
|
||||
|
||||
async def __run_output_task(self):
|
||||
async def __run_send_task(self):
|
||||
start_time = self.framework.now()
|
||||
while True:
|
||||
data = await self.outputs.get()
|
||||
self.__update_meter(self.output_meters, len(data), start_time)
|
||||
await self.conn.put(data)
|
||||
data = await self.send_queue.get()
|
||||
self.__update_meter(self.send_meters, len(data), start_time)
|
||||
await self.mid_queue.put(data)
|
||||
|
||||
async def __run_input_task(self):
|
||||
async def __run_recv_task(self):
|
||||
start_time = self.framework.now()
|
||||
while True:
|
||||
data = await self.conn.get()
|
||||
data = await self.mid_queue.get()
|
||||
if data is None:
|
||||
break
|
||||
await self.framework.sleep(self.latency)
|
||||
self.__update_meter(self.input_meters, len(data), start_time)
|
||||
await self.inputs.put(data)
|
||||
self.__update_meter(self.recv_meters, len(data), start_time)
|
||||
await self.recv_queue.put(data)
|
||||
|
||||
def __update_meter(self, meters: list[int], size: int, start_time: float):
|
||||
slot = math.floor(self.framework.now() - start_time)
|
||||
@ -75,11 +75,11 @@ class MeteredRemoteSimplexConnection(SimplexConnection):
|
||||
meters.extend([0] * (slot - len(meters) + 1))
|
||||
meters[-1] += size
|
||||
|
||||
def output_bandwidths(self) -> pandas.Series:
|
||||
return self.__bandwidths(self.output_meters)
|
||||
def sending_bandwidths(self) -> pandas.Series:
|
||||
return self.__bandwidths(self.send_meters)
|
||||
|
||||
def input_bandwidths(self) -> pandas.Series:
|
||||
return self.__bandwidths(self.input_meters)
|
||||
def receiving_bandwidths(self) -> pandas.Series:
|
||||
return self.__bandwidths(self.recv_meters)
|
||||
|
||||
def __bandwidths(self, meters: list[int]) -> pandas.Series:
|
||||
return pandas.Series(meters, name="bandwidth")
|
||||
|
||||
@ -32,29 +32,18 @@ class ConnectionStats:
|
||||
self._bandwidths_per_node()
|
||||
|
||||
def _bandwidths_per_conn(self):
|
||||
_, axs = plt.subplots(nrows=2, ncols=1, figsize=(12, 6))
|
||||
|
||||
for _, (inbound_conns, outbound_conns) in self.conns_per_node.items():
|
||||
for conn in inbound_conns:
|
||||
inbound_bandwidths = conn.input_bandwidths().map(lambda x: x / 1024)
|
||||
axs[0].plot(inbound_bandwidths.index, inbound_bandwidths)
|
||||
plt.plot(figsize=(12, 6))
|
||||
|
||||
for _, (_, outbound_conns) in self.conns_per_node.items():
|
||||
for conn in outbound_conns:
|
||||
outbound_bandwidths = conn.output_bandwidths().map(lambda x: x / 1024)
|
||||
axs[1].plot(outbound_bandwidths.index, outbound_bandwidths)
|
||||
|
||||
axs[0].set_title("Inbound Bandwidths per Connection")
|
||||
axs[0].set_xlabel("Time (s)")
|
||||
axs[0].set_ylabel("Bandwidth (KB/s)")
|
||||
axs[0].set_ylim(bottom=0)
|
||||
axs[0].grid(True)
|
||||
|
||||
axs[1].set_title("Outbound Bandwidths per Connection")
|
||||
axs[1].set_xlabel("Time (s)")
|
||||
axs[1].set_ylabel("Bandwidth (KB/s)")
|
||||
axs[1].set_ylim(bottom=0)
|
||||
axs[1].grid(True)
|
||||
sending_bandwidths = conn.sending_bandwidths().map(lambda x: x / 1024)
|
||||
plt.plot(sending_bandwidths.index, sending_bandwidths)
|
||||
|
||||
plt.title("Unidirectional Bandwidths per Connection")
|
||||
plt.xlabel("Time (s)")
|
||||
plt.ylabel("Bandwidth (KB/s)")
|
||||
plt.ylim(bottom=0)
|
||||
plt.grid(True)
|
||||
plt.tight_layout()
|
||||
plt.show()
|
||||
|
||||
@ -66,14 +55,14 @@ class ConnectionStats:
|
||||
):
|
||||
inbound_bandwidths = (
|
||||
pandas.concat(
|
||||
[conn.input_bandwidths() for conn in inbound_conns], axis=1
|
||||
[conn.receiving_bandwidths() for conn in inbound_conns], axis=1
|
||||
)
|
||||
.sum(axis=1)
|
||||
.map(lambda x: x / 1024)
|
||||
)
|
||||
outbound_bandwidths = (
|
||||
pandas.concat(
|
||||
[conn.output_bandwidths() for conn in outbound_conns], axis=1
|
||||
[conn.sending_bandwidths() for conn in outbound_conns], axis=1
|
||||
)
|
||||
.sum(axis=1)
|
||||
.map(lambda x: x / 1024)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user