nghttpx: Avoid copy of std::mt19937 which is huge
This commit is contained in:
parent
7dc39b1ee9
commit
f6301714db
|
@ -2908,8 +2908,7 @@ int process_options(Config *config,
|
||||||
auto iov = make_byte_ref(config->balloc, SHRPX_OBFUSCATED_NODE_LENGTH + 2);
|
auto iov = make_byte_ref(config->balloc, SHRPX_OBFUSCATED_NODE_LENGTH + 2);
|
||||||
auto p = iov.base;
|
auto p = iov.base;
|
||||||
*p++ = '_';
|
*p++ = '_';
|
||||||
std::random_device rd;
|
auto gen = util::make_mt19937();
|
||||||
auto gen = util::make_mt19937(rd);
|
|
||||||
p = util::random_alpha_digit(p, p + SHRPX_OBFUSCATED_NODE_LENGTH, gen);
|
p = util::random_alpha_digit(p, p + SHRPX_OBFUSCATED_NODE_LENGTH, gen);
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
fwdconf.by_obfuscated = StringRef{iov.base, p};
|
fwdconf.by_obfuscated = StringRef{iov.base, p};
|
||||||
|
|
|
@ -232,11 +232,9 @@ int ConnectionHandler::create_single_worker() {
|
||||||
all_ssl_ctx_.push_back(session_cache_ssl_ctx);
|
all_ssl_ctx_.push_back(session_cache_ssl_ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::random_device rd;
|
|
||||||
|
|
||||||
single_worker_ = make_unique<Worker>(
|
single_worker_ = make_unique<Worker>(
|
||||||
loop_, sv_ssl_ctx, cl_ssl_ctx, session_cache_ssl_ctx, cert_tree_.get(),
|
loop_, sv_ssl_ctx, cl_ssl_ctx, session_cache_ssl_ctx, cert_tree_.get(),
|
||||||
ticket_keys_, this, config->conn.downstream, util::make_mt19937(rd));
|
ticket_keys_, this, config->conn.downstream);
|
||||||
#ifdef HAVE_MRUBY
|
#ifdef HAVE_MRUBY
|
||||||
if (single_worker_->create_mruby_context() != 0) {
|
if (single_worker_->create_mruby_context() != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -278,8 +276,6 @@ int ConnectionHandler::create_worker_thread(size_t num) {
|
||||||
++num;
|
++num;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::random_device rd;
|
|
||||||
|
|
||||||
for (size_t i = 0; i < num; ++i) {
|
for (size_t i = 0; i < num; ++i) {
|
||||||
auto loop = ev_loop_new(config->ev_loop_flags);
|
auto loop = ev_loop_new(config->ev_loop_flags);
|
||||||
|
|
||||||
|
@ -295,7 +291,7 @@ int ConnectionHandler::create_worker_thread(size_t num) {
|
||||||
}
|
}
|
||||||
auto worker = make_unique<Worker>(
|
auto worker = make_unique<Worker>(
|
||||||
loop, sv_ssl_ctx, cl_ssl_ctx, session_cache_ssl_ctx, cert_tree_.get(),
|
loop, sv_ssl_ctx, cl_ssl_ctx, session_cache_ssl_ctx, cert_tree_.get(),
|
||||||
ticket_keys_, this, config->conn.downstream, util::make_mt19937(rd));
|
ticket_keys_, this, config->conn.downstream);
|
||||||
#ifdef HAVE_MRUBY
|
#ifdef HAVE_MRUBY
|
||||||
if (worker->create_mruby_context() != 0) {
|
if (worker->create_mruby_context() != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -114,9 +114,8 @@ Worker::Worker(struct ev_loop *loop, SSL_CTX *sv_ssl_ctx, SSL_CTX *cl_ssl_ctx,
|
||||||
ssl::CertLookupTree *cert_tree,
|
ssl::CertLookupTree *cert_tree,
|
||||||
const std::shared_ptr<TicketKeys> &ticket_keys,
|
const std::shared_ptr<TicketKeys> &ticket_keys,
|
||||||
ConnectionHandler *conn_handler,
|
ConnectionHandler *conn_handler,
|
||||||
std::shared_ptr<DownstreamConfig> downstreamconf,
|
std::shared_ptr<DownstreamConfig> downstreamconf)
|
||||||
std::mt19937 randgen)
|
: randgen_(util::make_mt19937()),
|
||||||
: randgen_(std::move(randgen)),
|
|
||||||
worker_stat_{},
|
worker_stat_{},
|
||||||
dns_tracker_(loop),
|
dns_tracker_(loop),
|
||||||
loop_(loop),
|
loop_(loop),
|
||||||
|
|
|
@ -223,8 +223,7 @@ public:
|
||||||
ssl::CertLookupTree *cert_tree,
|
ssl::CertLookupTree *cert_tree,
|
||||||
const std::shared_ptr<TicketKeys> &ticket_keys,
|
const std::shared_ptr<TicketKeys> &ticket_keys,
|
||||||
ConnectionHandler *conn_handler,
|
ConnectionHandler *conn_handler,
|
||||||
std::shared_ptr<DownstreamConfig> downstreamconf,
|
std::shared_ptr<DownstreamConfig> downstreamconf);
|
||||||
std::mt19937 randgen);
|
|
||||||
~Worker();
|
~Worker();
|
||||||
void run_async();
|
void run_async();
|
||||||
void wait();
|
void wait();
|
||||||
|
|
|
@ -412,8 +412,7 @@ int worker_process_event_loop(WorkerProcessConfig *wpconf) {
|
||||||
|
|
||||||
auto loop = EV_DEFAULT;
|
auto loop = EV_DEFAULT;
|
||||||
|
|
||||||
std::random_device rd;
|
auto gen = util::make_mt19937();
|
||||||
auto gen = util::make_mt19937(rd);
|
|
||||||
|
|
||||||
ConnectionHandler conn_handler(loop, gen);
|
ConnectionHandler conn_handler(loop, gen);
|
||||||
|
|
||||||
|
|
|
@ -1452,7 +1452,10 @@ StringRef extract_host(const StringRef &hostport) {
|
||||||
return StringRef{std::begin(hostport), p};
|
return StringRef{std::begin(hostport), p};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::mt19937 make_mt19937(std::random_device &rd) { return std::mt19937(rd()); }
|
std::mt19937 make_mt19937() {
|
||||||
|
std::random_device rd;
|
||||||
|
return std::mt19937(rd());
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace util
|
} // namespace util
|
||||||
|
|
||||||
|
|
|
@ -744,8 +744,8 @@ int sha256(uint8_t *buf, const StringRef &s);
|
||||||
// NULL-terminated.
|
// NULL-terminated.
|
||||||
StringRef extract_host(const StringRef &hostport);
|
StringRef extract_host(const StringRef &hostport);
|
||||||
|
|
||||||
// Returns new std::mt19937 object, seeded by |rd|.
|
// Returns new std::mt19937 object.
|
||||||
std::mt19937 make_mt19937(std::random_device &rd);
|
std::mt19937 make_mt19937();
|
||||||
|
|
||||||
} // namespace util
|
} // namespace util
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue