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

Conversation

jandadav
Copy link
Contributor

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

@codecov
Copy link

codecov bot commented Jun 26, 2019

Codecov Report

Merging #326 into master will decrease coverage by 0.03%.
The diff coverage is 50%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #326      +/-   ##
============================================
- Coverage     70.02%   69.98%   -0.04%     
  Complexity       12       12              
============================================
  Files           237      238       +1     
  Lines          4540     4548       +8     
  Branches        574      574              
============================================
+ Hits           3179     3183       +4     
- Misses         1203     1207       +4     
  Partials        158      158
Impacted Files Coverage Δ Complexity Δ
...va/com/ca/mfaas/product/constants/CoreService.java 100% <ø> (ø) 0 <0> (?)
...ava/com/ca/mfaas/product/logging/UseridFilter.java 100% <ø> (ø) 0 <0> (?)
.../ca/mfaas/product/registry/ApplicationWrapper.java 100% <ø> (ø) 0 <0> (?)
...as/product/service/ServiceStartupEventHandler.java 50% <ø> (ø) 0 <0> (?)
...as/product/routing/transform/TransformService.java 100% <ø> (ø) 0 <0> (?)
...main/java/com/ca/mfaas/product/utils/UrlUtils.java 76.92% <ø> (ø) 0 <0> (?)
...egistry/DiscoveryServiceNotAvailableException.java 0% <ø> (ø) 0 <0> (?)
...faas/product/security/WebServerSecurityConfig.java 100% <ø> (ø) 0 <0> (?)
.../routing/transform/URLTransformationException.java 50% <ø> (ø) 0 <0> (?)
...oduct/registry/CannotRegisterServiceException.java 0% <ø> (ø) 0 <0> (?)
... and 11 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update aaf4053...afdc01d. Read the comment docs.

cZikos
cZikos previously approved these changes Jun 27, 2019
@jandadav
Copy link
Contributor Author

jandadav commented Jul 1, 2019

I have reworked the solution based on the feedback from Jirka and Lena

@cZikos cZikos self-requested a review July 1, 2019 13:19
@petr-galik petr-galik requested review from arxioly and JirkaAichler and removed request for cZikos July 1, 2019 13:19
Copy link
Contributor

@JirkaAichler JirkaAichler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few minor issues.

* This class has been
*/
public class LatencyUtilsConfigInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
private final String PROPERTY_KEY = "LatencyUtils.useActualTime";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make this static.

*
* This class has been
*/
public class LatencyUtilsConfigInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try using @nonnull annotation

Copy link
Contributor

@arxioly arxioly Jul 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not @NotNull, it's @Nullable should be, because, you sending to this method null in test. So, you have two options: create application context object and send to this method, or add this @Nullable annotation. I would suggest to create some simple common context for this test and use it, for example:
private final ConfigurableApplicationContext ctx = new GenericApplicationContext();

P.s.: wrong line, the correct is 25 :)

*
* This class has been
*/
public class LatencyUtilsConfigInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
Copy link
Contributor

@arxioly arxioly Jul 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not @NotNull, it's @Nullable should be, because, you sending to this method null in test. So, you have two options: create application context object and send to this method, or add this @Nullable annotation. I would suggest to create some simple common context for this test and use it, for example:
private final ConfigurableApplicationContext ctx = new GenericApplicationContext();

P.s.: wrong line, the correct is 25 :)

@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
if (System.getProperties().getProperty(PROPERTY_KEY) == null)
System.getProperties().setProperty(PROPERTY_KEY, "false");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, make the block with {}.

assertNull( System.getProperties().getProperty(PROPERTY_KEY) );

LatencyUtilsConfigInitializer latencyUtilsConfigInitializer = new LatencyUtilsConfigInitializer();
latencyUtilsConfigInitializer.initialize(null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is that null, and the same in the test below.

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

assertEquals(System.getProperties().getProperty(PROPERTY_KEY),"false");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not correct order, "false" - is expected value, and should be before actual System.getProperties().getProperty(PROPERTY_KEY)

System.getProperties().remove(PROPERTY_KEY);
String value = "RandomValue";
System.getProperties().setProperty(PROPERTY_KEY, value);
assertEquals( System.getProperties().getProperty(PROPERTY_KEY), value );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same as above: value - is expected value and should be before actual.

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

assertEquals( System.getProperties().getProperty(PROPERTY_KEY), value );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same as above.

Copy link
Contributor

@ilkinabdullayev ilkinabdullayev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi guys,
I just made a quick review.

}

@Test
public void ShouldNotSetSystemPropertyWhenPropertyIsSetFromBefore() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method name is starting with an upper character. Please change to a small one. shouldNotSetSystemPropertyWhenPropertyIsSetFromBefore

private final String PROPERTY_KEY = "LatencyUtils.useActualTime";

@Test
public void ShouldSetSystemPropertyWhenPropertyNotSet() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method name is starting with an upper character. Please change to a small one. shouldNotSetSystemPropertyWhenPropertyIsSetFromBefore

Copy link
Contributor

@JirkaAichler JirkaAichler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor detail ...

public class LatencyUtilsConfigInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
private static final String PROPERTY_KEY = "LatencyUtils.useActualTime";
@Override
public void initialize(@NonNull ConfigurableApplicationContext applicationContext) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change it from @NonNull to @Nonnull ... it will get rid of the warning

JirkaAichler
JirkaAichler previously approved these changes Jul 4, 2019
Copy link
Contributor

@JirkaAichler JirkaAichler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for a great job!

arxioly
arxioly previously approved these changes Jul 4, 2019
Copy link
Contributor

@arxioly arxioly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super! Thanks!

…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>
Signed-off-by: janda06 <david.janda@broadcom.com>
suppressed security module as there are some classes that triggered the check
and this module is soon to be decommissioned
changed test method names
moved the classes to gateway-common

Signed-off-by: janda06 <david.janda@broadcom.com>
Moved gateway-common to apiml-common

Signed-off-by: janda06 <david.janda@broadcom.com>
@ilkinabdullayev ilkinabdullayev dismissed stale reviews from arxioly and JirkaAichler via afdc01d July 8, 2019 09:50
@ilkinabdullayev ilkinabdullayev force-pushed the private/janda06/issue282HighCpu branch from 55f54e7 to afdc01d Compare July 8, 2019 09:50
@jandadav
Copy link
Contributor Author

jandadav commented Jul 8, 2019

Rebased on master, please re-review. Thank you

Copy link
Contributor

@taban03 taban03 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job David!

@arxioly arxioly merged commit 8d49ee9 into master Jul 8, 2019
@delete-merged-branch delete-merged-branch bot deleted the private/janda06/issue282HighCpu branch July 8, 2019 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants