benchmark.sh 1.7 KB

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