benchmark.sh 1.8 KB

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