Skip to content

Commit 63368c9

Browse files
authored
Merge pull request #762 from oracle/diag-cm-threads
CPU burn bug observed with config map watch and lower logging levels for several entries.
2 parents debc44a + 216f4bf commit 63368c9

File tree

8 files changed

+191
-12
lines changed

8 files changed

+191
-12
lines changed

operator/src/main/java/oracle/kubernetes/operator/ConfigMapWatcher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
1+
// Copyright 2018, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
22
// Licensed under the Universal Permissive License v 1.0 as shown at
33
// http://oss.oracle.com/licenses/upl.
44

operator/src/main/java/oracle/kubernetes/operator/TuningParameters.java

Lines changed: 161 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2017, 2018, Oracle Corporation and/or its affiliates. All rights reserved.
1+
// Copyright 2017, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
22
// Licensed under the Universal Permissive License v 1.0 as shown at
33
// http://oss.oracle.com/licenses/upl.
44

@@ -7,6 +7,9 @@
77
import java.io.IOException;
88
import java.util.Map;
99
import java.util.concurrent.ScheduledExecutorService;
10+
import org.apache.commons.lang3.builder.EqualsBuilder;
11+
import org.apache.commons.lang3.builder.HashCodeBuilder;
12+
import org.apache.commons.lang3.builder.ToStringBuilder;
1013

1114
public interface TuningParameters extends Map<String, String> {
1215

@@ -47,6 +50,55 @@ public MainTuning(
4750
this.initialShortDelay = initialShortDelay;
4851
this.eventualLongDelay = eventualLongDelay;
4952
}
53+
54+
@Override
55+
public String toString() {
56+
return new ToStringBuilder(this)
57+
.append("domainPresenceFailureRetrySeconds", domainPresenceFailureRetrySeconds)
58+
.append("domainPresenceFailureRetryMaxCount", domainPresenceFailureRetryMaxCount)
59+
.append("domainPresenceRecheckIntervalSeconds", domainPresenceRecheckIntervalSeconds)
60+
.append("targetNamespaceRecheckIntervalSeconds", targetNamespaceRecheckIntervalSeconds)
61+
.append("statusUpdateTimeoutSeconds", statusUpdateTimeoutSeconds)
62+
.append("unchangedCountToDelayStatusRecheck", unchangedCountToDelayStatusRecheck)
63+
.append("initialShortDelay", initialShortDelay)
64+
.append("eventualLongDelay", eventualLongDelay)
65+
.toString();
66+
}
67+
68+
@Override
69+
public int hashCode() {
70+
return new HashCodeBuilder()
71+
.append(domainPresenceFailureRetrySeconds)
72+
.append(domainPresenceFailureRetryMaxCount)
73+
.append(domainPresenceRecheckIntervalSeconds)
74+
.append(targetNamespaceRecheckIntervalSeconds)
75+
.append(statusUpdateTimeoutSeconds)
76+
.append(unchangedCountToDelayStatusRecheck)
77+
.append(initialShortDelay)
78+
.append(eventualLongDelay)
79+
.toHashCode();
80+
}
81+
82+
@Override
83+
public boolean equals(Object o) {
84+
if (o == null) {
85+
return false;
86+
}
87+
if (!(o instanceof MainTuning)) {
88+
return false;
89+
}
90+
MainTuning mt = (MainTuning) o;
91+
return new EqualsBuilder()
92+
.append(domainPresenceFailureRetrySeconds, mt.domainPresenceFailureRetrySeconds)
93+
.append(domainPresenceFailureRetryMaxCount, mt.domainPresenceFailureRetryMaxCount)
94+
.append(domainPresenceRecheckIntervalSeconds, mt.domainPresenceRecheckIntervalSeconds)
95+
.append(targetNamespaceRecheckIntervalSeconds, mt.targetNamespaceRecheckIntervalSeconds)
96+
.append(statusUpdateTimeoutSeconds, mt.statusUpdateTimeoutSeconds)
97+
.append(unchangedCountToDelayStatusRecheck, mt.unchangedCountToDelayStatusRecheck)
98+
.append(initialShortDelay, mt.initialShortDelay)
99+
.append(eventualLongDelay, mt.eventualLongDelay)
100+
.isEquals();
101+
}
50102
}
51103

