From cd43db0861b852dd0d45395b18c0364f16a53ea2 Mon Sep 17 00:00:00 2001 From: Stuckinaboot Date: Sun, 7 Apr 2019 21:29:45 -0400 Subject: [PATCH] Clean up code --- examples/sharding/driver.py | 12 ++++++------ examples/sharding/output.html | 4 ++-- examples/sharding/receiver.py | 2 +- examples/sharding/sender.py | 4 +--- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/examples/sharding/driver.py b/examples/sharding/driver.py index 55a56b0..e57da18 100644 --- a/examples/sharding/driver.py +++ b/examples/sharding/driver.py @@ -58,11 +58,8 @@ def get_num_receivers_in_topology(topology): async def main(): # Create sender - print("Sender created") sender = await SenderNode.create(ACK_PROTOCOL) - - # Create receivers - print("Receivers created") + print("Sender created") # Define connection topology topology_dict = json.loads(open(sys.argv[1]).read()) @@ -76,14 +73,16 @@ async def main(): topics = topic_map.keys() + # Create receivers receivers = await create_receivers(num_receivers, topic_map) + print("Receivers created") # Create network topology await create_topology(topology, sender, receivers) print("Topology created") # Perform throughput test - # 1) Start receivers + # First, start receivers sender_info = info_from_p2p_addr(sender.libp2p_node.get_addrs()[0]) for receiver in receivers: print("Starting receiving") @@ -92,13 +91,14 @@ async def main(): # Allow time for start receiving to be completed await asyncio.sleep(0.5) - # 2) Start sending messages and perform throughput test + # Start sending messages and perform throughput test # Determine number of receivers in each topic num_receivers_in_each_topic = {} for topic in topic_map: num_receivers_in_each_topic[topic] = len(topic_map[topic]) print("Performing test") await sender.perform_test(num_receivers_in_each_topic, topics, 10) + print("All testing completed") await cleanup() diff --git a/examples/sharding/output.html b/examples/sharding/output.html index 83146e8..97c850b 100644 --- a/examples/sharding/output.html +++ b/examples/sharding/output.html @@ -47,8 +47,8 @@ // parsing and collecting nodes and edges from the python - nodes = new vis.DataSet([{"color": "#70ec84", "id": 0, "label": 0, "shape": "dot"}, {"color": "#70ec84", "id": 1, "label": 1, "shape": "dot"}, {"color": "#70ec84", "id": 2, "label": 2, "shape": "dot"}, {"color": "#70ec84", "id": 3, "label": 3, "shape": "dot"}, {"id": "sender", "label": "sender", "shape": "dot"}]); - edges = new vis.DataSet([{"from": "sender", "to": 0}, {"from": 0, "to": 1}, {"from": 1, "to": 2}, {"from": 2, "to": 3}]); + nodes = new vis.DataSet([{"color": "#70ec84", "id": 0, "label": 0, "shape": "dot"}, {"color": "#70ec84", "id": 1, "label": 1, "shape": "dot"}, {"color": "#ffa07a", "id": 2, "label": 2, "shape": "dot"}, {"color": "#ffa07a", "id": 3, "label": 3, "shape": "dot"}, {"color": "#005582", "id": 4, "label": 4, "shape": "dot"}, {"color": "#005582", "id": 5, "label": 5, "shape": "dot"}, {"id": "sender", "label": "sender", "shape": "dot"}]); + edges = new vis.DataSet([{"from": "sender", "to": 0}, {"from": "sender", "to": 2}, {"from": "sender", "to": 4}, {"from": 0, "to": 1}, {"from": 2, "to": 3}, {"from": 4, "to": 5}]); // adding nodes and edges to the graph data = {nodes: nodes, edges: edges}; diff --git a/examples/sharding/receiver.py b/examples/sharding/receiver.py index 040afec..6200a18 100644 --- a/examples/sharding/receiver.py +++ b/examples/sharding/receiver.py @@ -23,7 +23,7 @@ class ReceiverNode(): @classmethod async def create(cls, ack_protocol, topic): """ - Create a new DummyAccountNode and attach a libp2p node, a floodsub, and a pubsub + Create a new ReceiverNode and attach a libp2p node, a floodsub, and a pubsub instance to this new node We use create as this serves as a factory function and allows us diff --git a/examples/sharding/sender.py b/examples/sharding/sender.py index bedd23b..b25f394 100644 --- a/examples/sharding/sender.py +++ b/examples/sharding/sender.py @@ -14,9 +14,7 @@ TOPIC = "eth" class SenderNode(): """ - Node which has an internal balance mapping, meant to serve as - a dummy crypto blockchain. There is no actual blockchain, just a simple - map indicating how much crypto each user in the mappings holds + SenderNode which pings ReceiverNodes continuously to perform benchmarking """ def __init__(self):