Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix of high cpu usage occurence replicated in Broadcom based on GIT i…
…ssue #282 Solution is to switch LatencyUtils.useActualTime off, as described in javadoc of TimeServices class /** * Provide an API for time-related service, such as getting the current time and waiting for * a given period of time. By default, these services are provided by actual time services * in the JDK (i.e. System.nanoTime(), System.currentTimeMillis(), Thread.sleep(), and * java.util.concurrent.locks.LockSupport.parkNanos()). However, if the property * LatencyUtils.useActualTime is set to "false", TimeServers will only move the notion * of time in response to calls to the #setCurrentTime() method. * */ Signed-off-by: janda06 <david.janda@broadcom.com>
- Loading branch information
Showing
6 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
common-service-core/src/main/java/com/ca/mfaas/monitoring/LatencyUtilsConfigInitializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* This program and the accompanying materials are made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Copyright Contributors to the Zowe Project. | ||
*/ | ||
|
||
package com.ca.mfaas.monitoring; | ||
|
||
import org.springframework.context.ApplicationContextInitializer; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
|
||
/** | ||
* This class initializes the system property that disables LatencyUtils thread that measures time by low level java api | ||
* This needs to be done before Spring context starts to initialize | ||
* | ||
* This class has been | ||
*/ | ||
public class LatencyUtilsConfigInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> { | ||
private final String PROPERTY_KEY = "LatencyUtils.useActualTime"; | ||
@Override | ||
public void initialize(ConfigurableApplicationContext applicationContext) { | ||
if (System.getProperties().getProperty(PROPERTY_KEY) == null) | ||
System.getProperties().setProperty(PROPERTY_KEY, "false"); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...service-core/src/test/java/com/ca/mfaas/monitoring/LatencyUtilsConfigInitializerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* This program and the accompanying materials are made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Copyright Contributors to the Zowe Project. | ||
*/ | ||
|
||
package com.ca.mfaas.monitoring; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class LatencyUtilsConfigInitializerTest { | ||
private final String PROPERTY_KEY = "LatencyUtils.useActualTime"; | ||
|
||
@Test | ||
public void ShouldSetSystemPropertyWhenPropertyNotSet() { | ||
System.getProperties().remove(PROPERTY_KEY); | ||
assertNull( System.getProperties().getProperty(PROPERTY_KEY) ); | ||
|
||
LatencyUtilsConfigInitializer latencyUtilsConfigInitializer = new LatencyUtilsConfigInitializer(); | ||
latencyUtilsConfigInitializer.initialize(null); | ||
|
||
assertEquals(System.getProperties().getProperty(PROPERTY_KEY),"false"); | ||
} | ||
|
||
@Test | ||
public void ShouldNotSetSystemPropertyWhenPropertyIsSetFromBefore() { | ||
System.getProperties().remove(PROPERTY_KEY); | ||
String value = "RandomValue"; | ||
System.getProperties().setProperty(PROPERTY_KEY, value); | ||
assertEquals( System.getProperties().getProperty(PROPERTY_KEY), value ); | ||
|
||
LatencyUtilsConfigInitializer latencyUtilsConfigInitializer = new LatencyUtilsConfigInitializer(); | ||
latencyUtilsConfigInitializer.initialize(null); | ||
|
||
assertEquals( System.getProperties().getProperty(PROPERTY_KEY), value ); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters