Переглянути джерело

H2O: Documentation changes and minor code fixes (#3915)

Anton Kirilov 7 роки тому
батько
коміт
c8484dd4f6

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

@@ -6,6 +6,10 @@ This is a framework implementation using the [H2O](https://h2o.examp1e.net) HTTP
 
 [CMake](https://cmake.org), [H2O](https://h2o.examp1e.net), [libpq](https://www.postgresql.org), [mustache-c](https://github.com/x86-64/mustache-c), [OpenSSL](https://www.openssl.org), [YAJL](https://lloyd.github.io/yajl)
 
+## Performance tuning
+
+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 `start-servers.sh` script.
+
 ## Performance issues
 
 ### Database tests
@@ -20,10 +24,6 @@ In the Citrine environment the database connection settings that improve the per
 
 `libh2o` performs at least one system call per pipelined response.
 
-### Cached queries
-
-Most of the operations that the in-memory caching mechanism provided by `libh2o` supports modify the cache (in particular, `h2o_cache_fetch()` updates a list of least recently used entries, and may remove expired ones), so when the application is running multithreaded, cache access must be serialized.
-
 ## Contact
 
 Anton Kirilov <[email protected]>

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

@@ -30,7 +30,7 @@ static h2o_cache_t *get_cache(cache_t *cache, h2o_cache_hashcode_t keyhash)
 	return cache->cache[keyhash & (cache->cache_num - 1)];
 }
 
-int cache_create(size_t thread_num,
+int cache_create(size_t concurrency,
                  size_t capacity,
                  uint64_t duration,
                  void (*destroy_cb)(h2o_iovec_t value),
@@ -41,7 +41,7 @@ int cache_create(size_t thread_num,
 	memset(cache, 0, sizeof(*cache));
 	// Rounding up to a power of 2 simplifies the calculations a little bit, and, as any increase in
 	// the number of caches, potentially reduces thread contention.
-	cache->cache_num = round_up_to_power_of_2(thread_num);
+	cache->cache_num = round_up_to_power_of_2(concurrency);
 	cache->cache_num = MAX(cache->cache_num, 1);
 	capacity = (capacity + cache->cache_num - 1) / cache->cache_num;
 	cache->cache = malloc(cache->cache_num * sizeof(*cache->cache));

+ 1 - 1
frameworks/C/h2o/src/cache.h

@@ -28,7 +28,7 @@ typedef struct {
 	size_t cache_num;
 } cache_t;
 
-int cache_create(size_t thread_num,
+int cache_create(size_t concurrency,
                  size_t capacity,
                  uint64_t duration,
                  void (*destroy_cb)(h2o_iovec_t value),

+ 3 - 1
frameworks/C/h2o/src/database.c

@@ -314,7 +314,9 @@ static void poll_database_connection(h2o_socket_t *db_sock, const char *err)
 
 		switch (status) {
 			case PGRES_POLLING_WRITING:
-				h2o_socket_notify_write(db_conn->sock, on_database_write_ready);
+				if (!h2o_socket_is_writing(db_conn->sock))
+					h2o_socket_notify_write(db_conn->sock, on_database_write_ready);
+
 				return;
 			case PGRES_POLLING_OK:
 				if (PQsetnonblocking(db_conn->conn, 1)) {

+ 2 - 2
frameworks/C/h2o/src/utility.h

@@ -66,14 +66,14 @@ typedef struct {
 typedef struct {
 	h2o_logger_t *file_logger;
 	mustache_template_t *fortunes_template;
+	global_thread_data_t *global_thread_data;
 	h2o_socket_t *signals;
 	SSL_CTX *ssl_ctx;
-	global_thread_data_t *global_thread_data;
 	size_t memory_alignment;
 	int signal_fd;
 	bool shutdown;
-	cache_t world_cache;
 	h2o_globalconf_t h2o_config;
+	cache_t world_cache;
 } global_data_t;
 
 typedef struct {