Jelajahi Sumber

H2O: Make a couple of improvements

* Make the choice of the maximum number of database connections
smarter - the program does not have a global database connection
pool that is shared among all the threads; instead, there is
a separate connection pool per thread (since a connection pool
is not immutable state, and the policy has been to limit sharing
to such type of data as much as possible), and the maximum
number of connections applies to it individually. Furthermore,
there is an important difference between the cloud and the
physical hardware environments - while in the former the
application and the database server are the same, in the latter
the application server has more CPU cores. As a result, using
the same value for the maximum number of database connections
per thread in both environments means that in at least one of
them the setting will be suboptimal. That's why now the setup
script detects the current environment and adjusts the connection
number accordingly.
* Clean up the compiler flags - enabling the stack protector
by default in debug builds might interfere with other memory
debugging tools. Also, there is no need for the optimizations
enabled by "-Ofast".
Anton Kirilov 8 tahun lalu
induk
melakukan
947c546f6b
2 mengubah file dengan 15 tambahan dan 4 penghapusan
  1. 3 3
      frameworks/C/h2o/CMakeLists.txt
  2. 12 1
      frameworks/C/h2o/setup.sh

+ 3 - 3
frameworks/C/h2o/CMakeLists.txt

@@ -8,9 +8,9 @@ find_path(MUSTACHE_C_INCLUDE mustache.h)
 find_path(YAJL_INCLUDE yajl/yajl_gen.h)
 set(COMMON_OPTIONS -flto -pthread)
 add_compile_options(-std=gnu11 -pedantic -Wall -Wextra ${COMMON_OPTIONS})
-set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fstack-protector-all -D_FORTIFY_SOURCE=2")
-set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Ofast")
-set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -Ofast")
+set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_FORTIFY_SOURCE=2")
+set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3")
+set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -O3")
 add_definitions(-DH2O_USE_LIBUV=0)
 include_directories(src ${H2O_INCLUDE} ${MUSTACHE_C_INCLUDE} ${YAJL_INCLUDE})
 file(GLOB SOURCES "src/*.c")

+ 12 - 1
frameworks/C/h2o/setup.sh

@@ -7,6 +7,16 @@ BUILD_DIR="${H2O_APP_HOME}_build"
 H2O_APP_PROFILE_PORT="54321"
 H2O_APP_PROFILE_URL="http://127.0.0.1:$H2O_APP_PROFILE_PORT"
 
+# A hacky way to detect whether we are running in the physical hardware or the cloud environment.
+if [[ $(nproc) -gt 16 ]]; then
+	# In the physical hardware environment the application server has more CPU cores than the
+	# database server, so we need to reduce the maximum number of database connections per
+	# thread accordingly.
+	DB_CONN=2
+else
+	DB_CONN=8
+fi
+
 build_h2o_app()
 {
 	cmake -DCMAKE_INSTALL_PREFIX="$H2O_APP_HOME" -DCMAKE_BUILD_TYPE=Release \
@@ -25,7 +35,7 @@ run_curl()
 
 run_h2o_app()
 {
-	"$1/h2o_app" -a1 -f "$2/template/fortunes.mustache" -m5 "$3" "$4" \
+	"$1/h2o_app" -a1 -f "$2/template/fortunes.mustache" -m "$DB_CONN" "$3" "$4" \
 		-d "host=$DBHOST dbname=hello_world user=benchmarkdbuser password=benchmarkdbpass" &
 }
 
@@ -54,4 +64,5 @@ build_h2o_app "-fprofile-use"
 make -j "$(nproc)" install
 popd
 rm -rf "$BUILD_DIR"
+echo "Maximum database connections per thread: $DB_CONN"
 run_h2o_app "${H2O_APP_HOME}/bin" "${H2O_APP_HOME}/share/h2o_app"