aboutsummaryrefslogtreecommitdiff
path: root/src/stream/ngx_stream_proxy_module.c
diff options
context:
space:
mode:
authorVladimir Homutov <vl@nginx.com>2016-09-02 18:27:12 +0300
committerVladimir Homutov <vl@nginx.com>2016-09-02 18:27:12 +0300
commit443b52db591d876a0e10b9ac3406174eb7fdbce1 (patch)
tree22a648a79b4912c01d64702a5e084412af525c15 /src/stream/ngx_stream_proxy_module.c
parent64223df67078cec444cdf71584015036c68dcc32 (diff)
downloadnginx-443b52db591d876a0e10b9ac3406174eb7fdbce1.tar.gz
nginx-443b52db591d876a0e10b9ac3406174eb7fdbce1.zip
Stream: upstream response time variables.
The $upstream_connect_time, $upstream_first_byte_time and $upstream_session_time variables keep corresponding times.
Diffstat (limited to 'src/stream/ngx_stream_proxy_module.c')
-rw-r--r--src/stream/ngx_stream_proxy_module.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/stream/ngx_stream_proxy_module.c b/src/stream/ngx_stream_proxy_module.c
index edffaf8e5..ed802e7e1 100644
--- a/src/stream/ngx_stream_proxy_module.c
+++ b/src/stream/ngx_stream_proxy_module.c
@@ -684,6 +684,10 @@ ngx_stream_proxy_connect(ngx_stream_session_t *s)
u = s->upstream;
+ if (u->state) {
+ u->state->response_time = ngx_current_msec - u->state->response_time;
+ }
+
u->state = ngx_array_push(s->upstream_states);
if (u->state == NULL) {
ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR);
@@ -692,6 +696,10 @@ ngx_stream_proxy_connect(ngx_stream_session_t *s)
ngx_memzero(u->state, sizeof(ngx_stream_upstream_state_t));
+ u->state->connect_time = (ngx_msec_t) -1;
+ u->state->first_byte_time = (ngx_msec_t) -1;
+ u->state->response_time = ngx_current_msec;
+
rc = ngx_event_connect_peer(&u->peer);
ngx_log_debug1(NGX_LOG_DEBUG_STREAM, c->log, 0, "proxy connect: %i", rc);
@@ -813,6 +821,8 @@ ngx_stream_proxy_init_upstream(ngx_stream_session_t *s)
}
}
+ u->state->connect_time = ngx_current_msec - u->state->response_time;
+
c->log->action = "proxying connection";
if (u->upstream_buf.start == NULL) {
@@ -1518,6 +1528,13 @@ ngx_stream_proxy_process(ngx_stream_session_t *s, ngx_uint_t from_upstream,
}
}
+ if (from_upstream) {
+ if (u->state->first_byte_time == (ngx_msec_t) -1) {
+ u->state->first_byte_time = ngx_current_msec
+ - u->state->response_time;
+ }
+ }
+
if (c->type == SOCK_DGRAM && ++u->responses == pscf->responses)
{
src->read->ready = 0;
@@ -1664,6 +1681,8 @@ ngx_stream_proxy_finalize(ngx_stream_session_t *s, ngx_uint_t rc)
pc = u->peer.connection;
if (u->state) {
+ u->state->response_time = ngx_current_msec - u->state->response_time;
+
if (pc) {
u->state->bytes_received = u->received;
u->state->bytes_sent = pc->sent;