From c88a5291b7835097c7532f89b2bfdd6181155342 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Tue, 13 Jan 2015 23:20:06 +0900 Subject: [PATCH] nghttpx: Add --backend-response-buffer option --- src/shrpx.cc | 11 +++++++++++ src/shrpx_config.cc | 17 +++++++++++++++++ src/shrpx_config.h | 2 ++ src/shrpx_downstream.cc | 3 ++- 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/shrpx.cc b/src/shrpx.cc index a97b8853..5d31c5ce 100644 --- a/src/shrpx.cc +++ b/src/shrpx.cc @@ -747,6 +747,7 @@ void fill_default_config() { mod_config()->listener_disable_timeout = 0.; mod_config()->auto_tls_ticket_key = true; mod_config()->tls_ctx_per_worker = false; + mod_config()->downstream_response_buffer_size = 64 * 1024; } } // namespace @@ -877,6 +878,11 @@ Performance: Set maximum number of open files (RLIMIT_NOFILE) to . If 0 is given, nghttpx does not set the limit. Default: )" << get_config()->rlimit_nofile << R"( + --backend-response-buffer= + Set buffer size used to store backend response. + Default: )" + << util::utos_with_unit(get_config()->downstream_response_buffer_size) + << R"( Timeout: --frontend-http2-read-timeout= @@ -1273,6 +1279,7 @@ int main(int argc, char **argv) { {"tls-ticket-key-file", required_argument, &flag, 68}, {"rlimit-nofile", required_argument, &flag, 69}, {"tls-ctx-per-worker", no_argument, &flag, 70}, + {"backend-response-buffer", required_argument, &flag, 71}, {nullptr, 0, nullptr, 0}}; int option_index = 0; @@ -1594,6 +1601,10 @@ int main(int argc, char **argv) { // --tls-ctx-per-worker cmdcfgs.emplace_back(SHRPX_OPT_TLS_CTX_PER_WORKER, "yes"); break; + case 71: + // --backend-response-buffer + cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_RESPONSE_BUFFER, optarg); + break; default: break; } diff --git a/src/shrpx_config.cc b/src/shrpx_config.cc index 43efab7b..90203a0b 100644 --- a/src/shrpx_config.cc +++ b/src/shrpx_config.cc @@ -141,6 +141,7 @@ const char SHRPX_OPT_LISTENER_DISABLE_TIMEOUT[] = "listener-disable-timeout"; const char SHRPX_OPT_TLS_TICKET_KEY_FILE[] = "tls-ticket-key-file"; const char SHRPX_OPT_RLIMIT_NOFILE[] = "rlimit-nofile"; const char SHRPX_OPT_TLS_CTX_PER_WORKER[] = "tls-ctx-per-worker"; +const char SHRPX_OPT_BACKEND_RESPONSE_BUFFER[] = "backend-response-buffer"; namespace { Config *config = nullptr; @@ -1130,6 +1131,22 @@ int parse_config(const char *opt, const char *optarg) { return 0; } + if (util::strieq(opt, SHRPX_OPT_BACKEND_RESPONSE_BUFFER)) { + size_t n; + if (parse_uint_with_unit(&n, opt, optarg) != 0) { + return -1; + } + + if (n == 0) { + LOG(ERROR) << opt << ": specify an integer strictly more than 0"; + return -1; + } + + mod_config()->downstream_response_buffer_size = n; + + return 0; + } + if (util::strieq(opt, SHRPX_OPT_TLS_CTX_PER_WORKER)) { mod_config()->tls_ctx_per_worker = util::strieq(optarg, "yes"); diff --git a/src/shrpx_config.h b/src/shrpx_config.h index a55d2e17..bf7c1850 100644 --- a/src/shrpx_config.h +++ b/src/shrpx_config.h @@ -129,6 +129,7 @@ extern const char SHRPX_OPT_LISTENER_DISABLE_TIMEOUT[]; extern const char SHRPX_OPT_TLS_TICKET_KEY_FILE[]; extern const char SHRPX_OPT_RLIMIT_NOFILE[]; extern const char SHRPX_OPT_TLS_CTX_PER_WORKER[]; +extern const char SHRPX_OPT_BACKEND_RESPONSE_BUFFER[]; union sockaddr_union { sockaddr sa; @@ -256,6 +257,7 @@ struct Config { size_t padding; size_t worker_frontend_connections; size_t rlimit_nofile; + size_t downstream_response_buffer_size; // Bit mask to disable SSL/TLS protocol versions. This will be // passed to SSL_CTX_set_options(). long int tls_proto_mask; diff --git a/src/shrpx_downstream.cc b/src/shrpx_downstream.cc index 0e0deafb..dbf50209 100644 --- a/src/shrpx_downstream.cc +++ b/src/shrpx_downstream.cc @@ -642,7 +642,8 @@ Memchunks4K *Downstream::get_response_buf() { return &response_buf_; } bool Downstream::response_buf_full() { if (dconn_) { - return response_buf_.rleft() >= 64 * 1024; + return response_buf_.rleft() >= + get_config()->downstream_response_buffer_size; } else { return false; }