benchmark.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/bin/bash
  2. host=127.0.0.1
  3. port=2000
  4. connections=100
  5. duration=10
  6. threads=2
  7. while getopts 'h:p:c:d:t:' opt
  8. do
  9. case $opt in
  10. h) host=$OPTARG;;
  11. p) port=$OPTARG;;
  12. c) connections=$OPTARG;;
  13. d) duration=$OPTARG;;
  14. t) threads=$OPTARG;;
  15. *) exit -1;;
  16. esac
  17. done
  18. SCRIPT_DIR=$(cd `dirname $0`; pwd)
  19. cd ${SCRIPT_DIR}/..
  20. killall_echo_servers() {
  21. #sudo killall libevent_echo libev_echo libuv_echo libhv_echo asio_echo poco_echo muduo_echo
  22. if [ $(ps aux | grep _echo | grep -v grep | wc -l) -gt 0 ]; then
  23. ps aux | grep _echo | grep -v grep | awk '{print $2}' | xargs sudo kill -9
  24. fi
  25. }
  26. export LD_LIBRARY_PATH=lib:$LD_LIBRARY_PATH
  27. killall_echo_servers
  28. sport=$port
  29. if [ -x bin/libevent_echo ]; then
  30. let port++
  31. bin/libevent_echo $port &
  32. echo "libevent running on port $port"
  33. fi
  34. if [ -x bin/libev_echo ]; then
  35. let port++
  36. bin/libev_echo $port &
  37. echo "libev running on port $port"
  38. fi
  39. if [ -x bin/libuv_echo ]; then
  40. let port++
  41. bin/libuv_echo $port &
  42. echo "libuv running on port $port"
  43. fi
  44. if [ -x bin/libhv_echo ]; then
  45. let port++
  46. bin/libhv_echo $port &
  47. echo "libhv running on port $port"
  48. fi
  49. if [ -x bin/asio_echo ]; then
  50. let port++
  51. bin/asio_echo $port &
  52. echo "asio running on port $port"
  53. fi
  54. if [ -x bin/poco_echo ]; then
  55. let port++
  56. bin/poco_echo $port &
  57. echo "poco running on port $port"
  58. fi
  59. if [ -x bin/muduo_echo ]; then
  60. let port++
  61. bin/muduo_echo $port &
  62. echo "muduo running on port $port"
  63. fi
  64. sleep 1
  65. for ((p=$sport+1; p<=$port; ++p)); do
  66. echo -e "\n==============$p====================================="
  67. bin/pingpong_client -H $host -p $p -c $connections -d $duration -t $threads
  68. sleep 1
  69. done
  70. killall_echo_servers