From ddf654fdf2e023528a3a383625446c33abeb5138 Mon Sep 17 00:00:00 2001 From: Alban Crequy Date: Thu, 16 Mar 2017 12:24:14 +0100 Subject: [PATCH] extras/dialer: updates and fixes * remove randomness as far as possible * make listener to close connections * report time in a csv-friendly format * remove tools from README * rename time-scope-probe -> time-scope-probe-proc * add time-scope-probe-cgroup --- extras/dialer/README.md | 6 +-- extras/dialer/dialer | 6 +-- extras/dialer/src/dialer.go | 11 ++++- extras/dialer/time-scope-probe-cgroup | 41 +++++++++++++++++++ ...time-scope-probe => time-scope-probe-proc} | 7 +++- 5 files changed, 63 insertions(+), 8 deletions(-) create mode 100755 extras/dialer/time-scope-probe-cgroup rename extras/dialer/{time-scope-probe => time-scope-probe-proc} (69%) diff --git a/extras/dialer/README.md b/extras/dialer/README.md index b9a2d932c..6652ddcbf 100644 --- a/extras/dialer/README.md +++ b/extras/dialer/README.md @@ -22,19 +22,19 @@ can be used to compare performance under different scenarios/branches. ``` # Start a listener -./tools/dialer/listener +./extras/dialer/listener Listening on :8082 IP addr + port: 172.17.0.2:8082 # Start the dialer script with a maximum of 10 dialer containers # (default 50) -./tools/dialer/dialer 172.17.0.2:8082 10 +./extras/dialer/dialer 172.17.0.2:8082 10 # Start time-scope-probe to measure the scheduled time of scope-probe # every 3 seconds (default 10 seconds) for 3 times (default 60 times) -sudo ./tools/dialer/time-scope-probe 3 3 +sudo ./extras/dialer/time-scope-probe 3 3 ... ``` diff --git a/extras/dialer/dialer b/extras/dialer/dialer index c9f42c4bc..67dacf46a 100755 --- a/extras/dialer/dialer +++ b/extras/dialer/dialer @@ -17,15 +17,15 @@ dialer=() trap 'echo -n "stopping ... "; for c in "${dialer[@]}"; do docker rm -f "$c" >/dev/null; done; echo "done"' EXIT while true; do - rand=$(((RANDOM % max_dialer) + 1)) - dialer+=("$(docker run -d dialer /go/bin/dialer connect "$addr" "$rand")") + dialer+=("$(docker run -d dialer /go/bin/dialer connect "$addr" "10")") if [ ${#dialer[@]} -gt "$max_dialer" ]; then + rand=$(((RANDOM % max_dialer) + 1)) container=${dialer[$rand]} docker rm -f "$container" >/dev/null & unset dialer[$rand] dialer=("${dialer[@]}") fi - sleep $((rand % 3)) + sleep 2 done diff --git a/extras/dialer/src/dialer.go b/extras/dialer/src/dialer.go index 3eef4a66f..779413b57 100644 --- a/extras/dialer/src/dialer.go +++ b/extras/dialer/src/dialer.go @@ -31,13 +31,22 @@ func listen(url string) { defer l.Close() fmt.Println("Listening on " + url) for { - _, err := l.Accept() + conn, err := l.Accept() if err != nil { fmt.Println("Error accepting: ", err.Error()) os.Exit(1) } + go handleRequest(conn) } +} +func handleRequest(conn net.Conn) { + buf := make([]byte, 1024) + _, err := conn.Read(buf) + if err != nil { + fmt.Println("Error reading:", err.Error()) + } + conn.Close() } func main() { diff --git a/extras/dialer/time-scope-probe-cgroup b/extras/dialer/time-scope-probe-cgroup new file mode 100755 index 000000000..a5202f227 --- /dev/null +++ b/extras/dialer/time-scope-probe-cgroup @@ -0,0 +1,41 @@ +#!/bin/bash +set -eu +if [ $EUID -ne 0 ]; then + echo "You must be root!" >&2 + exit 1 +fi + +readonly interval_num=${1:-60} +readonly interval_sleep=${2:-10} + +readonly container_id="${3:-$(sudo docker inspect weavescope | jq -r .[].Id)}" +readonly cpuacct_stat="/sys/fs/cgroup/cpu,cpuacct/docker/${container_id}/cpuacct.stat" + +TIME_U1=0 +TIME_K1=0 +TIME_T1=0 +TIME_U2=0 +TIME_K2=0 +TIME_T2=0 + +if [ "$(pidof scope-probe)" == "" ]; then + echo "No scope-probe process running - aborting" >&2 + exit 1 +fi + +TIME_U2=$(awk '/user/ {print $2}' "${cpuacct_stat}") +TIME_K2=$(awk '/system/ {print $2}' "${cpuacct_stat}") +TIME_T2=$((TIME_U2 + TIME_K2)) + +echo "utime;stime;total_time" +for ((i = 0; i < "$interval_num"; i++)); do + sleep "$interval_sleep" + TIME_U1=$TIME_U2 + TIME_K1=$TIME_K2 + TIME_T1=$TIME_T2 + + TIME_U2=$(awk '/user/ {print $2}' "${cpuacct_stat}") + TIME_K2=$(awk '/system/ {print $2}' "${cpuacct_stat}") + TIME_T2=$((TIME_U2 + TIME_K2)) + echo "$((TIME_U2 - TIME_U1));$((TIME_K2 - TIME_K1));$((TIME_T2 - TIME_T1))" +done diff --git a/extras/dialer/time-scope-probe b/extras/dialer/time-scope-probe-proc similarity index 69% rename from extras/dialer/time-scope-probe rename to extras/dialer/time-scope-probe-proc index 6963aea45..dac26dd36 100755 --- a/extras/dialer/time-scope-probe +++ b/extras/dialer/time-scope-probe-proc @@ -20,6 +20,11 @@ if [ "$(pidof scope-probe)" == "" ]; then exit 1 fi +TIME_U2=$(gawk '{print $14"*10"}' <"/proc/$(pidof scope-probe)/stat" | bc) +TIME_K2=$(gawk '{print $15"*10"}' <"/proc/$(pidof scope-probe)/stat" | bc) +TIME_T2=$((TIME_U2 + TIME_K2)) + +echo "utime;stime;total_time" for ((i = 0; i < "$interval_num"; i++)); do sleep "$interval_sleep" TIME_U1=$TIME_U2 @@ -29,5 +34,5 @@ for ((i = 0; i < "$interval_num"; i++)); do TIME_U2=$(gawk '{print $14"*10"}' <"/proc/$(pidof scope-probe)/stat" | bc) TIME_K2=$(gawk '{print $15"*10"}' <"/proc/$(pidof scope-probe)/stat" | bc) TIME_T2=$((TIME_U2 + TIME_K2)) - echo "utime $((TIME_U2 - TIME_U1)) + stime $((TIME_K2 - TIME_K1)) = $((TIME_T2 - TIME_T1))" + echo "$((TIME_U2 - TIME_U1));$((TIME_K2 - TIME_K1));$((TIME_T2 - TIME_T1))" done