nghttpx: Make record size timeout more durable to high load situation

This commit is contained in:
Tatsuhiro Tsujikawa 2015-07-29 20:57:11 +09:00
parent d0a37d59a5
commit 6446660113
4 changed files with 16 additions and 5 deletions

View File

@ -247,6 +247,7 @@ int ClientHandler::write_tls() {
return -1; return -1;
} }
if (wb_.rleft() == 0) { if (wb_.rleft() == 0) {
conn_.start_tls_write_idle();
break; break;
} }
} }

View File

@ -61,7 +61,7 @@ Connection::Connection(struct ev_loop *loop, int fd, SSL *ssl,
rt.data = this; rt.data = this;
// set 0. to double field explicitly just in case // set 0. to double field explicitly just in case
tls.last_write_time = 0.; tls.last_write_idle = 0.;
if (ssl) { if (ssl) {
set_ssl(ssl); set_ssl(ssl);
@ -402,7 +402,7 @@ const size_t SHRPX_WARMUP_THRESHOLD = 1 << 20;
size_t Connection::get_tls_write_limit() { size_t Connection::get_tls_write_limit() {
auto t = ev_now(loop); auto t = ev_now(loop);
if (t - tls.last_write_time > 1.) { if (tls.last_write_idle >= 0. && t - tls.last_write_idle > 1.) {
// Time out, use small record size // Time out, use small record size
tls.warmup_writelen = 0; tls.warmup_writelen = 0;
return SHRPX_SMALL_WRITE_LIMIT; return SHRPX_SMALL_WRITE_LIMIT;
@ -421,6 +421,12 @@ void Connection::update_tls_warmup_writelen(size_t n) {
} }
} }
void Connection::start_tls_write_idle() {
if (tls.last_write_idle < 0.) {
tls.last_write_idle = ev_now(loop);
}
}
ssize_t Connection::write_tls(const void *data, size_t len) { ssize_t Connection::write_tls(const void *data, size_t len) {
// SSL_write requires the same arguments (buf pointer and its // SSL_write requires the same arguments (buf pointer and its
// length) on SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE. // length) on SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE.
@ -439,14 +445,14 @@ ssize_t Connection::write_tls(const void *data, size_t len) {
tls.last_writelen = 0; tls.last_writelen = 0;
} }
tls.last_write_idle = -1.;
auto rv = SSL_write(tls.ssl, data, len); auto rv = SSL_write(tls.ssl, data, len);
if (rv == 0) { if (rv == 0) {
return SHRPX_ERR_NETWORK; return SHRPX_ERR_NETWORK;
} }
tls.last_write_time = ev_now(loop);
if (rv < 0) { if (rv < 0) {
auto err = SSL_get_error(tls.ssl, rv); auto err = SSL_get_error(tls.ssl, rv);
switch (err) { switch (err) {

View File

@ -52,7 +52,7 @@ struct TLSConnection {
SSL *ssl; SSL *ssl;
SSL_SESSION *cached_session; SSL_SESSION *cached_session;
MemcachedRequest *cached_session_lookup_req; MemcachedRequest *cached_session_lookup_req;
ev_tstamp last_write_time; ev_tstamp last_write_idle;
size_t warmup_writelen; size_t warmup_writelen;
// length passed to SSL_write and SSL_read last time. This is // length passed to SSL_write and SSL_read last time. This is
// required since these functions require the exact same parameters // required since these functions require the exact same parameters
@ -100,6 +100,9 @@ struct Connection {
size_t get_tls_write_limit(); size_t get_tls_write_limit();
// Updates the number of bytes written in warm up period. // Updates the number of bytes written in warm up period.
void update_tls_warmup_writelen(size_t n); void update_tls_warmup_writelen(size_t n);
// Tells there is no immediate write now. This triggers timer to
// determine fallback to short record size mode.
void start_tls_write_idle();
ssize_t write_clear(const void *data, size_t len); ssize_t write_clear(const void *data, size_t len);
ssize_t writev_clear(struct iovec *iov, int iovcnt); ssize_t writev_clear(struct iovec *iov, int iovcnt);

View File

@ -1729,6 +1729,7 @@ int Http2Session::write_tls() {
return -1; return -1;
} }
if (wb_.rleft() == 0) { if (wb_.rleft() == 0) {
conn_.start_tls_write_idle();
break; break;
} }
} }