/
clone.inc.sh
54 lines (43 loc) · 1.46 KB
/
clone.inc.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# default variable values
if [[ -z "$REPLAY_RATE_LIMIT" ]]
then
REPLAY_RATE_LIMIT=0
fi
# general functions for traffic cloning setup
function kill_old_replays() {
if [ -f $FILE_WITH_PIDS ]
then
set +e
cat $FILE_WITH_PIDS | xargs kill >/dev/null 2>/dev/null
set -e
fi
}
function start_replays() {
echo "staring #<$REPLAY_COUNT> replay servers with #<$THREADS> threads and backlog of size #<$BACKLOG>"
rm -f $FILE_WITH_PIDS
for (( i=0; i <= $(($REPLAY_COUNT-1)); i++ ))
do
echo "start replay server $i"
python replay/replay.py $STATSD \
--socket="$UNIX_SOCKET_PATH.$i" \
--threads $THREADS --backlog $BACKLOG \
--multiplier $TRAFFIC_MULTIPLIER \
--rate-limit $REPLAY_RATE_LIMIT \
--upstream "$DEST_HOST_PORT" $EXTRA_REPLAY_PARAMS $REPLAY_EXTRA_PARAMS > /dev/null &
REPLAY_PID=$!
echo $REPLAY_PID >>$FILE_WITH_PIDS
echo "pid = $REPLAY_PID started"
done
ps ax | grep "python replay" | wc -l
}
function start_cap() {
sleep 1 # giving Python processes time to start listening on unix sockets
echo "starting cap"
./csniffer/cap $STATSD -i$IFACE --filter="$PCAP_FILTER" \
--rpslimit=$L_HTTP_LIMIT --replay-socket=$UNIX_SOCKET_PATH \
--pool-size=$REPLAY_COUNT --multiply=$LISTENER_TRAFFIC_MULTIPLIER
}
kill_old_replays
trap 'kill_old_replays' EXIT HUP INT TERM
start_replays
start_cap