52104
public static class CallBuilderTuning {
@@ -59,13 +111,77 @@ public CallBuilderTuning(int callRequestLimit, int callMaxRetryCount, int callTi
59111
this.callMaxRetryCount = callMaxRetryCount;
60112
this.callTimeoutSeconds = callTimeoutSeconds;
61113
}
114+
115+
@Override
116+
public String toString() {
117+
return new ToStringBuilder(this)
118+
.append("callRequestLimit", callRequestLimit)
119+
.append("callMaxRetryCount", callMaxRetryCount)
120+
.append("callTimeoutSeconds", callTimeoutSeconds)
121+
.toString();
122+
}
123+
124+
@Override
125+
public int hashCode() {
126+
return new HashCodeBuilder()
127+
.append(callRequestLimit)
128+
.append(callMaxRetryCount)
129+
.append(callTimeoutSeconds)
130+
.toHashCode();
131+
}
132+
133+
@Override
134+
public boolean equals(Object o) {
135+
if (o == null) {
136+
return false;
137+
}
138+
if (!(o instanceof CallBuilderTuning)) {
139+
return false;
140+
}
141+
CallBuilderTuning cbt = (CallBuilderTuning) o;
142+
return new EqualsBuilder()
143+
.append(callRequestLimit, cbt.callRequestLimit)
144+
.append(callMaxRetryCount, cbt.callMaxRetryCount)
145+
.append(callTimeoutSeconds, cbt.callTimeoutSeconds)
146+
.isEquals();
147+
}
62148
}
63149

64150
public static class WatchTuning {
65151
public final int watchLifetime;
152+
public final int watchMinimumDelay;
66153

67-
public WatchTuning(int watchLifetime) {
154+
public WatchTuning(int watchLifetime, int watchMinimumDelay) {
68155
this.watchLifetime = watchLifetime;
156+
this.watchMinimumDelay = watchMinimumDelay;
157+
}
158+
159+
@Override
160+
public String toString() {
161+
return new ToStringBuilder(this)
162+
.append("watchLifetime", watchLifetime)
163+
.append("watchMinimumDelay", watchMinimumDelay)
164+
.toString();
165+
}
166+
167+
@Override
168+
public int hashCode() {
169+
return new HashCodeBuilder().append(watchLifetime).append(watchMinimumDelay).toHashCode();
170+
}
171+
172+
@Override
173+
public boolean equals(Object o) {
174+
if (o == null) {
175+
return false;
176+
}
177+
if (!(o instanceof WatchTuning)) {
178+
return false;
179+
}
180+
WatchTuning wt = (WatchTuning) o;
181+
return new EqualsBuilder()
182+
.append(watchLifetime, wt.watchLifetime)
183+
.append(watchMinimumDelay, wt.watchMinimumDelay)
184+
.isEquals();
69185
}
70186
}
71187

@@ -91,6 +207,49 @@ public PodTuning(
91207
this.livenessProbeTimeoutSeconds = livenessProbeTimeoutSeconds;
92208
this.livenessProbePeriodSeconds = livenessProbePeriodSeconds;
93209
}
210+
211+
@Override
212+
public String toString() {
213+
return new ToStringBuilder(this)
214+
.append("readinessProbeInitialDelaySeconds", readinessProbeInitialDelaySeconds)
215+
.append("readinessProbeTimeoutSeconds", readinessProbeTimeoutSeconds)
216+
.append("readinessProbePeriodSeconds", readinessProbePeriodSeconds)
217+
.append("livenessProbeInitialDelaySeconds", livenessProbeInitialDelaySeconds)
218+
.append("livenessProbeTimeoutSeconds", livenessProbeTimeoutSeconds)
219+
.append("livenessProbePeriodSeconds", livenessProbePeriodSeconds)
220+
.toString();
221+
}
222+
223+
@Override
224+
public int hashCode() {
225+
return new HashCodeBuilder()
226+
.append(readinessProbeInitialDelaySeconds)
227+
.append(readinessProbeTimeoutSeconds)
228+
.append(readinessProbePeriodSeconds)
229+
.append(livenessProbeInitialDelaySeconds)
230+
.append(livenessProbeTimeoutSeconds)
231+
.append(livenessProbePeriodSeconds)
232+
.toHashCode();
233+
}
234+
235+
@Override
236+
public boolean equals(Object o) {
237+
if (o == null) {
238+
return false;
239+
}
240+
if (!(o instanceof PodTuning)) {
241+
return false;
242+
}
243+
PodTuning pt = (PodTuning) o;
244+
return new EqualsBuilder()
245+
.append(readinessProbeInitialDelaySeconds, pt.readinessProbeInitialDelaySeconds)
246+
.append(readinessProbeTimeoutSeconds, pt.readinessProbeTimeoutSeconds)
247+
.append(readinessProbePeriodSeconds, pt.readinessProbePeriodSeconds)
248+
.append(livenessProbeInitialDelaySeconds, pt.livenessProbeInitialDelaySeconds)
249+
.append(livenessProbeTimeoutSeconds, pt.livenessProbeTimeoutSeconds)
250+
.append(livenessProbePeriodSeconds, pt.livenessProbePeriodSeconds)
251+
.isEquals();
252+
}
94253
}
95254

96255
public MainTuning getMainTuning();

operator/src/main/java/oracle/kubernetes/operator/TuningParametersImpl.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2017, 2018, Oracle Corporation and/or its affiliates. All rights reserved.
1+
// Copyright 2017, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
22
// Licensed under the Universal Permissive License v 1.0 as shown at
33
// http://oss.oracle.com/licenses/upl.
44

