Search in sources :

Example 26 with AtomicDouble

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!");
    }
}
Also used : AtomicDouble(com.google.common.util.concurrent.AtomicDouble) HostMetricTagsPair(com.wavefront.common.HostMetricTagsPair) DeltaCounterValueException(com.wavefront.data.DeltaCounterValueException)

Example 27 with AtomicDouble

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;
}
Also used : Relationship(org.neo4j.graphdb.Relationship) Log(org.neo4j.logging.Log) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Result(org.neo4j.graphdb.Result) Iterator(java.util.Iterator) LoggerFactory(com.graphaware.common.log.LoggerFactory) AtomicDouble(com.google.common.util.concurrent.AtomicDouble) TypeConverter.getDoubleValue(com.graphaware.nlp.util.TypeConverter.getDoubleValue) Map(java.util.Map) HashMap(java.util.HashMap) Transaction(org.neo4j.graphdb.Transaction) AtomicDouble(com.google.common.util.concurrent.AtomicDouble) HashMap(java.util.HashMap) AtomicDouble(com.google.common.util.concurrent.AtomicDouble)

Example 28 with AtomicDouble

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);
    }
}
Also used : SingularityAgentUsage(com.hubspot.singularity.SingularityAgentUsage) AtomicDouble(com.google.common.util.concurrent.AtomicDouble) RequestUtilization(com.hubspot.singularity.RequestUtilization) ArrayList(java.util.ArrayList) AtomicLong(java.util.concurrent.atomic.AtomicLong) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) List(java.util.List) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

AtomicDouble (com.google.common.util.concurrent.AtomicDouble)28 HashMap (java.util.HashMap)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 AtomicLong (java.util.concurrent.atomic.AtomicLong)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ImmutableList (com.google.common.collect.ImmutableList)2 LoggerFactory (com.graphaware.common.log.LoggerFactory)2 Resources (com.hubspot.mesos.Resources)2 MesosTaskMonitorObject (com.hubspot.mesos.json.MesosTaskMonitorObject)2 InvalidSingularityTaskIdException (com.hubspot.singularity.InvalidSingularityTaskIdException)2 SingularityAgentUsage (com.hubspot.singularity.SingularityAgentUsage)2 SingularityTask (com.hubspot.singularity.SingularityTask)2 SingularityTaskCurrentUsage (com.hubspot.singularity.SingularityTaskCurrentUsage)2 SingularityTaskHistoryUpdate (com.hubspot.singularity.SingularityTaskHistoryUpdate)2 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)2 SingularityTaskUsage (com.hubspot.singularity.SingularityTaskUsage)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2