Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ buildscript {
classpath "gradle.plugin.org.nosphere.apache:creadur-rat-gradle:0.3.1"
classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.6.2'
classpath "com.diffplug.spotless:spotless-plugin-gradle:3.10.0"
classpath "me.champeau.gradle:jmh-gradle-plugin:0.4.7"
classpath "me.champeau.gradle:jmh-gradle-plugin:0.4.8"
classpath 'com.github.ben-manes:gradle-versions-plugin:0.17.0'
classpath 'io.spring.gradle:dependency-management-plugin:1.0.6.RELEASE'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,9 @@

import java.util.concurrent.atomic.AtomicLong;

import org.apache.geode.Statistics;
import org.apache.geode.StatisticsType;
import org.apache.geode.distributed.internal.DistributionConfig;
import org.apache.geode.internal.statistics.LocalStatisticsImpl;
import org.apache.geode.internal.statistics.StatisticsManager;
import org.apache.geode.internal.statistics.StatisticsTypeImpl;
import org.apache.geode.internal.stats50.Atomic50StatisticsImpl;

public class Atomics {
private Atomics() {}

/**
* Whether per-thread stats are used. Striping is disabled for the IBM JVM due to bug 38226
*/
private static final boolean STRIPED_STATS_DISABLED =
Boolean.getBoolean(DistributionConfig.GEMFIRE_PREFIX + "STRIPED_STATS_DISABLED")
|| "IBM Corporation".equals(System.getProperty("java.vm.vendor", "unknown"));


public static Statistics createAtomicStatistics(StatisticsType type, String textId, long nId,
long uId, StatisticsManager mgr) {
Statistics result = null;
if (((StatisticsTypeImpl) type).getDoubleStatCount() == 0 && !STRIPED_STATS_DISABLED) {
result = new Atomic50StatisticsImpl(type, textId, nId, uId, mgr);
} else {
result = new LocalStatisticsImpl(type, textId, nId, uId, true, 0, mgr);
}
return result;
}

/**
* Use it only when threads are doing incremental updates. If updates are random then this method
* may not be optimal.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ public class LocalStatisticsImpl extends StatisticsImpl {
*/
private final transient Object[] doubleLocks;

/** The StatisticsFactory that created this instance */
private final StatisticsManager statisticsManager;

/////////////////////// Constructors ///////////////////////

/**
Expand All @@ -72,10 +69,7 @@ public class LocalStatisticsImpl extends StatisticsImpl {
*/
public LocalStatisticsImpl(StatisticsType type, String textId, long numericId, long uniqueId,
boolean atomicIncrements, int osStatFlags, StatisticsManager statisticsManager) {
super(type, textId, numericId, uniqueId,
osStatFlags);

this.statisticsManager = statisticsManager;
super(type, textId, numericId, uniqueId, osStatFlags, statisticsManager);

StatisticsTypeImpl realType = (StatisticsTypeImpl) type;
int intCount = realType.getIntStatCount();
Expand Down Expand Up @@ -153,14 +147,6 @@ public boolean isAtomic() {
return intLocks != null || longLocks != null || doubleLocks != null;
}

@Override
public void close() {
super.close();
if (this.statisticsManager != null) {
statisticsManager.destroyStatistics(this);
}
}

//////////////////////// store() Methods ///////////////////////

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.apache.geode.Statistics;
import org.apache.geode.StatisticsType;
import org.apache.geode.annotations.internal.MutableForTesting;
import org.apache.geode.internal.concurrent.Atomics;
import org.apache.geode.internal.logging.LogService;
import org.apache.geode.internal.util.concurrent.CopyOnWriteHashMap;

Expand Down Expand Up @@ -71,6 +70,9 @@ public abstract class StatisticsImpl implements Statistics {
/** Uniquely identifies this instance */
private long uniqueId;

/** The StatisticsFactory that created this instance */
private final StatisticsManager statisticsManager;

/**
* Suppliers of int sample values to be sampled every sample-interval
*/
Expand Down Expand Up @@ -99,7 +101,7 @@ public abstract class StatisticsImpl implements Statistics {
*/
public static Statistics createAtomicNoOS(StatisticsType type, String textId, long numericId,
long uniqueId, StatisticsManager mgr) {
return Atomics.createAtomicStatistics(type, textId, numericId, uniqueId, mgr);
return new StripedStatisticsImpl(type, textId, numericId, uniqueId, mgr);
}

/**
Expand All @@ -113,12 +115,13 @@ public static Statistics createAtomicNoOS(StatisticsType type, String textId, lo
* only
*/
public StatisticsImpl(StatisticsType type, String textId, long numericId, long uniqueId,
int osStatFlags) {
int osStatFlags, StatisticsManager statisticsManager) {
this.type = (StatisticsTypeImpl) type;
this.textId = textId;
this.numericId = numericId;
this.uniqueId = uniqueId;
this.osStatFlags = osStatFlags;
this.statisticsManager = statisticsManager;
closed = false;
}

Expand All @@ -144,6 +147,9 @@ public StatisticDescriptor nameToDescriptor(String name) {

@Override
public void close() {
if (this.statisticsManager != null) {
statisticsManager.destroyStatistics(this);
}
this.closed = true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
* agreements. See the NOTICE file distributed with this work for additional information regarding
* copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License. You may obtain a
* copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

package org.apache.geode.internal.statistics;

import java.util.concurrent.atomic.DoubleAdder;
import java.util.concurrent.atomic.LongAdder;
import java.util.stream.Stream;

import org.apache.geode.StatisticsType;

/**
* Stripes statistic counters across threads to reduce contention using {@link LongAdder} and
* {@link DoubleAdder}.
*/
public class StripedStatisticsImpl extends StatisticsImpl {

private final LongAdder[] intAdders;
private final LongAdder[] longAdders;
private final DoubleAdder[] doubleAdders;

public StripedStatisticsImpl(StatisticsType type, String textId, long numericId,
long uniqueId, StatisticsManager statisticsManager) {
super(type, textId, numericId, uniqueId, 0, statisticsManager);

StatisticsTypeImpl realType = (StatisticsTypeImpl) type;

this.intAdders =
Stream.generate(LongAdder::new).limit(realType.getIntStatCount()).toArray(LongAdder[]::new);
this.longAdders =
Stream.generate(LongAdder::new).limit(realType.getLongStatCount())
.toArray(LongAdder[]::new);
this.doubleAdders =
Stream.generate(DoubleAdder::new).limit(realType.getDoubleStatCount())
.toArray(DoubleAdder[]::new);
}

@Override
public boolean isAtomic() {
return true;
}

@Override
protected void _setInt(int offset, int value) {
intAdders[offset].reset();
intAdders[offset].add(value);
}

@Override
protected void _setLong(int offset, long value) {
longAdders[offset].reset();
longAdders[offset].add(value);
}

@Override
protected void _setDouble(int offset, double value) {
doubleAdders[offset].reset();
doubleAdders[offset].add(value);
}

@Override
protected int _getInt(int offset) {
return intAdders[offset].intValue();
}

@Override
protected long _getLong(int offset) {
return longAdders[offset].sum();
}

@Override
protected double _getDouble(int offset) {
return doubleAdders[offset].sum();
}

@Override
protected void _incInt(int offset, int delta) {
intAdders[offset].add(delta);
}

@Override
protected void _incLong(int offset, long delta) {
longAdders[offset].add(delta);
}

@Override
protected void _incDouble(int offset, double delta) {
doubleAdders[offset].add(delta);
}
}
Loading