use of com.google.common.util.concurrent.AtomicDouble in project java by wavefrontHQ.
the class DeltaCounterAccumulationHandlerImpl method reportInternal.
@Override
void reportInternal(ReportPoint point) {
if (DeltaCounter.isDelta(point.getMetric())) {
try {
validatePoint(point, validationConfig);
} catch (DeltaCounterValueException e) {
discardedCounterSupplier.get().inc();
return;
}
getReceivedCounter().inc();
double deltaValue = (double) point.getValue();
receivedPointLag.update(Clock.now() - point.getTimestamp());
HostMetricTagsPair hostMetricTagsPair = new HostMetricTagsPair(point.getHost(), point.getMetric(), point.getAnnotations());
Objects.requireNonNull(aggregatedDeltas.get(hostMetricTagsPair, key -> new AtomicDouble(0))).getAndAdd(deltaValue);
if (validItemsLogger != null && validItemsLogger.isLoggable(Level.FINEST)) {
validItemsLogger.info(serializer.apply(point));
}
} else {
reject(point, "Port is not configured to accept non-delta counter data!");
}
}
use of com.google.common.util.concurrent.AtomicDouble in project neo4j-nlp by graphaware.
the class PageRank method run.
public Map<Long, Double> run(Map<Long, Map<Long, CoOccurrenceItem>> coOccurrences, int iter, double dampFactor, double threshold) {
nodeWeights = initializeNodeWeights(coOccurrences);
Map<Long, Double> pagerank = getInitializedPageRank(nodeWeights, dampFactor);
int nNodes = pagerank.size();
boolean thresholdHit = false;
Map<Long, Double> prTemp = new HashMap<>();
for (int iteration = 0; iteration < iter && !thresholdHit; iteration++) {
// Map<Long, Double> prTemp = new HashMap<>();
// calculate main part of the PR calculation, include weights of nodes and relationships
nodeWeights.entrySet().stream().forEach(enExt -> {
Long nodeIdExt = enExt.getKey();
Double nodeWExt = enExt.getValue();
AtomicDouble internalSum = new AtomicDouble(0.0);
// AtomicDouble internalNodeWSum = new AtomicDouble(0.0);
nodeWeights.entrySet().stream().filter(enInt -> coOccurrences.containsKey(enInt.getKey()) && coOccurrences.get(enInt.getKey()).containsKey(nodeIdExt)).forEach(enInt -> {
Long nodeIdInt = enInt.getKey();
Double nodeWInt = enInt.getValue();
// internalNodeWSum.addAndGet(nodeWInt);
Map<Long, CoOccurrenceItem> coOccurrentTags = coOccurrences.get(nodeIdInt);
// Can be optimized
double totalWeightSum = coOccurrentTags.values().stream().map(item -> item.getCount()).mapToDouble(Number::doubleValue).sum();
// internalSum.addAndGet(1.0d/coOccurrentTags.size() * pagerank.get(nodeIdInt)); // no relationship weights
// with relationship weights
internalSum.addAndGet(((1.0d * coOccurrentTags.get(nodeIdExt).getCount()) / totalWeightSum) * pagerank.get(nodeIdInt));
// internalSum.addAndGet(((1.0d * coOccurrentTags.get(nodeIdExt).getCount()) / totalWeightSum) * pagerank.get(nodeIdInt) * nodeWInt); // with relationship & node weights
});
// PR is a probability (PR values add up to 1)
double newPrValue = (1 - dampFactor) / nNodes + dampFactor * internalSum.get();
// PageRank with node weights
// long nInt = nodeWeights.entrySet().stream()
// .filter(enInt -> coOccurrences.containsKey(enInt.getKey()) && coOccurrences.get(enInt.getKey()).containsKey(nodeIdExt))
// .count();
// double newPrValue = (1 - dampFactor) / nNodes + dampFactor * internalSum.get() * (nInt / internalNodeWSum.get()); // PR is a probability (PR values add up to 1); WITH node weights
prTemp.put(nodeIdExt, newPrValue);
});
thresholdHit = checkThreshold(pagerank, prTemp, threshold);
if (thresholdHit) {
LOG.info("Threshold hit after " + (iteration + 1) + " iterations");
}
// finish page rank computation and store it to the final list
nodeWeights.keySet().stream().forEach((nodeIdExt) -> {
pagerank.put(nodeIdExt, prTemp.get(nodeIdExt));
});
}
// iterations
return pagerank;
}
use of com.google.common.util.concurrent.AtomicDouble in project Singularity by HubSpot.
the class SingularityUsagePoller method runActionOnPoll.
@Override
public void runActionOnPoll() {
Map<String, RequestUtilization> utilizationPerRequestId = new ConcurrentHashMap<>();
Map<String, RequestUtilization> previousUtilizations = usageManager.getRequestUtilizations(false);
final long now = System.currentTimeMillis();
AtomicLong totalMemBytesUsed = new AtomicLong(0);
AtomicLong totalMemBytesAvailable = new AtomicLong(0);
AtomicDouble totalCpuUsed = new AtomicDouble(0.00);
AtomicDouble totalCpuAvailable = new AtomicDouble(0.00);
AtomicLong totalDiskBytesUsed = new AtomicLong(0);
AtomicLong totalDiskBytesAvailable = new AtomicLong(0);
Map<SingularityAgentUsage, List<TaskIdWithUsage>> overLoadedHosts = new ConcurrentHashMap<>();
List<CompletableFuture<Void>> usageFutures = new ArrayList<>();
usageHelper.getAgentsToTrackUsageFor().forEach(agent -> {
usageFutures.add(CompletableFuture.runAsync(() -> {
usageHelper.collectAgentUsage(agent, now, utilizationPerRequestId, previousUtilizations, overLoadedHosts, totalMemBytesUsed, totalMemBytesAvailable, totalCpuUsed, totalCpuAvailable, totalDiskBytesUsed, totalDiskBytesAvailable, false);
}, usageExecutor));
});
CompletableFutures.allOf(usageFutures).join();
usageManager.saveClusterUtilization(getClusterUtilization(utilizationPerRequestId, totalMemBytesUsed.get(), totalMemBytesAvailable.get(), totalCpuUsed.get(), totalCpuAvailable.get(), totalDiskBytesUsed.get(), totalDiskBytesAvailable.get(), now));
utilizationPerRequestId.values().forEach(usageManager::saveRequestUtilization);
if (configuration.isShuffleTasksForOverloadedAgents() && !disasterManager.isDisabled(SingularityAction.TASK_SHUFFLE)) {
taskShuffler.shuffle(overLoadedHosts);
}
}
Aggregations