Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix of high cpu usage occurence replicated in Broadcom based on GIT issue #282 #326

Merged
merged 4 commits into from
Jul 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ pipeline {
archiveArtifacts artifacts: 'integration-enabler-spring-v2/build/libs/**/*.jar'
archiveArtifacts artifacts: 'integration-enabler-spring-v1-sample-app/build/libs/**/*.jar'
archiveArtifacts artifacts: 'common-service-core/build/libs/**/*.jar'
archiveArtifacts artifacts: 'gateway-common/build/libs/**/*.jar'
archiveArtifacts artifacts: 'apiml-common/build/libs/**/*.jar'
archiveArtifacts artifacts: 'scripts/apiml_cm.sh'
archiveArtifacts artifacts: 'api-layer.tar.gz'

Expand Down
2 changes: 1 addition & 1 deletion api-catalog-services/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ gitProperties {
}

dependencies {
compile(project(':gateway-common'))
compile(project(':apiml-common'))
compile(project(':integration-enabler-spring-v2'))
compile(project(':common-service-core'))
compile(project(':security-module'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
package com.ca.mfaas.apicatalog;

import com.ca.mfaas.enable.EnableApiDiscovery;
import com.ca.mfaas.product.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
File renamed without changes.
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.product.monitoring;

import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import javax.annotation.Nonnull;

/**
* 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
*/
public class LatencyUtilsConfigInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
private static final String PROPERTY_KEY = "LatencyUtils.useActualTime";
@Override
public void initialize(@Nonnull ConfigurableApplicationContext applicationContext) {
if (System.getProperties().getProperty(PROPERTY_KEY) == null) {
System.getProperties().setProperty(PROPERTY_KEY, "false");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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.product.monitoring;

import org.junit.Test;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.GenericApplicationContext;

import static org.junit.Assert.*;

public class LatencyUtilsConfigInitializerTest {
private static final String PROPERTY_KEY = "LatencyUtils.useActualTime";
private final ConfigurableApplicationContext applicationContext = new GenericApplicationContext();

@Test
public void shouldSetSystemPropertyWhenPropertyNotSet() {
System.getProperties().remove(PROPERTY_KEY);
assertNull(System.getProperties().getProperty(PROPERTY_KEY));

LatencyUtilsConfigInitializer latencyUtilsConfigInitializer = new LatencyUtilsConfigInitializer();
latencyUtilsConfigInitializer.initialize(applicationContext);

assertEquals("false", System.getProperties().getProperty(PROPERTY_KEY));
}

@Test
public void shouldNotSetSystemPropertyWhenPropertyIsSetFromBefore() {
System.getProperties().remove(PROPERTY_KEY);
String value = "RandomValue";
System.getProperties().setProperty(PROPERTY_KEY, value);
assertEquals(value, System.getProperties().getProperty(PROPERTY_KEY));

LatencyUtilsConfigInitializer latencyUtilsConfigInitializer = new LatencyUtilsConfigInitializer();
latencyUtilsConfigInitializer.initialize(applicationContext);

assertEquals(value, System.getProperties().getProperty(PROPERTY_KEY));
}

}
5 changes: 5 additions & 0 deletions codequality/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
<!-- follow Java naming conventions for naming variables -->
<module name="LocalVariableName"/>

<!-- Ensure methods begin with a lower case letter, followed by letters, digits, and underscores -->
<module name="MethodName">
<property name="format" value="^[a-z](_?[a-zA-Z0-9]+)*$"/>
</module>

</module>

<!-- Read checkstyle suppressions from a file -->
Expand Down
3 changes: 3 additions & 0 deletions codequality/checkstyle/suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
"-//Puppy Crawl//DTD Suppressions 1.1//EN"
"http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
<suppressions>
<suppress checks="MethodName"
files=".*security-module.*"
/>
</suppressions>
2 changes: 1 addition & 1 deletion discoverable-client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ gitProperties {

dependencies {
compile(project(':integration-enabler-spring-v2'))
compile(project(':gateway-common'))
compile(project(':apiml-common'))

compile libraries.gson
compile libraries.spring_boot_starter_actuator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
package com.ca.mfaas.client;

import com.ca.mfaas.enable.EnableApiDiscovery;
import com.ca.mfaas.product.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
2 changes: 1 addition & 1 deletion discovery-service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ gitProperties {
}

dependencies {
compile(project(':gateway-common'))
compile(project(':apiml-common'))

compile libraries.spring_boot_starter_web
compile libraries.spring_boot_starter_security
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
package com.ca.mfaas.discovery;

import com.ca.mfaas.product.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
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 4. Configuration of LatencyUtils to reduce cpu time used

Date: 2019-07-02

## Status

Accepted

## Context

CPU time used by Api Mediation Layer when idle should be minimal. We managed to reproduce a case where high cpu (hours per day) was consumed on one of our system. It has been identified that one of LatencyUtils threads is spending time constantly measuring time and accumulating used cpu time. LatencyUtils is transitive dependency of Spring Actuator

## Decision

Decision has been accepted that we will configure LatencyUtils to measure time in a different mode. System property `LatencyUtils.useActualTime` will be set to `false` programmatically before the Spring application is started.

## Consequences

Actuator metrics functionality is not impacted by this change.

This should be retested whenever we upgrade version of SpringBoot.
2 changes: 1 addition & 1 deletion gateway-service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ gitProperties {

dependencies {
compile(project(':common-service-core'))
compile(project(':gateway-common'))
compile(project(':apiml-common'))
compile(project(':integration-enabler-spring-v2'))
compile(project(':security-service-client-spring'))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import com.ca.mfaas.enable.EnableApiDiscovery;
import com.ca.mfaas.gateway.ribbon.GatewayRibbonConfig;
import com.ca.mfaas.product.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
2 changes: 1 addition & 1 deletion gradle/coverage.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ext.javaProjectsWithUnitTests = [
'common-service-core',
'discoverable-client',
'discovery-service',
'gateway-common',
'apiml-common',
'gateway-service',
'integration-enabler-spring-v2',
'integration-enabler-java',
Expand Down
2 changes: 1 addition & 1 deletion gradle/publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ext.javaEnablers = [

ext.javaLibraries = [
'common-service-core',
'gateway-common'
'apiml-common'
]

ext.serviceJars = [ 'zowe-install' ]
Expand Down
2 changes: 1 addition & 1 deletion security-module/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
dependencies {
compile(project(':common-service-core'))
compile(project(':gateway-common'))
compile(project(':apiml-common'))

compile libraries.jjwt
compile libraries.apacheCommons
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ include 'helloworld-jersey'
include 'discovery-service'
include 'integration-enabler-spring-v2'
include 'integration-enabler-spring-v1'
include 'gateway-common'
include 'apiml-common'
include 'gateway-service'
include 'common-service-core'
include 'discoverable-client'
Expand Down