nghttpd: Add -m, --max-concurrent-streams option

This commit is contained in:
Tatsuhiro Tsujikawa 2015-05-06 10:42:43 +09:00
parent 7ecca39025
commit 2d5d9d5d04
3 changed files with 27 additions and 8 deletions

View File

@ -89,9 +89,9 @@ template <typename Array> void append_nv(Stream *stream, const Array &nva) {
Config::Config() Config::Config()
: stream_read_timeout(60.), stream_write_timeout(60.), : stream_read_timeout(60.), stream_write_timeout(60.),
session_option(nullptr), data_ptr(nullptr), padding(0), num_worker(1), session_option(nullptr), data_ptr(nullptr), padding(0), num_worker(1),
header_table_size(-1), port(0), verbose(false), daemon(false), max_concurrent_streams(100), header_table_size(-1), port(0),
verify_client(false), no_tls(false), error_gzip(false), verbose(false), daemon(false), verify_client(false), no_tls(false),
early_response(false), hexdump(false) { error_gzip(false), early_response(false), hexdump(false) {
nghttp2_option_new(&session_option); nghttp2_option_new(&session_option);
nghttp2_option_set_recv_client_preface(session_option, 1); nghttp2_option_set_recv_client_preface(session_option, 1);
} }
@ -660,8 +660,10 @@ int Http2Handler::on_write() { return write_(*this); }
int Http2Handler::connection_made() { int Http2Handler::connection_made() {
int r; int r;
auto config = sessions_->get_config();
r = nghttp2_session_server_new2(&session_, sessions_->get_callbacks(), this, r = nghttp2_session_server_new2(&session_, sessions_->get_callbacks(), this,
sessions_->get_config()->session_option); config->session_option);
if (r != 0) { if (r != 0) {
return r; return r;
} }
@ -669,11 +671,11 @@ int Http2Handler::connection_made() {
size_t niv = 1; size_t niv = 1;
entry[0].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS; entry[0].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS;
entry[0].value = 100; entry[0].value = config->max_concurrent_streams;
if (sessions_->get_config()->header_table_size >= 0) { if (config->header_table_size >= 0) {
entry[niv].settings_id = NGHTTP2_SETTINGS_HEADER_TABLE_SIZE; entry[niv].settings_id = NGHTTP2_SETTINGS_HEADER_TABLE_SIZE;
entry[niv].value = sessions_->get_config()->header_table_size; entry[niv].value = config->header_table_size;
++niv; ++niv;
} }
r = nghttp2_submit_settings(session_, NGHTTP2_FLAG_NONE, entry.data(), niv); r = nghttp2_submit_settings(session_, NGHTTP2_FLAG_NONE, entry.data(), niv);

View File

@ -63,6 +63,7 @@ struct Config {
void *data_ptr; void *data_ptr;
size_t padding; size_t padding;
size_t num_worker; size_t num_worker;
size_t max_concurrent_streams;
ssize_t header_table_size; ssize_t header_table_size;
uint16_t port; uint16_t port;
bool verbose; bool verbose;

View File

@ -88,6 +88,7 @@ void print_usage(std::ostream &out) {
namespace { namespace {
void print_help(std::ostream &out) { void print_help(std::ostream &out) {
Config config;
print_usage(out); print_usage(out);
out << R"( out << R"(
<PORT> Specify listening port number. <PORT> Specify listening port number.
@ -128,6 +129,10 @@ Options:
-b, --padding=<N> -b, --padding=<N>
Add at most <N> bytes to a frame payload as padding. Add at most <N> bytes to a frame payload as padding.
Specify 0 to disable padding. Specify 0 to disable padding.
-m, --max-concurrent-streams=<N>
Set the maximum number of the concurrent streams in one
HTTP/2 session.
Default: )" << config.max_concurrent_streams << R"(
-n, --workers=<N> -n, --workers=<N>
Set the number of worker threads. Set the number of worker threads.
Default: 1 Default: 1
@ -173,6 +178,7 @@ int main(int argc, char **argv) {
{"header-table-size", required_argument, nullptr, 'c'}, {"header-table-size", required_argument, nullptr, 'c'},
{"push", required_argument, nullptr, 'p'}, {"push", required_argument, nullptr, 'p'},
{"padding", required_argument, nullptr, 'b'}, {"padding", required_argument, nullptr, 'b'},
{"max-concurrent-streams", required_argument, nullptr, 'm'},
{"workers", required_argument, nullptr, 'n'}, {"workers", required_argument, nullptr, 'n'},
{"error-gzip", no_argument, nullptr, 'e'}, {"error-gzip", no_argument, nullptr, 'e'},
{"no-tls", no_argument, &flag, 1}, {"no-tls", no_argument, &flag, 1},
@ -184,7 +190,7 @@ int main(int argc, char **argv) {
{"hexdump", no_argument, &flag, 7}, {"hexdump", no_argument, &flag, 7},
{nullptr, 0, nullptr, 0}}; {nullptr, 0, nullptr, 0}};
int option_index = 0; int option_index = 0;
int c = getopt_long(argc, argv, "DVb:c:d:ehn:p:va:", long_options, int c = getopt_long(argc, argv, "DVb:c:d:ehm:n:p:va:", long_options,
&option_index); &option_index);
char *end; char *end;
if (c == -1) { if (c == -1) {
@ -209,6 +215,16 @@ int main(int argc, char **argv) {
case 'e': case 'e':
config.error_gzip = true; config.error_gzip = true;
break; break;
case 'm': {
// max-concurrent-streams option
auto n = util::parse_uint(optarg);
if (n == -1) {
std::cerr << "-m: invalid argument: " << optarg << std::endl;
exit(EXIT_FAILURE);
}
config.max_concurrent_streams = n;
break;
}
case 'n': case 'n':
#ifdef NOTHREADS #ifdef NOTHREADS
std::cerr << "-n: WARNING: Threading disabled at build time, " std::cerr << "-n: WARNING: Threading disabled at build time, "