Browse Source

H2O: Use 64 pipelined database queries per database connection (#7895)

Anton Kirilov 2 years ago
parent
commit
a5e607df80

+ 4 - 3
frameworks/C/h2o/README.md

@@ -17,9 +17,10 @@ The test implementations are located into the `src/handlers` directory - refer t
 ## Performance tuning
 ## Performance tuning
 
 
 If the test environment changes, it will probably be necessary to tune some of the framework
 If the test environment changes, it will probably be necessary to tune some of the framework
-settings in order to achieve the best performance possible. The most significant parameter is
-the maximum number of database connections per thread, which is controlled by the `DB_CONN`
-variable in the `h2o.sh` script.
+settings in order to achieve the best performance possible. The most significant parameters are the
+maximum number of database connections per thread and the maximum number of pipelined database
+queries per database connection, which are controlled by the `DB_CONN` and the `DB_PIPELINE`
+variables respectively in the `h2o.sh` script.
 
 
 ## Performance issues
 ## Performance issues
 
 

+ 5 - 5
frameworks/C/h2o/h2o.dockerfile

@@ -3,9 +3,9 @@ FROM ubuntu:22.04
 WORKDIR /h2o_app_src
 WORKDIR /h2o_app_src
 COPY ./ ./
 COPY ./ ./
 
 
-ENV DEBIAN_FRONTEND noninteractive
-RUN apt-get update && \
-    apt-get install -yqq autoconf bison cmake curl file flex g++ git libnuma-dev libpq-dev \
+ARG DEBIAN_FRONTEND=noninteractive
+RUN apt-get -yqq update && \
+    apt-get -yqq install autoconf bison cmake curl file flex g++ git libnuma-dev libpq-dev \
                          libssl-dev libtool libyajl-dev libz-dev make ninja-build wget
                          libssl-dev libtool libyajl-dev libz-dev make ninja-build wget
 
 
 ### Install mustache-c
 ### Install mustache-c
@@ -13,7 +13,7 @@ RUN apt-get update && \
 ARG MUSTACHE_C_REVISION=c1948c599edfe48c6099ed70ab1d5911d8c3ddc8
 ARG MUSTACHE_C_REVISION=c1948c599edfe48c6099ed70ab1d5911d8c3ddc8
 
 
 ARG MUSTACHE_C_BUILD_DIR=mustache-c-build
 ARG MUSTACHE_C_BUILD_DIR=mustache-c-build
-ENV MUSTACHE_C_PREFIX /opt/mustache-c
+ENV MUSTACHE_C_PREFIX=/opt/mustache-c
 
 
 RUN mkdir -p "$MUSTACHE_C_BUILD_DIR" && \
 RUN mkdir -p "$MUSTACHE_C_BUILD_DIR" && \
     cd "$MUSTACHE_C_BUILD_DIR" && \
     cd "$MUSTACHE_C_BUILD_DIR" && \
@@ -29,7 +29,7 @@ RUN mkdir -p "$MUSTACHE_C_BUILD_DIR" && \
 ARG H2O_VERSION=v2.2.6
 ARG H2O_VERSION=v2.2.6
 
 
 ARG H2O_BUILD_DIR=h2o-build
 ARG H2O_BUILD_DIR=h2o-build
-ENV H2O_PREFIX /opt/h2o
+ENV H2O_PREFIX=/opt/h2o
 
 
 RUN mkdir -p "${H2O_BUILD_DIR}/build" && \
 RUN mkdir -p "${H2O_BUILD_DIR}/build" && \
     cd "$H2O_BUILD_DIR" && \
     cd "$H2O_BUILD_DIR" && \

+ 5 - 2
frameworks/C/h2o/h2o.sh

@@ -25,9 +25,11 @@ if [[ -z "$MUSTACHE_C_PREFIX" ]]; then
 fi
 fi
 
 
 if [[ "$BENCHMARK_ENV" = "Azure" ]]; then
 if [[ "$BENCHMARK_ENV" = "Azure" ]]; then
-	DB_CONN=2
+	DB_CONN=1
+	DB_PIPELINE=64
 else
 else
 	DB_CONN=1
 	DB_CONN=1
+	DB_PIPELINE=64
 fi
 fi
 
 
 build_h2o_app()
 build_h2o_app()
@@ -49,7 +51,7 @@ run_curl()
 run_h2o_app()
 run_h2o_app()
 {
 {
 	LD_LIBRARY_PATH="${MUSTACHE_C_PREFIX}/lib:$LD_LIBRARY_PATH" \
 	LD_LIBRARY_PATH="${MUSTACHE_C_PREFIX}/lib:$LD_LIBRARY_PATH" \
-	taskset -c "$1" "$2/h2o_app" -a20 -e32 -f "$3/template" -m "$DB_CONN" "$4" "$5" \
+	taskset -c "$1" "$2/h2o_app" -a20 -e "$DB_PIPELINE" -f "$3/template" -m "$DB_CONN" "$4" "$5" \
 	        -d "host=$DBHOST dbname=hello_world user=benchmarkdbuser sslmode=disable \
 	        -d "host=$DBHOST dbname=hello_world user=benchmarkdbuser sslmode=disable \
 	            password=benchmarkdbpass" &
 	            password=benchmarkdbpass" &
 }
 }
@@ -81,5 +83,6 @@ popd
 rm -rf "$H2O_APP_BUILD_DIR"
 rm -rf "$H2O_APP_BUILD_DIR"
 echo "Running h2o_app in the $BENCHMARK_ENV environment."
 echo "Running h2o_app in the $BENCHMARK_ENV environment."
 echo "Maximum database connections per thread: $DB_CONN"
 echo "Maximum database connections per thread: $DB_CONN"
+echo "Maximum pipelined database queries per database connection: $DB_PIPELINE"
 run_h2o_app 0 "${H2O_APP_PREFIX}/bin" "${H2O_APP_PREFIX}/share/h2o_app"
 run_h2o_app 0 "${H2O_APP_PREFIX}/bin" "${H2O_APP_PREFIX}/share/h2o_app"
 wait
 wait

+ 6 - 6
frameworks/C/h2o/src/database.c

@@ -186,12 +186,14 @@ static void error_notification(db_conn_pool_t *pool, bool timeout, const char *e
 
 
 static void on_database_connect_error(db_conn_t *conn, bool timeout, const char *error_string)
 static void on_database_connect_error(db_conn_t *conn, bool timeout, const char *error_string)
 {
 {
-	error_notification(conn->pool, timeout, error_string);
+	db_conn_pool_t * const pool = conn->pool;
+
 	h2o_timeout_unlink(&conn->timeout);
 	h2o_timeout_unlink(&conn->timeout);
 	h2o_socket_read_stop(conn->sock);
 	h2o_socket_read_stop(conn->sock);
 	h2o_socket_close(conn->sock);
 	h2o_socket_close(conn->sock);
 	PQfinish(conn->conn);
 	PQfinish(conn->conn);
 	free(conn);
 	free(conn);
+	error_notification(pool, timeout, error_string);
 }
 }
 
 
 static void on_database_connect_read_ready(h2o_socket_t *sock, const char *err)
 static void on_database_connect_read_ready(h2o_socket_t *sock, const char *err)
@@ -409,12 +411,10 @@ static void on_database_write_ready(h2o_socket_t *sock, const char *err)
 			LIBRARY_ERROR("PQflush", PQerrorMessage(conn->conn));
 			LIBRARY_ERROR("PQflush", PQerrorMessage(conn->conn));
 			on_database_error(conn, DB_ERROR);
 			on_database_error(conn, DB_ERROR);
 		}
 		}
