Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upstream_response_time 是否包含 tcp 三次握手? #1974

Open
Heysexyboy opened this issue Nov 28, 2024 · 2 comments
Open

upstream_response_time 是否包含 tcp 三次握手? #1974

Heysexyboy opened this issue Nov 28, 2024 · 2 comments
Assignees

Comments

@Heysexyboy
Copy link

查看官方针对 upstream_response_time 的解释很模糊,因此想请教一下 upstream_response_time 是否包含 tcp 三次握手和四次挥手?

https://nginx.org/en/docs/http/ngx_http_upstream_module.html
$upstream_response_time
keeps time spent on receiving the response from the upstream server; the time is kept in seconds with millisecond resolution. Times of several responses are separated by commas and colons like addresses in the $upstream_addr variable.

https://docs.nginx.com/nginx/admin-guide/monitoring/logging/
$upstream_response_time – The time between establishing a connection and receiving the last byte of the response body from the upstream server

@Heysexyboy
Copy link
Author

在代码中看到的 response_time 是在 ngx_close_connection(u->peer.connection); 之后,是否可以证实是包含tcp三次握手和四次挥手的耗时?
//如果响应时间未设置,更新响应时间为当前时间减去开始时间
if (u->state && u->state->response_time == (ngx_msec_t) -1) {
u->state->response_time = ngx_current_msec - u->start_time;
//更新接收和发送的字节数。
if (u->pipe && u->pipe->read_length) {
u->state->bytes_received += u->pipe->read_length
- u->pipe->preread_size;
u->state->response_length = u->pipe->read_length;
}

    if (u->peer.connection) {
        u->state->bytes_sent = u->peer.connection->sent;
    }
}

//调用上游模块的结束请求函数。
u->finalize_request(r, rc);
//释放上游服务器的地址信息
if (u->peer.free && u->peer.sockaddr) {
u->peer.free(&u->peer, u->peer.data, 0);
u->peer.sockaddr = NULL;
}

if (u->peer.connection) {

#if (NGX_HTTP_SSL)

    /* TODO: do not shutdown persistent connection */

    if (u->peer.connection->ssl) {

        /*
         * We send the "close notify" shutdown alert to the upstream only
         * and do not wait its "close notify" shutdown alert.
         * It is acceptable according to the TLS standard.
         */

        u->peer.connection->ssl->no_wait_shutdown = 1;

        (void) ngx_ssl_shutdown(u->peer.connection);
    }

#endif

    ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
                   "close http upstream connection: %d",
                   u->peer.connection->fd);

    if (u->peer.connection->pool) {
        ngx_destroy_pool(u->peer.connection->pool);
    }

    ngx_close_connection(u->peer.connection);
}

@chobits
Copy link
Member

chobits commented Nov 29, 2024

$upstream_response_time 记录的是从建立连接到接收完响应主体的最后一个字节之间的时间。
该时间包括:
TCP 三次握手的时间(连接建立时间)。
发送请求到接收到完整响应的时间(即请求处理时间和数据传输时间)。

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants