cassandra-pr mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jolynch <...@git.apache.org>
Subject [GitHub] cassandra pull request #283: CASSANDRA-14459: DynamicEndpointSnitch should n...
Date Fri, 30 Nov 2018 18:33:36 GMT
Github user jolynch commented on a diff in the pull request:

    https://github.com/apache/cassandra/pull/283#discussion_r237958792
  
    --- Diff: src/java/org/apache/cassandra/locator/dynamicsnitch/DynamicEndpointSnitchEMA.java
---
    @@ -0,0 +1,133 @@
    +/*
    + * 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.cassandra.locator.dynamicsnitch;
    +
    +import java.util.Collections;
    +import java.util.HashMap;
    +import java.util.Map;
    +import java.util.Optional;
    +
    +import com.google.common.annotations.VisibleForTesting;
    +
    +import org.apache.cassandra.locator.DynamicEndpointSnitch;
    +import org.apache.cassandra.locator.IEndpointSnitch;
    +import org.apache.cassandra.locator.InetAddressAndPort;
    +import org.apache.cassandra.metrics.ExponentialMovingAverage;
    +
    +
    +/**
    + * A dynamic snitching implementation that uses Exponentially Moving Averages as a low
pass filter to prefer
    + * or de-prefer hosts
    + *
    + * This implementation generates a few orders of magnitude less garbage than histograms
and is close to 10x faster,
    + * but as it is not a Median LPF (it is an Average LPF), it is more vulnerable to noise.
This may be acceptable but
    + * given the significant change in behavior this is not the default in 4.0
    + */
    +public class DynamicEndpointSnitchEMA extends DynamicEndpointSnitch
    +{
    +    // A ~10 sample EMA heavily weighted to the past values to minimize noise
    +    private static final double EMA_ALPHA = 0.10;
    +
    +    protected static class EMASnitchMeasurement implements ISnitchMeasurement
    +    {
    +        public final ExponentialMovingAverage avg;
    +
    +        EMASnitchMeasurement(double initial)
    +        {
    +            avg = new ExponentialMovingAverage(EMA_ALPHA, initial);
    +        }
    +
    +        @Override
    +        public void sample(long value)
    +        {
    +            avg.update(value);
    +        }
    +
    +        @Override
    +        public double measure()
    +        {
    +            return avg.getAvg();
    +        }
    +
    +        @Override
    +        public Iterable<Double> measurements()
    +        {
    +            return Collections.singletonList(avg.getAvg());
    +        }
    +    }
    +
    +    // Called via reflection
    +    public DynamicEndpointSnitchEMA(IEndpointSnitch snitch)
    +    {
    +        this(snitch, "ema");
    +    }
    +
    +    public DynamicEndpointSnitchEMA(IEndpointSnitch snitch, String instance)
    +    {
    +        super(snitch, instance);
    +    }
    +
    +    @Override
    +    protected ISnitchMeasurement measurementImpl(long initialValue)
    +    {
    +        return new EMASnitchMeasurement(initialValue);
    +    }
    +
    +    /**
    +     * Unlike the Histogram implementation, calling this measure method is reasonably
cheap (doesn't require a
    +     * Snapshot or anything) so we can skip a round of iterations and just normalize
the scores slightly
    +     * differently
    +     */
    +    @Override
    +    public Map<InetAddressAndPort, Double> calculateScores()
    +    {
    +        // We're going to weight the latency for each host against the worst one we see,
to
    +        // arrive at sort of a 'badness percentage' for them. First, find the worst for
each:
    +        HashMap<InetAddressAndPort, Double> newScores = new HashMap<>(samples.size());
    +        Optional<Double> maxObservedAvgLatency = samples.values().stream()
    --- End diff --
    
    I went ahead and removed the EMA entirely, let's follow up on that in another change.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Mime
View raw message