comparison src/stream/ngx_stream_proxy_module.c @ 6677:c02290241cbe

Stream: upstream response time variables. The $upstream_connect_time, $upstream_first_byte_time and $upstream_session_time variables keep corresponding times.
author Vladimir Homutov <vl@nginx.com>
date Fri, 02 Sep 2016 18:27:12 +0300
parents df3a7c029dec
children 56fc55e32f23
comparison
equal deleted inserted replaced
6676:df3a7c029dec 6677:c02290241cbe
682 682
683 c->log->action = "connecting to upstream"; 683 c->log->action = "connecting to upstream";
684 684
685 u = s->upstream; 685 u = s->upstream;
686 686
687 if (u->state) {
688 u->state->response_time = ngx_current_msec - u->state->response_time;
689 }
690
687 u->state = ngx_array_push(s->upstream_states); 691 u->state = ngx_array_push(s->upstream_states);
688 if (u->state == NULL) { 692 if (u->state == NULL) {
689 ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR); 693 ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR);
690 return; 694 return;
691 } 695 }
692 696
693 ngx_memzero(u->state, sizeof(ngx_stream_upstream_state_t)); 697 ngx_memzero(u->state, sizeof(ngx_stream_upstream_state_t));
698
699 u->state->connect_time = (ngx_msec_t) -1;
700 u->state->first_byte_time = (ngx_msec_t) -1;
701 u->state->response_time = ngx_current_msec;
694 702
695 rc = ngx_event_connect_peer(&u->peer); 703 rc = ngx_event_connect_peer(&u->peer);
696 704
697 ngx_log_debug1(NGX_LOG_DEBUG_STREAM, c->log, 0, "proxy connect: %i", rc); 705 ngx_log_debug1(NGX_LOG_DEBUG_STREAM, c->log, 0, "proxy connect: %i", rc);
698 706
810 &str, u->peer.name); 818 &str, u->peer.name);
811 819
812 c->log->handler = handler; 820 c->log->handler = handler;
813 } 821 }
814 } 822 }
823
824 u->state->connect_time = ngx_current_msec - u->state->response_time;
815 825
816 c->log->action = "proxying connection"; 826 c->log->action = "proxying connection";
817 827
818 if (u->upstream_buf.start == NULL) { 828 if (u->upstream_buf.start == NULL) {
819 p = ngx_pnalloc(c->pool, pscf->buffer_size); 829 p = ngx_pnalloc(c->pool, pscf->buffer_size);
1516 src->read->delayed = 1; 1526 src->read->delayed = 1;
1517 ngx_add_timer(src->read, delay); 1527 ngx_add_timer(src->read, delay);
1518 } 1528 }
1519 } 1529 }
1520 1530
1531 if (from_upstream) {
1532 if (u->state->first_byte_time == (ngx_msec_t) -1) {
1533 u->state->first_byte_time = ngx_current_msec
1534 - u->state->response_time;
1535 }
1536 }
1537
1521 if (c->type == SOCK_DGRAM && ++u->responses == pscf->responses) 1538 if (c->type == SOCK_DGRAM && ++u->responses == pscf->responses)
1522 { 1539 {
1523 src->read->ready = 0; 1540 src->read->ready = 0;
1524 src->read->eof = 1; 1541 src->read->eof = 1;
1525 } 1542 }
1662 } 1679 }
1663 1680
1664 pc = u->peer.connection; 1681 pc = u->peer.connection;
1665 1682
1666 if (u->state) { 1683 if (u->state) {
1684 u->state->response_time = ngx_current_msec - u->state->response_time;
1685
1667 if (pc) { 1686 if (pc) {
1668 u->state->bytes_received = u->received; 1687 u->state->bytes_received = u->received;
1669 u->state->bytes_sent = pc->sent; 1688 u->state->bytes_sent = pc->sent;
1670 } 1689 }
1671 } 1690 }