From 8272314445e3be647f3319313f2a4afe9e67d9c2 Mon Sep 17 00:00:00 2001 From: Morgan Rockett Date: Sat, 23 Nov 2024 00:58:01 +0000 Subject: [PATCH] feat: IP, creates parsec shell executable file for flex num of agents, tmcs, shards to run --- scripts/generate-parsec-multi.sh | 206 +++++++++++++++++++++++++++++++ 1 file changed, 206 insertions(+) create mode 100755 scripts/generate-parsec-multi.sh diff --git a/scripts/generate-parsec-multi.sh b/scripts/generate-parsec-multi.sh new file mode 100755 index 00000000..6ba826c8 --- /dev/null +++ b/scripts/generate-parsec-multi.sh @@ -0,0 +1,206 @@ +#!/bin/bash + +IP="localhost" # 127.0.0.1 +port_alloc_agent=20000 +port_alloc_tmc=30000 +port_alloc_shard=40000 # increment by += 2 +port_alloc_raft=50000 +LOGLEVEL="WARN" +RUNNER_TYPE="evm" + +# FIXME: update args later +function print_help() { + echo "Usage: ./scripts/generate-parsec-multi.sh > launch-parsec-multi.sh" + echo "" + echo "OPTIONS:" + echo " --ip The IP address to use. Default is localhost." + echo " --port The port number to use. Default is 8888." + echo " --loglevel The log level to use. Default is WARN." + echo " --runner_type The runner type to use in the agent. Defaults to EVM." + echo " -h, --help Show this help message and exit." + echo "" +} + +# FIXME: update args later +for arg in "$@"; do + if [[ "$arg" == "-h" || "$arg" == "--help" ]]; then + print_help + exit 0 + elif [[ "$arg" == "--runner_type"* ]]; then + if [[ "$arg" == "--runner_type=lua" ]]; then + RUNNER_TYPE="lua" + elif [[ "$arg" != "--runner_type=evm" ]]; then + echo "unknown runner type, using evm" + fi + elif [[ "$arg" == "--ip"* ]]; then + IP="${arg#--ip=}" + elif [[ "$arg" == "--port"* ]]; then + PORT="${arg#--port=}" + elif [[ "$arg" == "--loglevel"* ]]; then + LOGLEVEL="${arg#--loglevel=}" + fi +done + +mkdir -p logs +# FIXME: multiple ports... +# echo Running agent on $IP:$port_alloc_agent +# echo Log level = $LOGLEVEL +# echo Runner type = $RUNNER_TYPE + +# Parsec configurations +# FIXME: don't hardcode these values in future +num_agents=10 + +repl_factor_tmc=3 +num_tmcs=$((1 * repl_factor_tmc)) + +num_shards_non_repl=10 +repl_factor_shards=3 +num_shards_repl="$repl_factor_shards" +num_shards_total=$(( num_shards_non_repl * num_shards_repl )) + +all_shell_cmds=() + +# helper functions +function build_shard_line() { + # build out line like this: + # --shard_count=1 --shard0_count=1 --shard00_endpoint=$IP:5556 \ + # input: shard port id + local id_shard=$1 + local id_shard_repl=$2 + local port_shard=$3 + local line="" + line+="--shard_count=$num_shards_non_repl" + line+="--shard${id_shard}_count=$num_shards_repl" + line+=" --shard${id_shard}${id_shard_repl}_endpoint=$IP:$port_shard" + # FIXME: test if captured correctly into shell cmd data structure + echo "$line" + # printf "%s\n" "$line" +} + +function build_raft_line() { + # build out line like this: + # --shard00_raft_endpoint=$IP:5557 + # inputs: + # idx_shard: shard id + # idx_repl: replica id + # port_raft: raft port id + local idx_shard=$1 + local idx_repl=$2 + local port_raft=$3 + local line="" + line+=" --shard${idx_shard}${idx_repl}_raft_endpoint=$IP:$port_raft" + + printf "%s\n" "$line" +} + +function build_agent_line() { + # build out line like this: + # --agent_count=4 --agent0_endpoint=$IP:$PORT --agent1_endpoint=$IP:$PORT2 --agent2_endpoint=$IP:$PORT3 --agent3_endpoint=$IP:$PORT4 \ + # inputs: + # idx_agent: agent id + # increment by += 1 for agent port id from base port + local idx_agent=$1 + local line="" + line+=" --agent_count=$num_agents" + line+=" --agent${idx_agent}_endpoint=$IP:$((port_alloc_agent + idx_agent))" + + printf "%s\n" "$line" +} + +function build_tmc_line() { + # build out line like this: + # --ticket_machine_count=1 --ticket_machine0_endpoint=$IP:7777 + # input: tmc port id + idx_tmc=$1 + port_tmc=$2 + local line="" + line+=" --ticket_machine_count=$num_tmcs" + line+=" --ticket_machine${idx_tmc}_endpoint=$IP:$port_tmc" + + printf "%s\n" "$line" +} + +# main script +line_log="--loglevel=$LOGLEVEL" +line_runner="--runner_type=$RUNNER_TYPE" + +# FIXME: think about fixing O(n^4) runtime lol +# ticket machine replication loop +for (( idx_tmc=0; idx_tmc