|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +IP="localhost" # 127.0.0.1 |
| 4 | +port_alloc_agent=20000 |
| 5 | +port_alloc_tmc=30000 |
| 6 | +port_alloc_shard=40000 # increment by += 2 |
| 7 | +port_alloc_raft=50000 |
| 8 | +LOGLEVEL="WARN" |
| 9 | +RUNNER_TYPE="evm" |
| 10 | + |
| 11 | +# FIXME: update args later |
| 12 | +function print_help() { |
| 13 | + echo "Usage: ./scripts/generate-parsec-multi.sh > launch-parsec-multi.sh" |
| 14 | + echo "" |
| 15 | + echo "OPTIONS:" |
| 16 | + echo " --ip The IP address to use. Default is localhost." |
| 17 | + echo " --port The port number to use. Default is 8888." |
| 18 | + echo " --loglevel The log level to use. Default is WARN." |
| 19 | + echo " --runner_type The runner type to use in the agent. Defaults to EVM." |
| 20 | + echo " -h, --help Show this help message and exit." |
| 21 | + echo "" |
| 22 | +} |
| 23 | + |
| 24 | +# FIXME: update args later |
| 25 | +for arg in "$@"; do |
| 26 | + if [[ "$arg" == "-h" || "$arg" == "--help" ]]; then |
| 27 | + print_help |
| 28 | + exit 0 |
| 29 | + elif [[ "$arg" == "--runner_type"* ]]; then |
| 30 | + if [[ "$arg" == "--runner_type=lua" ]]; then |
| 31 | + RUNNER_TYPE="lua" |
| 32 | + elif [[ "$arg" != "--runner_type=evm" ]]; then |
| 33 | + echo "unknown runner type, using evm" |
| 34 | + fi |
| 35 | + elif [[ "$arg" == "--ip"* ]]; then |
| 36 | + IP="${arg#--ip=}" |
| 37 | + elif [[ "$arg" == "--port"* ]]; then |
| 38 | + PORT="${arg#--port=}" |
| 39 | + elif [[ "$arg" == "--loglevel"* ]]; then |
| 40 | + LOGLEVEL="${arg#--loglevel=}" |
| 41 | + fi |
| 42 | +done |
| 43 | + |
| 44 | +mkdir -p logs |
| 45 | +# FIXME: multiple ports... |
| 46 | +# echo Running agent on $IP:$port_alloc_agent |
| 47 | +# echo Log level = $LOGLEVEL |
| 48 | +# echo Runner type = $RUNNER_TYPE |
| 49 | + |
| 50 | +# Parsec configurations |
| 51 | +# FIXME: don't hardcode these values in future |
| 52 | +num_agents=10 |
| 53 | + |
| 54 | +repl_factor_tmc=3 |
| 55 | +num_tmcs=$((1 * repl_factor_tmc)) |
| 56 | + |
| 57 | +num_shards_non_repl=10 |
| 58 | +repl_factor_shards=3 |
| 59 | +num_shards_repl="$repl_factor_shards" |
| 60 | +num_shards_total=$(( num_shards_non_repl * num_shards_repl )) |
| 61 | + |
| 62 | +all_shell_cmds=() |
| 63 | + |
| 64 | +# helper functions |
| 65 | +function build_shard_line() { |
| 66 | + # build out line like this: |
| 67 | + # --shard_count=1 --shard0_count=1 --shard00_endpoint=$IP:5556 \ |
| 68 | + # input: shard port id |
| 69 | + local id_shard=$1 |
| 70 | + local id_shard_repl=$2 |
| 71 | + local port_shard=$3 |
| 72 | + local line="" |
| 73 | + line+="--shard_count=$num_shards_non_repl" |
| 74 | + line+="--shard${id_shard}_count=$num_shards_repl" |
| 75 | + line+=" --shard${id_shard}${id_shard_repl}_endpoint=$IP:$port_shard" |
| 76 | + # FIXME: test if captured correctly into shell cmd data structure |
| 77 | + echo "$line" |
| 78 | + # printf "%s\n" "$line" |
| 79 | +} |
| 80 | + |
| 81 | +function build_raft_line() { |
| 82 | + # build out line like this: |
| 83 | + # --shard00_raft_endpoint=$IP:5557 |
| 84 | + # inputs: |
| 85 | + # idx_shard: shard id |
| 86 | + # idx_repl: replica id |
| 87 | + # port_raft: raft port id |
| 88 | + local idx_shard=$1 |
| 89 | + local idx_repl=$2 |
| 90 | + local port_raft=$3 |
| 91 | + local line="" |
| 92 | + line+=" --shard${idx_shard}${idx_repl}_raft_endpoint=$IP:$port_raft" |
| 93 | + |
| 94 | + printf "%s\n" "$line" |
| 95 | +} |
| 96 | + |
| 97 | +function build_agent_line() { |
| 98 | + # build out line like this: |
| 99 | + # --agent_count=4 --agent0_endpoint=$IP:$PORT --agent1_endpoint=$IP:$PORT2 --agent2_endpoint=$IP:$PORT3 --agent3_endpoint=$IP:$PORT4 \ |
| 100 | + # inputs: |
| 101 | + # idx_agent: agent id |
| 102 | + # increment by += 1 for agent port id from base port |
| 103 | + local idx_agent=$1 |
| 104 | + local line="" |
| 105 | + line+=" --agent_count=$num_agents" |
| 106 | + line+=" --agent${idx_agent}_endpoint=$IP:$((port_alloc_agent + idx_agent))" |
| 107 | + |
| 108 | + printf "%s\n" "$line" |
| 109 | +} |
| 110 | + |
| 111 | +function build_tmc_line() { |
| 112 | + # build out line like this: |
| 113 | + # --ticket_machine_count=1 --ticket_machine0_endpoint=$IP:7777 |
| 114 | + # input: tmc port id |
| 115 | + idx_tmc=$1 |
| 116 | + port_tmc=$2 |
| 117 | + local line="" |
| 118 | + line+=" --ticket_machine_count=$num_tmcs" |
| 119 | + line+=" --ticket_machine${idx_tmc}_endpoint=$IP:$port_tmc" |
| 120 | + |
| 121 | + printf "%s\n" "$line" |
| 122 | +} |
| 123 | + |
| 124 | +# main script |
| 125 | +line_log="--loglevel=$LOGLEVEL" |
| 126 | +line_runner="--runner_type=$RUNNER_TYPE" |
| 127 | + |
| 128 | +# FIXME: think about fixing O(n^4) runtime lol |
| 129 | +# ticket machine replication loop |
| 130 | +for (( idx_tmc=0; idx_tmc<repl_factor_tmc; idx_tmc++ )); do |
| 131 | + tmc_port_id=$(( port_alloc_tmc + idx_tmc )) |
| 132 | + |
| 133 | + # agent loop |
| 134 | + for (( idx_agent=0; idx_agent<num_agents; idx_agent++ )); do |
| 135 | + agent_port_id=$(( port_alloc_agent + idx_agent )) |
| 136 | + line_component=" --component_id=$idx_agent" |
| 137 | + |
| 138 | + # shards loop |
| 139 | + for (( idx_shard=0; idx_shard<num_shards_non_repl; idx_shard++ )); do |
| 140 | + |
| 141 | + # shard replicas loop |
| 142 | + for (( idx_repl=0; idx_repl<num_shards_repl; idx_repl++ )); do |
| 143 | + |
| 144 | + shard_port_id=$(( port_alloc_shard + idx_shard * 2 )) |
| 145 | + line_shard=$(build_shard_line $idx_shard $idx_repl $shard_port_id) |
| 146 | + |
| 147 | + raft_port_id=$(( port_alloc_raft + idx_shard * 2 )) |
| 148 | + line_raft=$(build_raft_line $idx_shard $idx_repl $raft_port_id) |
| 149 | + |
| 150 | + line_tmc=$(build_tmc_line $idx_tmc $tmc_port_id) |
| 151 | + |
| 152 | + line_agent=$(build_agent_line $idx_agent) |
| 153 | + |
| 154 | + line_node=" --node_id=${idx_shard}" # FIXME, cluster shard is in |
| 155 | + |
| 156 | + # FIXME: check if ports are available before generating shell commands |
| 157 | + # netstat etc |
| 158 | + shard_cmd="./build/src/parsec/runtime_locking_shard/runtime_locking_shardd" |
| 159 | + shard_cmd+="$line_shard" |
| 160 | + shard_cmd+="$line_raft" |
| 161 | + shard_cmd+="$line_tmc" |
| 162 | + shard_cmd+="$line_agent" |
| 163 | + shard_cmd+="$line_component" |
| 164 | + shard_cmd+="$line_node" |
| 165 | + shard_cmd+="$line_log" |
| 166 | + shard_cmd+="$line_runner" |
| 167 | + shard_cmd+=" > logs/shardd${idx_shard}-${idx_repl}.log 2>&1 &" # dash in case of double digits |
| 168 | + |
| 169 | + all_shell_cmds+=("$shard_cmd") |
| 170 | + |
| 171 | + # ticket_machined |
| 172 | + tmc_cmd="./scripts/wait-for-it.sh -s $IP:$shard_port_id -t 60 --" |
| 173 | + tmc_cmd+=" ./build/src/parsec/ticket_machine/ticket_machined" |
| 174 | + tmc_cmd+="$line_shard" |
| 175 | + tmc_cmd+="$line_tmc" |
| 176 | + tmc_cmd+="$line_agent" |
| 177 | + tmc_cmd+="$line_component" |
| 178 | + tmc_cmd+="$line_log" |
| 179 | + tmc_cmd+=" > logs/ticket_machined${idx_tmc}.log 2>&1 &" |
| 180 | + |
| 181 | + all_shell_cmds+=("$tmc_cmd") |
| 182 | + |
| 183 | + # can hardcode tmc port (line 0) for now as there is just 1 |
| 184 | + agent_cmd="./scripts/wait-for-it.sh -s $IP:$tmc_port_id -t 60 --" |
| 185 | + agent_cmd+=" ./scripts/wait-for-it.sh -s $IP:$shard_port_id -t 60 --" |
| 186 | + agent_cmd+=" ./build/src/parsec/agent/agentd" |
| 187 | + agent_cmd+="$line_shard" |
| 188 | + agent_cmd+="$line_tmc" |
| 189 | + agent_cmd+="$line_agent" |
| 190 | + agent_cmd+="$line_component" |
| 191 | + agent_cmd+="$line_log" |
| 192 | + agent_cmd+="$line_runner" |
| 193 | + agent_cmd+=" > logs/agentd${idx_agent}.log 2>&1 &" |
| 194 | + |
| 195 | + all_shell_cmds+=("$agent_cmd") |
| 196 | + |
| 197 | + done |
| 198 | + done |
| 199 | + done |
| 200 | +done |
| 201 | + |
| 202 | +printf "#!/bin/bash\n\n" |
| 203 | +for cmd in "${all_shell_cmds[@]}"; do |
| 204 | + printf "%s\n" "$cmd" |
| 205 | + printf "sleep 1\n\n" |
| 206 | +done |
0 commit comments