Skip to content

Commit

Permalink
Fix of high cpu usage occurence replicated in Broadcom based on GIT i…
Browse files Browse the repository at this point in the history
…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
jandadav committed Jul 8, 2019
1 parent aaf4053 commit c074095
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 0 deletions.
Expand Up @@ -10,6 +10,7 @@
package com.ca.mfaas.apicatalog;

import com.ca.mfaas.enable.EnableApiDiscovery;
import com.ca.mfaas.monitoring.LatencyUtilsConfigInitializer;
import com.ca.mfaas.product.service.BuildInfo;
import com.ca.mfaas.product.service.ServiceStartupEventHandler;
import org.springframework.boot.SpringApplication;
Expand Down Expand Up @@ -39,6 +40,7 @@ public class ApiCatalogApplication implements ApplicationListener<ApplicationRea

public static void main(String[] args) {
SpringApplication app = new SpringApplication(ApiCatalogApplication.class);
app.addInitializers(new LatencyUtilsConfigInitializer());
app.setLogStartupInfo(false);
new BuildInfo().logBuildInfo();
app.run(args);
Expand Down
@@ -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");
}
}
@@ -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 );
}

}
Expand Up @@ -10,6 +10,7 @@
package com.ca.mfaas.client;

import com.ca.mfaas.enable.EnableApiDiscovery;
import com.ca.mfaas.monitoring.LatencyUtilsConfigInitializer;
import com.ca.mfaas.product.service.BuildInfo;
import com.ca.mfaas.product.service.ServiceStartupEventHandler;
import org.springframework.boot.SpringApplication;
Expand All @@ -30,6 +31,7 @@ public class DiscoverableClientSampleApplication implements ApplicationListener<

public static void main(String[] args) {
SpringApplication app = new SpringApplication(DiscoverableClientSampleApplication.class);
app.addInitializers(new LatencyUtilsConfigInitializer());
app.setLogStartupInfo(false);
new BuildInfo().logBuildInfo();
app.run(args);
Expand Down
Expand Up @@ -9,6 +9,7 @@
*/
package com.ca.mfaas.discovery;

import com.ca.mfaas.monitoring.LatencyUtilsConfigInitializer;
import com.ca.mfaas.product.service.BuildInfo;
import com.ca.mfaas.product.service.ServiceStartupEventHandler;
import org.springframework.boot.SpringApplication;
Expand All @@ -28,6 +29,7 @@ public class DiscoveryServiceApplication implements ApplicationListener<Applicat

public static void main(String[] args) {
SpringApplication app = new SpringApplication(DiscoveryServiceApplication.class);
app.addInitializers(new LatencyUtilsConfigInitializer());
app.setLogStartupInfo(false);
new BuildInfo().logBuildInfo();
app.run(args);
Expand Down
Expand Up @@ -11,6 +11,7 @@

import com.ca.mfaas.enable.EnableApiDiscovery;
import com.ca.mfaas.gateway.ribbon.GatewayRibbonConfig;
import com.ca.mfaas.monitoring.LatencyUtilsConfigInitializer;
import com.ca.mfaas.product.service.BuildInfo;
import com.ca.mfaas.product.service.ServiceStartupEventHandler;
import org.springframework.boot.SpringApplication;
Expand Down Expand Up @@ -42,6 +43,7 @@
public class GatewayApplication implements ApplicationListener<ApplicationReadyEvent> {
public static void main(String[] args) {
SpringApplication app = new SpringApplication(GatewayApplication.class);
app.addInitializers(new LatencyUtilsConfigInitializer());
app.setLogStartupInfo(false);
new BuildInfo().logBuildInfo();
app.run(args);
Expand Down

0 comments on commit c074095

Please sign in to comment.