setup.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/bin/bash
  2. fw_depends postgresql h2o mustache-c yajl
  3. H2O_APP_HOME="${IROOT}/h2o_app"
  4. BUILD_DIR="${H2O_APP_HOME}_build"
  5. H2O_APP_PROFILE_PORT=54321
  6. H2O_APP_PROFILE_URL="http://127.0.0.1:$H2O_APP_PROFILE_PORT"
  7. NUM_WORKERS="$CPU_COUNT"
  8. # A hacky way to detect whether we are running in the physical hardware or the cloud environment.
  9. if [[ "$CPU_COUNT" -gt 16 ]]; then
  10. USE_PROCESSES=false
  11. # In the physical hardware environment the number of threads used by the application is not
  12. # the same as the number of logical CPU cores that the database server has, so we need to
  13. # adjust the maximum number of database connections per thread accordingly.
  14. DB_CONN=1
  15. else
  16. USE_PROCESSES=false
  17. DB_CONN=16
  18. fi
  19. build_h2o_app()
  20. {
  21. cmake -DCMAKE_INSTALL_PREFIX="$H2O_APP_HOME" -DCMAKE_BUILD_TYPE=Release \
  22. -DCMAKE_PREFIX_PATH="${H2O_HOME};${MUSTACHE_C_HOME};${YAJL_HOME}" \
  23. -DCMAKE_C_FLAGS="-march=native $1" "$TROOT"
  24. make -j "$CPU_COUNT"
  25. }
  26. run_curl()
  27. {
  28. for ((i = 0; i < 10; i++)); do
  29. curl "${H2O_APP_PROFILE_URL}/$1" > /dev/null 2>&1
  30. done
  31. }
  32. run_h2o_app()
  33. {
  34. taskset -c "$1" "$2/h2o_app" -a20 -f "$3/template/fortunes.mustache" -m "$DB_CONN" "$4" "$5" \
  35. -d "host=TFB-database dbname=hello_world user=benchmarkdbuser password=benchmarkdbpass" &
  36. }
  37. generate_profile_data()
  38. {
  39. run_h2o_app 0 . "${TROOT}" -p$H2O_APP_PROFILE_PORT -t1
  40. local -r H2O_APP_PROFILE_PID=$!
  41. while ! curl ${H2O_APP_PROFILE_URL} > /dev/null 2>&1; do sleep 1; done
  42. run_curl json
  43. run_curl db
  44. run_curl queries?queries=20
  45. run_curl fortunes
  46. run_curl updates?queries=20
  47. run_curl plaintext
  48. run_curl cached-worlds?queries=20
  49. kill -s SIGTERM $H2O_APP_PROFILE_PID
  50. wait $H2O_APP_PROFILE_PID
  51. }
  52. install -d "$BUILD_DIR"
  53. pushd "$BUILD_DIR"
  54. build_h2o_app "-fprofile-generate"
  55. generate_profile_data
  56. make clean
  57. rm -f CMakeCache.txt
  58. build_h2o_app "-fprofile-use"
  59. make -j "$CPU_COUNT" install
  60. popd
  61. rm -rf "$BUILD_DIR"
  62. echo "Maximum database connections per thread: $DB_CONN"
  63. if "$USE_PROCESSES"; then
  64. echo "Running $NUM_WORKERS h2o_app processes..."
  65. for ((i = 0; i < NUM_WORKERS; i++)); do
  66. run_h2o_app "$i" "${H2O_APP_HOME}/bin" "${H2O_APP_HOME}/share/h2o_app" -t1
  67. done
  68. else
  69. echo "Running h2o_app multithreaded..."
  70. run_h2o_app 0 "${H2O_APP_HOME}/bin" "${H2O_APP_HOME}/share/h2o_app"
  71. fi