[
https://issues.apache.org/jira/browse/GEODE-10371?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17556950#comment-17556950
]
ASF GitHub Bot commented on GEODE-10371:
----------------------------------------
gaussianrecurrence commented on code in PR #974:
URL: https://github.com/apache/geode-native/pull/974#discussion_r902718227
##########
cppcache/test/TcrConnectionTest.cpp:
##########
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <CacheImpl.hpp>
+#include <TcrConnection.hpp>
+#include <TcrConnectionManager.hpp>
+
+#include <gtest/gtest.h>
+
+namespace {
+
+using apache::geode::client::CacheImpl;
+using apache::geode::client::TcrConnection;
+using apache::geode::client::TcrConnectionManager;
+
+class TcrConnectionTest : public TcrConnection {
+ public:
+ explicit TcrConnectionTest(const TcrConnectionManager& manager)
+ : TcrConnection(manager) {}
+
+ int getExpiryTimeVariancePercentage() {
+ return expiryTimeVariancePercentage_;
+ }
+};
+
+TEST(TcrConnectionTest,
+ getExpiryTimeVariancePercentageReturnsRandomBetweenMinusNineAndNine) {
+ CacheImpl* cache = nullptr;
+
+ // Create several connections at the same time
+ const int connections = 100;
+ std::unique_ptr<TcrConnectionTest> tcrConnections[connections];
+ for (int i = 0; i < connections; i++) {
+ tcrConnections[i] =
+ std::unique_ptr<TcrConnectionTest>(new TcrConnectionTest(
+ static_cast<const TcrConnectionManager>(nullptr)));
+ }
+
Review Comment:
This is a suggestion for a change to this case or maybe for another case,
but given the goal of this change is to ensure the variance is evenly
distributed along the connections created within a close period of time, I'd
suggest instead of comparing with the first value, I'd rather sample the
distribution and check no bucket in the sample has more than x times (i.e
double) the expected amount.
> C++ Native client: Improve dispersion on connections expiration
> ---------------------------------------------------------------
>
> Key: GEODE-10371
> URL: https://issues.apache.org/jira/browse/GEODE-10371
> Project: Geode
> Issue Type: Improvement
> Components: native client
> Reporter: Alberto Gomez
> Assignee: Alberto Gomez
> Priority: Major
> Labels: pull-request-available
>
> The dispersion on connections expirations in the C++ native client works in
> such a way that it adds a dispersion (variance) between -9% and 9% over the
> time for a connection to expire due to load-conditioning so that, in the
> event of having many connections being created at the same, they do not
> expire at the right exact time.
> Nevertheless, the current implementation has two problems:
> - The randomness of the variance depends on the current time in seconds. As a
> result, for connections created in the same second, the variance will be the
> same and, therefore, the expiration time too.
> - The randomness is created using the C standard's library "rand()" function
> which is considered not secure.
> It is recommended to change the library used to generate the random variance
> to a secure one and also to make sure that for the time in seconds it does
> not return the same variance.
--
This message was sent by Atlassian Jira
(v8.20.7#820007)