Browse Source

[core] perf: initialize con->conf using memcpy()

initialize specific_config (con->conf) from top-level specific_config
using memcpy()
personal/stbuehler/ci-build
Glenn Strauss 2 years ago
parent
commit
78a6440492
  1. 21
      src/base.h
  2. 67
      src/configfile.c
  3. 4
      src/configfile.h

21
src/base.h

@ -84,9 +84,7 @@ typedef struct {
buffer *error_handler;
buffer *error_handler_404;
buffer *server_tag;
buffer *dirlist_encoding;
buffer *errorfile_prefix;
buffer *socket_perms;
unsigned short high_precision_timestamps;
unsigned short max_keep_alive_requests;
@ -109,11 +107,6 @@ typedef struct {
unsigned short log_condition_handling;
unsigned short log_timeouts;
/* server wide */
unsigned short use_ipv6, set_v6only; /* set_v6only is only a temporary option */
unsigned short defer_accept;
unsigned short ssl_enabled; /* only interesting for setting up listening sockets. don't use at runtime */
unsigned short allow_http11;
unsigned short etag_use_inode;
unsigned short etag_use_mtime;
@ -121,7 +114,6 @@ typedef struct {
unsigned short force_lowercase_filenames; /* if the FS is case-insensitive, force all files to lower-case */
unsigned int http_parseopts;
unsigned int max_request_size;
int listen_backlog;
unsigned short kbytes_per_second; /* connection kb/s limit */
@ -144,6 +136,19 @@ typedef struct {
*/
off_t *global_bytes_per_second_cnt_ptr; /* */
/*
* global_bytes_per_second_cnt_ptr must be the final member above this point
* members above this point are patched per connection
*/
/* global or per-socket config; not patched per connection */
unsigned short use_ipv6, set_v6only; /* set_v6only is only a temporary option */
unsigned short defer_accept;
unsigned short ssl_enabled; /* only interesting for setting up listening sockets. don't use at runtime */
int listen_backlog;
buffer *socket_perms;
#if defined(__FreeBSD__) || defined(__NetBSD__) \
|| defined(__OpenBSD__) || defined(__DragonFly__)
buffer *bsd_accept_filter;

67
src/configfile.c

@ -668,58 +668,18 @@ static int config_insert(server *srv) {
}
#define PATCH(x) con->conf.x = s->x
int config_setup_connection(server *srv, connection *con) {
specific_config *s = srv->config_storage[0];
PATCH(http_parseopts);
PATCH(allow_http11);
PATCH(mimetypes);
PATCH(document_root);
PATCH(high_precision_timestamps);
PATCH(max_keep_alive_requests);
PATCH(max_keep_alive_idle);
PATCH(max_read_idle);
PATCH(max_write_idle);
PATCH(max_request_size);
PATCH(use_xattr);
PATCH(error_handler);
PATCH(error_handler_404);
PATCH(error_intercept);
PATCH(errorfile_prefix);
PATCH(follow_symlink);
PATCH(server_tag);
PATCH(kbytes_per_second);
PATCH(global_kbytes_per_second);
PATCH(global_bytes_per_second_cnt);
con->conf.global_bytes_per_second_cnt_ptr = &s->global_bytes_per_second_cnt;
PATCH(log_request_header);
PATCH(log_response_header);
PATCH(log_request_handling);
PATCH(log_condition_handling);
PATCH(log_file_not_found);
PATCH(log_timeouts);
PATCH(range_requests);
PATCH(force_lowercase_filenames);
/*PATCH(listen_backlog);*//*(not necessary; used only at startup)*/
PATCH(stream_request_body);
PATCH(stream_response_body);
PATCH(socket_perms);
PATCH(etag_use_inode);
PATCH(etag_use_mtime);
PATCH(etag_use_size);
con->server_name = s->server_name;
return 0;
void config_setup_connection(server *srv, connection *con) {
/* initialize specific_config (con->conf) from top-level specific_config */
specific_config * const s = srv->config_storage[0];
const size_t len = /* offsetof() */
(uintptr_t)&((specific_config *)0)->global_bytes_per_second_cnt_ptr;
con->conf.global_bytes_per_second_cnt_ptr = &s->global_bytes_per_second_cnt;
con->server_name = s->server_name;
memcpy(&con->conf, s, len);
}
int config_patch_connection(server *srv, connection *con) {
#define PATCH(x) con->conf.x = s->x
void config_patch_connection(server *srv, connection *con) {
size_t i, j;
/* skip the first, the global context */
@ -802,8 +762,10 @@ int config_patch_connection(server *srv, connection *con) {
PATCH(global_kbytes_per_second);
PATCH(global_bytes_per_second_cnt);
con->conf.global_bytes_per_second_cnt_ptr = &s->global_bytes_per_second_cnt;
#if 0 /*(not necessary; used only at startup)*/
} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("server.socket-perms"))) {
PATCH(socket_perms);
#endif
}
}
}
@ -811,15 +773,10 @@ int config_patch_connection(server *srv, connection *con) {
con->etag_flags = (con->conf.etag_use_mtime ? ETAG_USE_MTIME : 0) |
(con->conf.etag_use_inode ? ETAG_USE_INODE : 0) |
(con->conf.etag_use_size ? ETAG_USE_SIZE : 0);
return 0;
}
#undef PATCH
typedef struct {
int foo;
int bar;
const buffer *source;
const char *input;
size_t offset;

4
src/configfile.h

@ -119,8 +119,8 @@ int config_parse_file(server *srv, config_t *context, const char *fn);
__attribute_cold__
int config_parse_cmd(server *srv, config_t *context, const char *cmd);
int config_setup_connection(server *srv, connection *con);
int config_patch_connection(server *srv, connection *con);
void config_setup_connection(server *srv, connection *con);
void config_patch_connection(server *srv, connection *con);
void config_cond_cache_reset(server *srv, connection *con);
void config_cond_cache_reset_item(server *srv, connection *con, comp_key_t item);

Loading…
Cancel
Save