Skip to content

Commit

Permalink
nghttpx: Make record size timeout more durable to high load situation
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsuhiro-t committed Jul 29, 2015
1 parent d0a37d5 commit 6446660
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/shrpx_client_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ int ClientHandler::write_tls() {
return -1;
}
if (wb_.rleft() == 0) {
conn_.start_tls_write_idle();
break;
}
}
Expand Down
14 changes: 10 additions & 4 deletions src/shrpx_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Connection::Connection(struct ev_loop *loop, int fd, SSL *ssl,
rt.data = this;

// set 0. to double field explicitly just in case
tls.last_write_time = 0.;
tls.last_write_idle = 0.;

if (ssl) {
set_ssl(ssl);
Expand Down Expand Up @@ -402,7 +402,7 @@ const size_t SHRPX_WARMUP_THRESHOLD = 1 << 20;
size_t Connection::get_tls_write_limit() {
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
tls.warmup_writelen = 0;
return SHRPX_SMALL_WRITE_LIMIT;
Expand All @@ -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) {
// SSL_write requires the same arguments (buf pointer and its
// length) on SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE.
Expand All @@ -439,14 +445,14 @@ ssize_t Connection::write_tls(const void *data, size_t len) {
tls.last_writelen = 0;
}

tls.last_write_idle = -1.;

auto rv = SSL_write(tls.ssl, data, len);

if (rv == 0) {
return SHRPX_ERR_NETWORK;
}

tls.last_write_time = ev_now(loop);

if (rv < 0) {
auto err = SSL_get_error(tls.ssl, rv);
switch (err) {
Expand Down
5 changes: 4 additions & 1 deletion src/shrpx_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct TLSConnection {
SSL *ssl;
SSL_SESSION *cached_session;
MemcachedRequest *cached_session_lookup_req;
ev_tstamp last_write_time;
ev_tstamp last_write_idle;
size_t warmup_writelen;
// length passed to SSL_write and SSL_read last time. This is
// required since these functions require the exact same parameters
Expand Down Expand Up @@ -100,6 +100,9 @@ struct Connection {
size_t get_tls_write_limit();
// Updates the number of bytes written in warm up period.
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 writev_clear(struct iovec *iov, int iovcnt);
Expand Down
1 change: 1 addition & 0 deletions src/shrpx_http2_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1729,6 +1729,7 @@ int Http2Session::write_tls() {
return -1;
}
if (wb_.rleft() == 0) {
conn_.start_tls_write_idle();
break;
}
}
Expand Down

0 comments on commit 6446660

Please sign in to comment.