diff --git a/doc/admin-guide/monitoring/logging/log-formats.en.rst b/doc/admin-guide/monitoring/logging/log-formats.en.rst index bd294dc0989..9d02967f81b 100644 --- a/doc/admin-guide/monitoring/logging/log-formats.en.rst +++ b/doc/admin-guide/monitoring/logging/log-formats.en.rst @@ -785,6 +785,12 @@ The following list describes |TS| custom logging fields. from a single server session. A value greater than 0 indicates connection reuse. +.. _sscc: + +``sscc`` + The number of open connections to specified origin at the time of + connection establishment. + .. _ttms: ``ttms`` diff --git a/proxy/http/HttpSM.cc b/proxy/http/HttpSM.cc index b8b2ef04cfc..51a6dac2c67 100644 --- a/proxy/http/HttpSM.cc +++ b/proxy/http/HttpSM.cc @@ -272,7 +272,7 @@ HttpSM::HttpSM() server_response_hdr_bytes(0), server_response_body_bytes(0), client_response_hdr_bytes(0), client_response_body_bytes(0), cache_response_hdr_bytes(0), cache_response_body_bytes(0), pushed_response_hdr_bytes(0), pushed_response_body_bytes(0), client_tcp_reused(false), client_ssl_reused(false), client_connection_is_ssl(false), client_sec_protocol("-"), - client_cipher_suite("-"), server_transact_count(0), server_connection_is_ssl(false), plugin_tag(0), plugin_id(0), + client_cipher_suite("-"), server_transact_count(0), server_connection_is_ssl(false), server_connection_count(0), plugin_tag(0), plugin_id(0), hooks_set(false), cur_hook_id(TS_HTTP_LAST_HOOK), cur_hook(NULL), cur_hooks(0), callout_state(HTTP_API_NO_CALLOUT), terminate_sm(false), kill_this_async_done(false), parse_range_done(false) { @@ -1678,9 +1678,9 @@ HttpSM::state_http_server_open(int event, void *data) // of connections per host. Set enable_origin_connection_limiting // to true in the server session so it will increment and decrement // the connection count. - if (t_state.txn_conf->origin_max_connections > 0 || t_state.http_config_param->origin_min_keep_alive_connections > 0) { + if (t_state.txn_conf->origin_max_connections > 0 || t_state.http_config_param->origin_min_keep_alive_connections > 0 || t_state.reverse_proxy) { DebugSM("http_ss", "[%" PRId64 "] max number of connections: %" PRIu64, sm_id, t_state.txn_conf->origin_max_connections); - session->enable_origin_connection_limiting = true; + session->enable_origin_connection_tracking = true; } /*UnixNetVConnection * vc = (UnixNetVConnection*)(ua_session->client_vc); UnixNetVConnection *server_vc = (UnixNetVConnection*)data; @@ -4656,7 +4656,14 @@ HttpSM::do_http_server_open(bool raw) } DebugSM("http_seq", "[HttpSM::do_http_server_open] Sending request to server"); - + ConnectionCount *connections = ConnectionCount::getInstance(); + INK_MD5 hostname_hash; + MD5Context md5_ctx; + md5_ctx.hash_immediate(hostname_hash, static_cast(t_state.current.server->name), + strlen(t_state.current.server->name)); + server_connection_count = connections->getCount(t_state.current.server->dst_addr, hostname_hash, + (TSServerSessionSharingMatchType)t_state.txn_conf->server_session_sharing_match); + milestones[TS_MILESTONE_SERVER_CONNECT] = Thread::get_hrtime(); if (milestones[TS_MILESTONE_SERVER_FIRST_CONNECT] == 0) { milestones[TS_MILESTONE_SERVER_FIRST_CONNECT] = milestones[TS_MILESTONE_SERVER_CONNECT]; @@ -4802,13 +4809,6 @@ HttpSM::do_http_server_open(bool raw) // Check to see if we have reached the max number of connections on this // host. if (t_state.txn_conf->origin_max_connections > 0) { - ConnectionCount *connections = ConnectionCount::getInstance(); - - INK_MD5 hostname_hash; - MD5Context md5_ctx; - md5_ctx.hash_immediate(hostname_hash, static_cast(t_state.current.server->name), - strlen(t_state.current.server->name)); - ip_port_text_buffer addrbuf; if (connections->getCount(t_state.current.server->dst_addr, hostname_hash, (TSServerSessionSharingMatchType)t_state.txn_conf->server_session_sharing_match) >= diff --git a/proxy/http/HttpSM.h b/proxy/http/HttpSM.h index 93b957ccee5..a09afea4091 100644 --- a/proxy/http/HttpSM.h +++ b/proxy/http/HttpSM.h @@ -499,6 +499,7 @@ class HttpSM : public Continuation const char *client_cipher_suite; int server_transact_count; bool server_connection_is_ssl; + int server_connection_count; TransactionMilestones milestones; ink_hrtime api_timer; diff --git a/proxy/http/HttpServerSession.cc b/proxy/http/HttpServerSession.cc index 8d0bd0901ad..f69cb3bc8fb 100644 --- a/proxy/http/HttpServerSession.cc +++ b/proxy/http/HttpServerSession.cc @@ -73,7 +73,7 @@ HttpServerSession::new_connection(NetVConnection *new_vc) HTTP_INCREMENT_DYN_STAT(http_total_server_connections_stat); // Check to see if we are limiting the number of connections // per host - if (enable_origin_connection_limiting == true) { + if (enable_origin_connection_tracking == true) { if (connection_count == NULL) connection_count = ConnectionCount::getInstance(); connection_count->incrementCount(server_ip, hostname_hash, sharing_match); @@ -138,7 +138,7 @@ HttpServerSession::do_io_close(int alerrno) // Check to see if we are limiting the number of connections // per host - if (enable_origin_connection_limiting == true) { + if (enable_origin_connection_tracking == true) { if (connection_count->getCount(server_ip, hostname_hash, sharing_match) >= 0) { connection_count->incrementCount(server_ip, hostname_hash, sharing_match, -1); ip_port_text_buffer addrbuf; diff --git a/proxy/http/HttpServerSession.h b/proxy/http/HttpServerSession.h index 8f57618fa79..3182778d155 100644 --- a/proxy/http/HttpServerSession.h +++ b/proxy/http/HttpServerSession.h @@ -71,7 +71,7 @@ class HttpServerSession : public VConnection HttpServerSession() : VConnection(NULL), hostname_hash(), con_id(0), transact_count(0), state(HSS_INIT), to_parent_proxy(false), server_trans_stat(0), private_session(false), sharing_match(TS_SERVER_SESSION_SHARING_MATCH_BOTH), - sharing_pool(TS_SERVER_SESSION_SHARING_POOL_GLOBAL), enable_origin_connection_limiting(false), connection_count(NULL), + sharing_pool(TS_SERVER_SESSION_SHARING_POOL_GLOBAL), enable_origin_connection_tracking(false), connection_count(NULL), read_buffer(NULL), server_vc(NULL), magic(HTTP_SS_MAGIC_DEAD), buf_reader(NULL) { ink_zero(server_ip); @@ -151,7 +151,7 @@ class HttpServerSession : public VConnection // Keep track of connection limiting and a pointer to the // singleton that keeps track of the connection counts. - bool enable_origin_connection_limiting; + bool enable_origin_connection_tracking; ConnectionCount *connection_count; // The ServerSession owns the following buffer which use diff --git a/proxy/http/HttpSessionManager.cc b/proxy/http/HttpSessionManager.cc index 004beaaf44b..2da62bcc545 100644 --- a/proxy/http/HttpSessionManager.cc +++ b/proxy/http/HttpSessionManager.cc @@ -170,7 +170,7 @@ ServerSessionPool::eventHandler(int event, void *data) // to the origin and we are below the min number of keep alive connections to this // origin, then reset the timeouts on our end and do not close the connection if ((event == VC_EVENT_INACTIVITY_TIMEOUT || event == VC_EVENT_ACTIVE_TIMEOUT) && s->state == HSS_KA_SHARED && - s->enable_origin_connection_limiting) { + s->enable_origin_connection_tracking) { bool connection_count_below_min = s->connection_count->getCount(s->server_ip, s->hostname_hash, s->sharing_match) <= http_config_params->origin_min_keep_alive_connections; diff --git a/proxy/logging/Log.cc b/proxy/logging/Log.cc index c71e373301a..bbee6754be3 100644 --- a/proxy/logging/Log.cc +++ b/proxy/logging/Log.cc @@ -718,6 +718,11 @@ Log::init_fields() &LogAccess::unmarshal_int_to_str); global_field_list.add(field, false); ink_hash_table_insert(field_symbol_hash, "sca", field); + + field = new LogField("server_connection_count", "sscc", LogField::sINT, &LogAccess::marshal_server_connection_count, + &LogAccess::unmarshal_int_to_str); + global_field_list.add(field, false); + ink_hash_table_insert(field_symbol_hash, "sscc", field); field = new LogField("cached_resp_status_code", "csssc", LogField::sINT, &LogAccess::marshal_cache_resp_status_code, &LogAccess::unmarshal_http_status); diff --git a/proxy/logging/LogAccess.cc b/proxy/logging/LogAccess.cc index 639e0e8389e..725f27c4d08 100644 --- a/proxy/logging/LogAccess.cc +++ b/proxy/logging/LogAccess.cc @@ -564,6 +564,14 @@ LogAccess::marshal_server_connect_attempts(char *buf) DEFAULT_INT_FIELD; } +/*------------------------------------------------------------------------- +-------------------------------------------------------------------------*/ +int +LogAccess::marshal_server_connection_count(char *buf) +{ + DEFAULT_INT_FIELD; +} + /*------------------------------------------------------------------------- -------------------------------------------------------------------------*/ diff --git a/proxy/logging/LogAccess.h b/proxy/logging/LogAccess.h index bda148b45a8..ca2a153e677 100644 --- a/proxy/logging/LogAccess.h +++ b/proxy/logging/LogAccess.h @@ -233,6 +233,7 @@ class LogAccess inkcoreapi virtual int marshal_server_resp_time_s(char *); // INT inkcoreapi virtual int marshal_server_transact_count(char *); // INT inkcoreapi virtual int marshal_server_connect_attempts(char *); // INT + inkcoreapi virtual int marshal_server_connection_count(char *); // INT // // cache -> client fields diff --git a/proxy/logging/LogAccessHttp.cc b/proxy/logging/LogAccessHttp.cc index 1d736cf8220..fd0d27b772a 100644 --- a/proxy/logging/LogAccessHttp.cc +++ b/proxy/logging/LogAccessHttp.cc @@ -1153,6 +1153,20 @@ LogAccessHttp::marshal_server_connect_attempts(char *buf) return INK_MIN_ALIGN; } +/*------------------------------------------------------------------------- + -------------------------------------------------------------------------*/ + +int +LogAccessHttp::marshal_server_connection_count(char *buf) +{ + if (buf) { + int64_t count; + count = m_http_sm->server_connection_count; + marshal_int(buf, count); + } + return INK_MIN_ALIGN; +} + /*------------------------------------------------------------------------- -------------------------------------------------------------------------*/ diff --git a/proxy/logging/LogAccessHttp.h b/proxy/logging/LogAccessHttp.h index 8ddde20a1db..608b58928b1 100644 --- a/proxy/logging/LogAccessHttp.h +++ b/proxy/logging/LogAccessHttp.h @@ -115,6 +115,7 @@ class LogAccessHttp : public LogAccess virtual int marshal_server_resp_time_s(char *); // INT virtual int marshal_server_transact_count(char *); // INT virtual int marshal_server_connect_attempts(char *); // INT + virtual int marshal_server_connection_count(char *); // INT // // cache -> client fields