generate_csv.sh 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #!/bin/bash
  2. #
  3. # This script assumes that 2 machines are used to generate performance results.
  4. # First machine is assumed to be the one where this script runs.
  5. # Second machine is the "REMOTE_IP_SSH" machine; we assume to have passwordless SSH access.
  6. #
  7. # Usage example:
  8. # export REMOTE_IP_SSH=10.0.0.1
  9. # export LOCAL_TEST_ENDPOINT="tcp://192.168.1.1:1234"
  10. # export REMOTE_TEST_ENDPOINT="tcp://192.168.1.2:1234"
  11. # export REMOTE_LIBZMQ_PATH="/home/fmontorsi/libzmq/perf"
  12. # ./generate_csv.sh
  13. #
  14. set -u
  15. # configurable values (via environment variables):
  16. REMOTE_IP_SSH=${REMOTE_IP_SSH:-127.0.0.1}
  17. REMOTE_LIBZMQ_PATH=${REMOTE_LIBZMQ_PATH:-/root/libzmq/perf}
  18. LOCAL_TEST_ENDPOINT=${LOCAL_TEST_ENDPOINT:-tcp://192.168.1.1:1234}
  19. REMOTE_TEST_ENDPOINT=${REMOTE_TEST_ENDPOINT:-tcp://192.168.1.2:1234}
  20. # constant values:
  21. MESSAGE_SIZE_LIST="8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072"
  22. OUTPUT_DIR="results"
  23. OUTPUT_FILE_PREFIX="results.txt"
  24. OUTPUT_FILE_CSV_PREFIX="results.csv"
  25. # utility functions:
  26. function verify_ssh()
  27. {
  28. ssh $REMOTE_IP_SSH "ls /" >/dev/null
  29. if [ $? -ne 0 ]; then
  30. echo "Cannot connect via SSH passwordless to the REMOTE_IP_SSH $REMOTE_IP_SSH. Please fix the problem and retry."
  31. exit 2
  32. fi
  33. ssh $REMOTE_IP_SSH "ls $REMOTE_LIBZMQ_PATH" >/dev/null
  34. if [ $? -ne 0 ]; then
  35. echo "The folder $REMOTE_LIBZMQ_PATH is not valid. Please fix the problem and retry."
  36. exit 2
  37. fi
  38. echo "SSH connection to the remote $REMOTE_IP_SSH is working fine."
  39. }
  40. function run_remote_perf_util()
  41. {
  42. local MESSAGE_SIZE_BYTES="$1"
  43. local REMOTE_PERF_UTIL="$2"
  44. local NUM_MESSAGES="$3"
  45. echo "Launching on $REMOTE_IP_SSH the utility [$REMOTE_PERF_UTIL] for messages ${MESSAGE_SIZE_BYTES}B long"
  46. ssh $REMOTE_IP_SSH "$REMOTE_LIBZMQ_PATH/$REMOTE_PERF_UTIL $TEST_ENDPOINT $MESSAGE_SIZE_BYTES $NUM_MESSAGES" &
  47. if [ $? -ne 0 ]; then
  48. echo "Failed to launch remote perf util."
  49. exit 2
  50. fi
  51. }
  52. function generate_output_file()
  53. {
  54. local LOCAL_PERF_UTIL="$1" # must be the utility generating the TXT output
  55. local REMOTE_PERF_UTIL="$2"
  56. local OUTPUT_FILE_PREFIX="$3"
  57. local NUM_MESSAGES="$4"
  58. local CSV_HEADER_LINE="$5"
  59. # derived values:
  60. local OUTPUT_FILE_TXT="${OUTPUT_DIR}/${OUTPUT_FILE_PREFIX}.txt" # useful just for human-friendly debugging
  61. local OUTPUT_FILE_CSV="${OUTPUT_DIR}/${OUTPUT_FILE_PREFIX}.csv" # actually used to later produce graphs
  62. local MESSAGE_SIZE_ARRAY=($MESSAGE_SIZE_LIST)
  63. echo "Killing still-running ZMQ performance utils, if any"
  64. pkill $LOCAL_PERF_UTIL # in case it's running from a previous test
  65. if [ ! -z "$REMOTE_PERF_UTIL" ]; then
  66. ssh $REMOTE_IP_SSH "pkill $REMOTE_PERF_UTIL" # in case it's running from a previous test
  67. fi
  68. echo "Resetting output file $OUTPUT_FILE_TXT and $OUTPUT_FILE_CSV"
  69. mkdir -p ${OUTPUT_DIR}
  70. > $OUTPUT_FILE_TXT
  71. echo "$CSV_HEADER_LINE" > $OUTPUT_FILE_CSV
  72. for MESSAGE_SIZE in ${MESSAGE_SIZE_ARRAY[@]}; do
  73. echo "Launching locally the utility [$LOCAL_PERF_UTIL] for messages ${MESSAGE_SIZE}B long"
  74. ./$LOCAL_PERF_UTIL $TEST_ENDPOINT $MESSAGE_SIZE $NUM_MESSAGES >${OUTPUT_FILE_TXT}-${MESSAGE_SIZE} &
  75. if [ ! -z "$REMOTE_PERF_UTIL" ]; then
  76. run_remote_perf_util $MESSAGE_SIZE $REMOTE_PERF_UTIL $NUM_MESSAGES
  77. fi
  78. wait
  79. # produce the complete human-readable output file:
  80. cat ${OUTPUT_FILE_TXT}-${MESSAGE_SIZE} >>${OUTPUT_FILE_TXT}
  81. # produce a machine-friendly file for later plotting:
  82. local DATALINE="$(cat ${OUTPUT_FILE_TXT}-${MESSAGE_SIZE} | grep -o '[0-9.]*' | tr '\n' ',')"
  83. echo ${DATALINE::-1} >>$OUTPUT_FILE_CSV
  84. rm -f ${OUTPUT_FILE_TXT}-${MESSAGE_SIZE}
  85. done
  86. echo "All measurements completed and saved into $OUTPUT_FILE_TXT and $OUTPUT_FILE_CSV"
  87. }
  88. # main:
  89. verify_ssh
  90. THROUGHPUT_CSV_HEADER_LINE="# message_size,message_count,PPS[msg/s],throughput[Mb/s]"
  91. # PUSH/PULL TCP throughput CSV file:
  92. TEST_ENDPOINT="$LOCAL_TEST_ENDPOINT"
  93. generate_output_file "local_thr" "remote_thr" \
  94. "pushpull_tcp_thr_results" \
  95. "1000000" \
  96. "$THROUGHPUT_CSV_HEADER_LINE"
  97. # PUSH/PULL INPROC throughput CSV file:
  98. # NOTE: in this case there is no remote utility to run and no ENDPOINT to provide:
  99. TEST_ENDPOINT="" # inproc does not require any endpoint
  100. generate_output_file "inproc_thr" "" \
  101. "pushpull_inproc_thr_results" \
  102. "10000000" \
  103. "$THROUGHPUT_CSV_HEADER_LINE"
  104. # PUB/SUB proxy INPROC throughput CSV file:
  105. # NOTE: in this case there is no remote utility to run and no ENDPOINT to provide:
  106. TEST_ENDPOINT="" # inproc does not require any endpoint
  107. generate_output_file "proxy_thr" "" \
  108. "pubsubproxy_inproc_thr_results" \
  109. "10000000" \
  110. "$THROUGHPUT_CSV_HEADER_LINE"
  111. # REQ/REP TCP latency CSV file:
  112. # NOTE: in this case it's the remote_lat utility that prints out the data, so we swap the local/remote arguments to the bash func:
  113. TEST_ENDPOINT="$REMOTE_TEST_ENDPOINT"
  114. generate_output_file "remote_lat" "local_lat" \
  115. "reqrep_tcp_lat_results" \
  116. "10000" \
  117. "# message_size,message_count,latency[us]"