nghttpx: Add --num-accept and --accept-delay options
This commit is contained in:
parent
4e68ca8233
commit
402ebb277f
21
src/shrpx.cc
21
src/shrpx.cc
|
@ -757,6 +757,8 @@ void fill_default_config() {
|
|||
mod_config()->tls_ctx_per_worker = false;
|
||||
mod_config()->downstream_request_buffer_size = 16 * 1024;
|
||||
mod_config()->downstream_response_buffer_size = 16 * 1024;
|
||||
mod_config()->num_accept = 16;
|
||||
mod_config()->accept_delay = 0.5;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
@ -897,6 +899,15 @@ Performance:
|
|||
Default: )"
|
||||
<< util::utos_with_unit(get_config()->downstream_response_buffer_size)
|
||||
<< R"(
|
||||
--num-accept=<N>
|
||||
The number of connections acceptor can accept at once.
|
||||
Default: )" << get_config()->num_accept << R"(
|
||||
--accept-delay=<MSEC>
|
||||
Acceptors get idle in <MSEC> milliseconds after they
|
||||
accepted at most N connections, where N is defined in
|
||||
--num-accept option.
|
||||
Default: )" << static_cast<int>(get_config()->accept_delay * 1000)
|
||||
<< R"(
|
||||
|
||||
Timeout:
|
||||
--frontend-http2-read-timeout=<SEC>
|
||||
|
@ -1301,6 +1312,8 @@ int main(int argc, char **argv) {
|
|||
{"tls-ctx-per-worker", no_argument, &flag, 70},
|
||||
{"backend-response-buffer", required_argument, &flag, 71},
|
||||
{"backend-request-buffer", required_argument, &flag, 72},
|
||||
{"num-accept", required_argument, &flag, 73},
|
||||
{"accept-delay", required_argument, &flag, 74},
|
||||
{nullptr, 0, nullptr, 0}};
|
||||
|
||||
int option_index = 0;
|
||||
|
@ -1630,6 +1643,14 @@ int main(int argc, char **argv) {
|
|||
// --backend-request-buffer
|
||||
cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_REQUEST_BUFFER, optarg);
|
||||
break;
|
||||
case 73:
|
||||
// --num-accept
|
||||
cmdcfgs.emplace_back(SHRPX_OPT_NUM_ACCEPT, optarg);
|
||||
break;
|
||||
case 74:
|
||||
// --accept-delay
|
||||
cmdcfgs.emplace_back(SHRPX_OPT_ACCEPT_DELAY, optarg);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -56,6 +56,7 @@ AcceptHandler::~AcceptHandler() {
|
|||
}
|
||||
|
||||
void AcceptHandler::accept_connection() {
|
||||
size_t n = 0;
|
||||
for (;;) {
|
||||
sockaddr_union sockaddr;
|
||||
socklen_t addrlen = sizeof(sockaddr);
|
||||
|
@ -83,7 +84,7 @@ void AcceptHandler::accept_connection() {
|
|||
continue;
|
||||
}
|
||||
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
#ifndef HAVE_ACCEPT4
|
||||
|
@ -94,7 +95,12 @@ void AcceptHandler::accept_connection() {
|
|||
util::make_socket_nodelay(cfd);
|
||||
|
||||
conn_hnr_->handle_connection(cfd, &sockaddr.sa, addrlen);
|
||||
++n;
|
||||
if (n == get_config()->num_accept) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
conn_hnr_->disable_acceptor_temporary(get_config()->accept_delay);
|
||||
}
|
||||
|
||||
void AcceptHandler::enable() { ev_io_start(conn_hnr_->get_loop(), &wev_); }
|
||||
|
|
|
@ -143,6 +143,8 @@ 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_REQUEST_BUFFER[] = "backend-request-buffer";
|
||||
const char SHRPX_OPT_BACKEND_RESPONSE_BUFFER[] = "backend-response-buffer";
|
||||
const char SHRPX_OPT_NUM_ACCEPT[] = "num-accept";
|
||||
const char SHRPX_OPT_ACCEPT_DELAY[] = "accept-delay";
|
||||
|
||||
namespace {
|
||||
Config *config = nullptr;
|
||||
|
@ -1156,6 +1158,28 @@ int parse_config(const char *opt, const char *optarg) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (util::strieq(opt, SHRPX_OPT_NUM_ACCEPT)) {
|
||||
size_t n;
|
||||
if (parse_uint(&n, opt, optarg) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
mod_config()->num_accept = n;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (util::strieq(opt, SHRPX_OPT_ACCEPT_DELAY)) {
|
||||
size_t n;
|
||||
if (parse_uint(&n, opt, optarg) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
mod_config()->accept_delay = n / 1000.;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (util::strieq(opt, "conf")) {
|
||||
LOG(WARN) << "conf: ignored";
|
||||
|
||||
|
|
|
@ -131,6 +131,8 @@ extern const char SHRPX_OPT_RLIMIT_NOFILE[];
|
|||
extern const char SHRPX_OPT_TLS_CTX_PER_WORKER[];
|
||||
extern const char SHRPX_OPT_BACKEND_REQUEST_BUFFER[];
|
||||
extern const char SHRPX_OPT_BACKEND_RESPONSE_BUFFER[];
|
||||
extern const char SHRPX_OPT_NUM_ACCEPT[];
|
||||
extern const char SHRPX_OPT_ACCEPT_DELAY[];
|
||||
|
||||
union sockaddr_union {
|
||||
sockaddr_storage storage;
|
||||
|
@ -197,6 +199,7 @@ struct Config {
|
|||
ev_tstamp stream_write_timeout;
|
||||
ev_tstamp downstream_idle_read_timeout;
|
||||
ev_tstamp listener_disable_timeout;
|
||||
ev_tstamp accept_delay;
|
||||
std::unique_ptr<char[]> host;
|
||||
std::unique_ptr<char[]> private_key_file;
|
||||
std::unique_ptr<char[]> private_key_passwd;
|
||||
|
@ -260,6 +263,7 @@ struct Config {
|
|||
size_t rlimit_nofile;
|
||||
size_t downstream_request_buffer_size;
|
||||
size_t downstream_response_buffer_size;
|
||||
size_t num_accept;
|
||||
// Bit mask to disable SSL/TLS protocol versions. This will be
|
||||
// passed to SSL_CTX_set_options().
|
||||
long int tls_proto_mask;
|
||||
|
|
Loading…
Reference in New Issue