-		else {
-			if (send_status)
-				h2o_socket_notify_write(conn->sock, on_database_write_ready);
-
+		else if (send_status)
+			h2o_socket_notify_write(conn->sock, on_database_write_ready);
+		else
 			process_queries(conn);
 			process_queries(conn);
-		}
 	}
 	}
 }
 }
 
 

+ 1 - 1
frameworks/C/h2o/src/handlers/fortune.c

@@ -41,7 +41,7 @@
 #define FORTUNE_TABLE_NAME "Fortune"
 #define FORTUNE_TABLE_NAME "Fortune"
 #define FORTUNE_QUERY "SELECT * FROM " FORTUNE_TABLE_NAME ";"
 #define FORTUNE_QUERY "SELECT * FROM " FORTUNE_TABLE_NAME ";"
 #define ID_FIELD_NAME "id"
 #define ID_FIELD_NAME "id"
-#define MAX_IOVEC 64
+#define MAX_IOVEC 128
 #define MESSAGE_FIELD_NAME "message"
 #define MESSAGE_FIELD_NAME "message"
 #define NEW_FORTUNE_ID "0"
 #define NEW_FORTUNE_ID "0"
 #define NEW_FORTUNE_MESSAGE "Additional fortune added at request time."
 #define NEW_FORTUNE_MESSAGE "Additional fortune added at request time."

+ 2 - 2
frameworks/C/h2o/src/main.c

@@ -46,7 +46,7 @@
 	"[-b <bind address>] " \
 	"[-b <bind address>] " \
 	"[-c <certificate file>] " \
 	"[-c <certificate file>] " \
 	"[-d <database connection string>] " \
 	"[-d <database connection string>] " \
-	"[-e <max pipelined database queries>] " \
+	"[-e <max pipelined database queries per database connection>] " \
 	"[-f <template file path>] " \
 	"[-f <template file path>] " \
 	"[-j <max reused JSON generators>] " \
 	"[-j <max reused JSON generators>] " \
 	"[-k <private key file>] " \
 	"[-k <private key file>] " \
@@ -264,7 +264,7 @@ static void set_default_options(config_t *config)
 		config->max_accept = 10;
 		config->max_accept = 10;
 
 
 	if (!config->max_db_conn_num)
 	if (!config->max_db_conn_num)
-		config->max_db_conn_num = 10;
+		config->max_db_conn_num = 1;
 
 
 	if (!config->max_pipeline_query_num)
 	if (!config->max_pipeline_query_num)
 		config->max_pipeline_query_num = 16;
 		config->max_pipeline_query_num = 16;