This is an automated email from the ASF dual-hosted git repository.
bnolsen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new e964cb73e3 move session pool metrics calls outside critical section
(#10996)
e964cb73e3 is described below
commit e964cb73e33fc19a9b758e816923b6f3b32cb574
Author: Brian Olsen <[email protected]>
AuthorDate: Tue Jan 23 09:28:32 2024 -0700
move session pool metrics calls outside critical section (#10996)
---
src/proxy/http/HttpSessionManager.cc | 49 ++++++++++++++++++++++--------------
1 file changed, 30 insertions(+), 19 deletions(-)
diff --git a/src/proxy/http/HttpSessionManager.cc
b/src/proxy/http/HttpSessionManager.cc
index 9f4a28e4e9..9bb015053e 100644
--- a/src/proxy/http/HttpSessionManager.cc
+++ b/src/proxy/http/HttpSessionManager.cc
@@ -419,6 +419,7 @@ HttpSessionManager::_acquire_session(sockaddr const *ip,
CryptoHash const &hostn
{
PoolableSession *to_return = nullptr;
HSMresult_t retval = HSM_NOT_FOUND;
+ bool acquired = false;
// Extend the mutex window until the acquired Server session is attached
// to the SM. Releasing the mutex before that results in race conditions
@@ -435,10 +436,12 @@ HttpSessionManager::_acquire_session(sockaddr const *ip,
CryptoHash const &hostn
if (locked) {
if (TS_SERVER_SESSION_SHARING_POOL_THREAD == pool_type) {
- retval = ethread->server_session_pool->acquireSession(ip,
hostname_hash, match_style, sm, to_return);
+ retval = ethread->server_session_pool->acquireSession(ip,
hostname_hash, match_style, sm, to_return);
+ acquired = (HSM_DONE == retval);
Debug("http_ss", "[acquire session] thread pool search %s", to_return
? "successful" : "failed");
} else {
- retval = m_g_pool->acquireSession(ip, hostname_hash, match_style, sm,
to_return);
+ retval = m_g_pool->acquireSession(ip, hostname_hash, match_style,
sm, to_return);
+ acquired = (HSM_DONE == retval);
Debug("http_ss", "[acquire session] global pool search %s", to_return
? "successful" : "failed");
// At this point to_return has been removed from the pool. Do we need
to move it
// to the same thread?
@@ -491,6 +494,11 @@ HttpSessionManager::_acquire_session(sockaddr const *ip,
CryptoHash const &hostn
}
}
}
+
+ if (acquired) {
+ Metrics::Gauge::decrement(http_rsb.pooled_server_connections);
+ }
+
return retval;
}
@@ -504,20 +512,26 @@ HttpSessionManager::release_session(PoolableSession
*to_release)
// The per thread lock looks like it should not be needed but if it's not
locked the close checking I/O op will crash.
- MutexLock mlock;
- MutexTryLock tlock;
- bool const locked = lockSessionPool(pool->mutex, ethread,
this->get_pool_type(), &mlock, &tlock);
+ {
+ MutexLock mlock;
+ MutexTryLock tlock;
+ bool const locked = lockSessionPool(pool->mutex, ethread,
this->get_pool_type(), &mlock, &tlock);
- if (locked) {
- pool->releaseSession(to_release);
- } else if (this->get_pool_type() == TS_SERVER_SESSION_SHARING_POOL_HYBRID) {
- // Try again with the thread pool
- to_release->sharing_pool = TS_SERVER_SESSION_SHARING_POOL_THREAD;
- return release_session(to_release);
- } else {
- Debug("http_ss", "[%" PRId64 "] [release session] could not release
session due to lock contention",
- to_release->connection_id());
- released_p = false;
+ if (locked) {
+ pool->releaseSession(to_release);
+ } else if (this->get_pool_type() == TS_SERVER_SESSION_SHARING_POOL_HYBRID)
{
+ // Try again with the thread pool
+ to_release->sharing_pool = TS_SERVER_SESSION_SHARING_POOL_THREAD;
+ return release_session(to_release);
+ } else {
+ Debug("http_ss", "[%" PRId64 "] [release session] could not release
session due to lock contention",
+ to_release->connection_id());
+ released_p = false;
+ }
+ }
+
+ if (released_p) {
+ Metrics::Gauge::increment(http_rsb.pooled_server_connections);
}
return released_p ? HSM_DONE : HSM_RETRY;
@@ -535,9 +549,7 @@ ServerSessionPool::removeSession(PoolableSession *to_remove)
m_ip_pool.count());
}
m_fqdn_pool.erase(to_remove);
- if (m_ip_pool.erase(to_remove)) {
- Metrics::Gauge::decrement(http_rsb.pooled_server_connections);
- }
+ m_ip_pool.erase(to_remove);
if (is_debug_tag_set("http_ss")) {
Debug("http_ss", "After Remove session %p m_fqdn_pool size=%zu
m_ip_pool_size=%zu", to_remove, m_fqdn_pool.count(),
m_ip_pool.count());
@@ -552,7 +564,6 @@ ServerSessionPool::addSession(PoolableSession *ss)
// put it in the pools.
m_ip_pool.insert(ss);
m_fqdn_pool.insert(ss);
- Metrics::Gauge::increment(http_rsb.pooled_server_connections);
if (is_debug_tag_set("http_ss")) {
char peer_ip[INET6_ADDRPORTSTRLEN];