Skip to content

Commit

Permalink
Fix APPEND/NO_OP
Browse files Browse the repository at this point in the history
  • Loading branch information
axelniklasson committed Apr 11, 2019
1 parent 6f82c4b commit 7a363a6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 20 deletions.
9 changes: 5 additions & 4 deletions client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
help="requests to be sent for each client", type=int)
parser.add_argument("SCALE_FACTOR",
help="scale factor for deployment", type=int, default=1)
parser.add_argument("OPERATION", help="scale factor for deployment")

async def req_applied(req, nodes):
"""Blocks until the supplied request is the last execed req on >= 1 nodes"""
Expand Down Expand Up @@ -50,11 +51,11 @@ async def req_applied(req, nodes):
return


async def run_client(client_id, reqs_count, nodes):
async def run_client(client_id, operation, reqs_count, nodes):
"""Send reqs_count reqs to all nodes with specified client_id."""
start_val = client_id * 100
for r in range(start_val, start_val + reqs_count):
req = build_payload(client_id, r)
for x in range(start_val, start_val + reqs_count):
req = build_payload(client_id, operation, x)
await broadcast(req)
await req_applied(req, nodes)
return
Expand All @@ -69,7 +70,7 @@ async def main():
tasks = []
start_time = time.time()
for i in range(args.ID * client_count, args.ID * client_count + client_count):
t = run_client(i, args.REQS_PER_CLIENT, nodes)
t = run_client(i, args.OPERATION, args.REQS_PER_CLIENT, nodes)
tasks.append(t)
await asyncio.gather(*tasks)
count = client_count * args.REQS_PER_CLIENT
Expand Down
9 changes: 5 additions & 4 deletions client/comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
nodes = get_nodes()


def build_payload(client_id, *args):
"""Builds a NO_OP request object to be sent to all BFTList nodes."""
def build_payload(client_id, op, *args):
"""Builds a request object to be sent to all BFTList nodes."""
return {
"client_id": client_id,
"timestamp": int(time.time()),
"operation": {
"type": "NO_OP",
"type": op,
"args": args
}
}
Expand Down Expand Up @@ -51,7 +51,8 @@ async def broadcast(req):
"""Broadcast the request to all running BFTList nodes."""
nodes = get_nodes()
tasks = []
print(f"Client {req['client_id']} ==> Broadcasting req NO_OP to all nodes")
print(f"Client {req['client_id']} ==> Broadcasting req " +
f"{req['operation']['type']} {req['operation']['args']} to all nodes")
for _, node in nodes.items():
tasks.append(send_to_node(node, req))
# wait for request to be sent to all nodes
Expand Down
14 changes: 9 additions & 5 deletions client/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@
import asyncio
from comm import build_payload, broadcast

ops = ["NO_OP"]
ops = ["NO_OP", "APPEND"]

async def main():
print("Welcome to BFT Client shell! Available operations are 'NO_OP'")
print("Welcome to BFT Client shell! Available operations are 'NO_OP' and APPEND x")
while True:
s = input("BFTList Client > ")
if s not in ops:
parts = s.split(" ")
op = parts[0]
if op not in ops:
print(f"Illegal operation {op}")
continue
payload = build_payload(0)
if len(parts) == 2:
payload = build_payload(0, op, parts[1])
else:
payload = build_payload(0, op)
await broadcast(payload)

# if __name__ == '__main__':
Expand Down
7 changes: 3 additions & 4 deletions run_clients_distributed.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash
# NOTE that nbr_of_clients must be a multiple of the number of nodes

if [ "$#" -ne 4 ]; then
echo "Run as SLICE=slice_name SSH_KEY=abs_path_to_ssh_key ./run_clients [abs_path_to_hosts_file] [scale_factor] [nbr_of_clients] [reqs_per_client]"
if [ "$#" -ne 5 ]; then
echo "Run as SLICE=slice_name SSH_KEY=abs_path_to_ssh_key ./run_clients [abs_path_to_hosts_file] [scale_factor] [nbr_of_clients] [reqs_per_client] [operation]"
exit 1
fi

Expand All @@ -15,8 +15,7 @@ cat $1 | awk "NR % $2 == 0" | tr ',' ' ' | awk '{print $1","$2}' | while read li
do
ID=$(echo $line | tr ',' ' ' | awk '{print $1}')
HOST=$(echo $line | tr ',' ' ' | awk '{print $2}')
CMD="cd /practicalbft/BFTList-client && source ./env/bin/activate && HOSTS_PATH=/practicalbft/BFTList/conf/hosts.txt python client/client.py $ID $3 $4 $2"
echo $CMD
CMD="cd /practicalbft/BFTList-client && source ./env/bin/activate && HOSTS_PATH=/practicalbft/BFTList/conf/hosts.txt python client/client.py $ID $3 $4 $2 $5"
echo "Launcher ==> Launching client on ${HOST}"
ssh -o StrictHostKeyChecking=no -l ${SLICE:-$DEF_SLICE} -i ${SSH_KEY:-$DEF_SSH_KEY} ${HOST} ${CMD} &> /dev/null &
pids[${ID}]=$!
Expand Down
6 changes: 3 additions & 3 deletions run_clients_local.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/bin/bash
# NOTE that nbr_of_clients should be a multiple of the number of nodes

if [ "$#" -ne 4 ]; then
echo "Run as ./run_clients [abs_path_to_hosts_file] [scale_factor] [nbr_of_clients] [reqs_per_client]"
if [ "$#" -ne 5 ]; then
echo "Run as ./run_clients [abs_path_to_hosts_file] [scale_factor] [nbr_of_clients] [reqs_per_client] [operation]"
exit 1
fi

NODES=$(cat ${1} | wc -l)
echo "Launcher ==> Launching all clients"
for i in $(seq 0 $(($NODES-1))); do
source ./env/bin/activate && HOSTS_PATH=$1 python client/client.py $i $3 $4 $2 &
source ./env/bin/activate && HOSTS_PATH=$1 python client/client.py $i $3 $4 $2 $5 &
done
echo "Launcher ==> Launched all clients, waiting for completion"
wait
Expand Down

0 comments on commit 7a363a6

Please sign in to comment.