@@ -47,8 +47,6 @@ private static void updateTuningParameters() {
4747
}
4848

4949
private void update() {
50-
LOGGER.info(MessageKeys.TUNING_PARAMETERS);
51-
5250
MainTuning main =
5351
new MainTuning(
5452
(int) readTuningParameter("domainPresenceFailureRetrySeconds", 10),
@@ -66,7 +64,10 @@ private void update() {
6664
(int) readTuningParameter("callMaxRetryCount", 5),
6765
(int) readTuningParameter("callTimeoutSeconds", 10));
6866

69-
WatchTuning watch = new WatchTuning((int) readTuningParameter("watchLifetime", 300));
67+
WatchTuning watch =
68+
new WatchTuning(
69+
(int) readTuningParameter("watchLifetime", 300),
70+
(int) readTuningParameter("watchMinimumDelay", 5));
7071

7172
PodTuning pod =
7273
new PodTuning(
@@ -79,6 +80,12 @@ private void update() {
7980

8081
lock.writeLock().lock();
8182
try {
83+
if (!main.equals(this.main)
84+
|| !callBuilder.equals(this.callBuilder)
85+
|| !watch.equals(this.watch)
86+
|| !pod.equals(this.pod)) {
87+
LOGGER.info(MessageKeys.TUNING_PARAMETERS);
88+
}
8289
this.main = main;
8390
this.callBuilder = callBuilder;
8491
this.watch = watch;

operator/src/main/java/oracle/kubernetes/operator/Watcher.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ abstract class Watcher<T> {
3838
private AtomicBoolean stopping;
3939
private WatchListener<T> listener;
4040
private Thread thread = null;
41+
private long lastInitialize = 0;
4142

4243
/**
4344
* Constructs a watcher without specifying a listener. Needed when the listener is the watch
@@ -120,6 +121,18 @@ protected boolean isStopping() {
120121
}
121122

122123
private void watchForEvents() {
124+
long now = System.currentTimeMillis();
125+
long delay = (tuning.watchMinimumDelay * 1000) - (now - lastInitialize);
126+
if (lastInitialize != 0 && delay > 0) {
127+
try {
128+
Thread.sleep(delay);
129+
} catch (InterruptedException ex) {
130+
LOGGER.warning(MessageKeys.EXCEPTION, ex);
131+
}
132+
lastInitialize = System.currentTimeMillis();
133+
} else {
134+
lastInitialize = now;
135+
}
123136
try (WatchI<T> watch =
124137
initiateWatch(
125138
new WatchBuilder()

operator/src/main/java/oracle/kubernetes/operator/helpers/ConfigMapHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private V1ObjectMeta createMetadata() {
9090

9191
private synchronized Map<String, String> loadScriptsFromClasspath() {
9292
Map<String, String> scripts = scriptReader.loadFilesFromClasspath();
93-
LOGGER.info(MessageKeys.SCRIPT_LOADED, this.domainNamespace);
93+
LOGGER.fine(MessageKeys.SCRIPT_LOADED, this.domainNamespace);
9494
return scripts;
9595
}
9696

operator/src/main/java/oracle/kubernetes/operator/steps/ConfigMapAfterStep.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2017, 2018, Oracle Corporation and/or its affiliates. All rights reserved.
1+
// Copyright 2017, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
22
// Licensed under the Universal Permissive License v 1.0 as shown at
33
// http://oss.oracle.com/licenses/upl.
44

operator/src/test/java/oracle/kubernetes/operator/WatcherTestBase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2018 Oracle Corporation and/or its affiliates. All rights reserved.
1+
// Copyright 2018, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
22
// Licensed under the Universal Permissive License v 1.0 as shown at
33
// http://oss.oracle.com/licenses/upl.
44

@@ -41,7 +41,7 @@ public abstract class WatcherTestBase extends ThreadFactoryTestBase
4141

4242
private int resourceVersion = INITIAL_RESOURCE_VERSION;
4343

44-
protected WatchTuning tuning = new WatchTuning(30);
44+
protected WatchTuning tuning = new WatchTuning(30, 0);
4545

4646
private V1ObjectMeta createMetaData() {
4747
return createMetaData("test", NAMESPACE);

operator/src/test/java/oracle/kubernetes/operator/helpers/DomainIntrospectorJobTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ static String getJobName() {
290290
}
291291

292292
FiberTestSupport.StepFactory getStepFactory() {
293-
return next -> JobHelper.createDomainIntrospectorJobStep(new WatchTuning(30), next);
293+
return next -> JobHelper.createDomainIntrospectorJobStep(new WatchTuning(30, 0), next);
294294
}
295295

296296
V1PodList createListPods() {

0 commit comments

Comments
 (0)