This is an automated email from the ASF dual-hosted git repository.

bbender pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode-native.git


The following commit(s) were added to refs/heads/develop by this push:
     new 0d9955f  GEODE-7783: Introduce dispersion in connection expiration 
(#577)
0d9955f is described below

commit 0d9955fc23b40fca47c31359b9082d9d19e59499
Author: Alberto Bustamante Reyes <[email protected]>
AuthorDate: Mon Feb 24 17:38:49 2020 +0100

    GEODE-7783: Introduce dispersion in connection expiration (#577)
    
    * We are suffering performance issues due to c++ native client connections 
expiration.
    * Introducing some dispersion so not all connections are closed and open at 
the same time.
---
 cppcache/src/TcrConnection.cpp |  5 +++--
 cppcache/src/TcrConnection.hpp | 20 +++++++++++++++++++-
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/cppcache/src/TcrConnection.cpp b/cppcache/src/TcrConnection.cpp
index 51e5c09..7353c23 100644
--- a/cppcache/src/TcrConnection.cpp
+++ b/cppcache/src/TcrConnection.cpp
@@ -1238,8 +1238,9 @@ bool TcrConnection::hasExpired(const 
std::chrono::milliseconds& expiryTime) {
   if (expiryTime <= std::chrono::milliseconds::zero()) {
     return false;
   }
-
-  return (clock::now() - m_creationTime) > expiryTime;
+  auto variadicExpiryTime =
+      expiryTime + (expiryTime * m_expiryTimeVariancePercentage) / 100;
+  return (clock::now() - m_creationTime) > variadicExpiryTime;
 }
 
 bool TcrConnection::isIdle(const std::chrono::milliseconds& idleTime) {
diff --git a/cppcache/src/TcrConnection.hpp b/cppcache/src/TcrConnection.hpp
index 18969e1..22b4af9 100644
--- a/cppcache/src/TcrConnection.hpp
+++ b/cppcache/src/TcrConnection.hpp
@@ -142,7 +142,24 @@ class APACHE_GEODE_EXPORT TcrConnection {
         m_chunksProcessSema(0),
         m_isBeingUsed(false),
         m_isUsed(0),
-        m_poolDM(nullptr) {}
+        m_poolDM(nullptr) {
+    auto nowTimePoint = clock::now().time_since_epoch();
+    auto now_ms =
+        std::chrono::duration_cast<std::chrono::milliseconds>(nowTimePoint)
+            .count();
+    auto now_s =
+        std::chrono::duration_cast<std::chrono::seconds>(nowTimePoint).count();
+    auto seed = (now_s * 1000) + (now_ms / 1000);
+    srand(static_cast<unsigned int>(seed));
+    int numbers = 21;
+    int random = rand() % numbers + 1;
+    if (random > 10) {
+      random = random - numbers;
+    }
+    m_expiryTimeVariancePercentage = random;
+    LOGDEBUG("m_expiryTimeVariancePercentage set to: %d",
+             m_expiryTimeVariancePercentage);
+  }
 
   /* destroy the connection */
   ~TcrConnection();
@@ -307,6 +324,7 @@ class APACHE_GEODE_EXPORT TcrConnection {
  private:
   int64_t connectionId;
   const TcrConnectionManager* m_connectionManager;
+  int m_expiryTimeVariancePercentage = 0;
 
   std::chrono::microseconds calculateHeaderTimeout(
       std::chrono::microseconds receiveTimeout, bool retry);

Reply via email to