This is an automated email from the ASF dual-hosted git repository.
bschuchardt pushed a commit to branch feature/GEODE-6583
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/feature/GEODE-6583 by this
push:
new 0d1fd84 removed sync when creating detectors & cleaned up copyright
notice
0d1fd84 is described below
commit 0d1fd846d309b24746a7c687724a60d549fb1b53
Author: Bruce Schuchardt <[email protected]>
AuthorDate: Tue Apr 2 08:37:34 2019 -0700
removed sync when creating detectors & cleaned up copyright notice
also added a test of the phi detector
---
.../gms/fd/PhiAccrualFailureDetectorTest.java | 86 ++++++++++++++++++++++
.../membership/gms/fd/GMSHealthMonitor.java | 28 ++++---
.../gms/fd/PhiAccrualFailureDetector.java | 36 +++------
3 files changed, 109 insertions(+), 41 deletions(-)
diff --git
a/geode-core/src/integrationTest/java/org/apache/geode/distributed/internal/membership/gms/fd/PhiAccrualFailureDetectorTest.java
b/geode-core/src/integrationTest/java/org/apache/geode/distributed/internal/membership/gms/fd/PhiAccrualFailureDetectorTest.java
new file mode 100644
index 0000000..d3e6a64
--- /dev/null
+++
b/geode-core/src/integrationTest/java/org/apache/geode/distributed/internal/membership/gms/fd/PhiAccrualFailureDetectorTest.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2018 Mitsunori Komatsu (komamitsu)
+ *
+ * Licensed 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.
+ */
+
+package org.apache.geode.distributed.internal.membership.gms.fd;
+
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import static org.junit.Assert.*;
+
+import org.apache.geode.test.junit.categories.MembershipTest;
+
+@Category({MembershipTest.class})
+public class PhiAccrualFailureDetectorTest
+{
+ @Test
+ public void test()
+ {
+ PhiAccrualFailureDetector failureDetector = new
PhiAccrualFailureDetector.Builder().build();
+ long now = 1420070400000L;
+ for (int i = 0; i < 300; i++) {
+ long timestampMillis = now + i * 1000;
+
+ if (i > 290) {
+ double phi = failureDetector.phi(timestampMillis);
+ if (i == 291) {
+ assertTrue(1 < phi && phi < 3);
+ assertTrue(failureDetector.isAvailable(timestampMillis));
+ }
+ else if (i == 292) {
+ assertTrue(3 < phi && phi < 8);
+ assertTrue(failureDetector.isAvailable(timestampMillis));
+ }
+ else if (i == 293) {
+ assertTrue(8 < phi && phi < 16);
+ assertTrue(failureDetector.isAvailable(timestampMillis));
+ }
+ else if (i == 294) {
+ assertTrue(16 < phi && phi < 30);
+ assertFalse(failureDetector.isAvailable(timestampMillis));
+ }
+ else if (i == 295) {
+ assertTrue(30 < phi && phi < 50);
+ assertFalse(failureDetector.isAvailable(timestampMillis));
+ }
+ else if (i == 296) {
+ assertTrue(50 < phi && phi < 70);
+ assertFalse(failureDetector.isAvailable(timestampMillis));
+ }
+ else if (i == 297) {
+ assertTrue(70 < phi && phi < 100);
+ assertFalse(failureDetector.isAvailable(timestampMillis));
+ }
+ else {
+ assertTrue(100 < phi);
+ assertFalse(failureDetector.isAvailable(timestampMillis));
+ }
+ continue;
+ }
+ else if (i > 200) {
+ if (i % 5 == 0) {
+ double phi = failureDetector.phi(timestampMillis);
+ assertTrue(0.1 < phi && phi < 0.5);
+ assertTrue(failureDetector.isAvailable(timestampMillis));
+ continue;
+ }
+ }
+ failureDetector.heartbeat(timestampMillis);
+ assertTrue(failureDetector.phi(timestampMillis) < 0.1);
+ assertTrue(failureDetector.isAvailable(timestampMillis));
+ }
+ }
+}
diff --git
a/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/gms/fd/GMSHealthMonitor.java
b/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/gms/fd/GMSHealthMonitor.java
index 41e41e5..ac8c35f 100644
---
a/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/gms/fd/GMSHealthMonitor.java
+++
b/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/gms/fd/GMSHealthMonitor.java
@@ -385,21 +385,19 @@ public class GMSHealthMonitor implements HealthMonitor,
MessageHandler {
public PhiAccrualFailureDetector getOrCreatePhiAccrualFailureDetector(
InternalDistributedMember member,
long timeStamp) {
- PhiAccrualFailureDetector detector;
- // TODO use something cheaper than a sync on the health monitor
- synchronized (GMSHealthMonitor.this) {
- detector = GMSHealthMonitor.this.memberDetectors.get(member);
-
- if (detector == null) {
- logger.info("creating new failure detector for {}", member);
- final double threshold = 10;
- final int sampleSize = 200;
- final int minStdDev = 100;
- detector = new PhiAccrualFailureDetector(
- threshold, sampleSize, minStdDev, memberTimeout, memberTimeout);
- detector.heartbeat(timeStamp);
- memberDetectors.put(member, detector);
- }
+ PhiAccrualFailureDetector detector =
GMSHealthMonitor.this.memberDetectors.get(member);
+
+ if (detector == null) {
+ // it's okay to not synchronize here - if we happen to create another
detector
+ // for this member in another thread it will be pretty equivalent to the
one created here
+ logger.info("Creating new failure detector for {}", member);
+ final int threshold = Integer.getInteger("geode.phiAccrualThreshold",
10);
+ final int sampleSize = Integer.getInteger("geode.phiAccrualSampleSize",
200);
+ final int minStdDev =
Integer.getInteger("geode.phiAccrualMinimumStandardDeviation", 100);
+ detector = new PhiAccrualFailureDetector(
+ threshold, sampleSize, minStdDev, memberTimeout, memberTimeout);
+ detector.heartbeat(timeStamp);
+ memberDetectors.put(member, detector);
}
return detector;
}
diff --git
a/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/gms/fd/PhiAccrualFailureDetector.java
b/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/gms/fd/PhiAccrualFailureDetector.java
index 760fbdc..2748e5d 100644
---
a/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/gms/fd/PhiAccrualFailureDetector.java
+++
b/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/gms/fd/PhiAccrualFailureDetector.java
@@ -1,20 +1,4 @@
/*
- * 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.
- */
-package org.apache.geode.distributed.internal.membership.gms.fd;
-
-/*
* Copyright 2018 Mitsunori Komatsu (komamitsu)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -30,37 +14,37 @@ package
org.apache.geode.distributed.internal.membership.gms.fd;
* limitations under the License.
*/
+package org.apache.geode.distributed.internal.membership.gms.fd;
+
import java.util.LinkedList;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
-import org.apache.logging.log4j.Logger;
-
-import org.apache.geode.internal.logging.LogService;
-
/**
+ * <p>Ported to Geode from
https://github.com/komamitsu/phi-accural-failure-detector. Javadoc
+ * from that repo follows...</p>
+ * <p>
* This is a port of
*
https://github.com/akka/akka/blob/master/akka-remote/src/main/scala/akka/remote/PhiAccrualFailureDetector.scala
*
* Implementation of 'The Phi Accrual Failure Detector' by Hayashibara et al.
as defined in their
* paper:
* [http://ddg.jaist.ac.jp/pub/HDY+04.pdf]
- *
+ *<p>
* The suspicion level of failure is given by a value called φ (phi).
* The basic idea of the φ failure detector is to express the value of φ on a
scale that
* is dynamically adjusted to reflect current network conditions. A
configurable
* threshold is used to decide if φ is considered to be a failure.
- *
+ *<p>
* The value of φ is calculated as:
- *
- * {{{
+ *<pre>
* φ = -log10(1 - F(timeSinceLastHeartbeat)
- * }}}
+ * </pre>
* where F is the cumulative distribution function of a normal distribution
with mean
* and standard deviation estimated from historical heartbeat inter-arrival
times.
+ *
*/
public class PhiAccrualFailureDetector {
- private static final Logger logger = LogService.getLogger();
private final double threshold;
private final double minStdDeviationMillis;
private final long acceptableHeartbeatPauseMillis;