Пример #1
0
        private void IncorporateReading(TaskAttemptId attemptID, float newProgress, long
                                        newTime)
        {
            //TODO: Refactor this method, it seems more complicated than necessary.
            AtomicReference <ExponentiallySmoothedTaskRuntimeEstimator.EstimateVector> vectorRef
                = estimates[attemptID];

            if (vectorRef == null)
            {
                estimates.PutIfAbsent(attemptID, new AtomicReference <ExponentiallySmoothedTaskRuntimeEstimator.EstimateVector
                                                                      >(null));
                IncorporateReading(attemptID, newProgress, newTime);
                return;
            }
            ExponentiallySmoothedTaskRuntimeEstimator.EstimateVector oldVector = vectorRef.Get
                                                                                     ();
            if (oldVector == null)
            {
                if (vectorRef.CompareAndSet(null, new ExponentiallySmoothedTaskRuntimeEstimator.EstimateVector
                                                (this, -1.0, 0.0F, long.MinValue)))
                {
                    return;
                }
                IncorporateReading(attemptID, newProgress, newTime);
                return;
            }
            while (!vectorRef.CompareAndSet(oldVector, oldVector.Incorporate(newProgress, newTime
                                                                             )))
            {
                oldVector = vectorRef.Get();
            }
        }
Пример #2
0
        public override long EstimatedRuntime(TaskAttemptId id)
        {
            long startTime = startTimes[id];

            if (startTime == null)
            {
                return(-1L);
            }
            ExponentiallySmoothedTaskRuntimeEstimator.EstimateVector vector = GetEstimateVector
                                                                                  (id);
            if (vector == null)
            {
                return(-1L);
            }
            long   sunkTime = vector.atTime - startTime;
            double value    = vector.value;
            float  progress = vector.basedOnProgress;

            if (value == 0)
            {
                return(-1L);
            }
            double rate = smoothedValue == ExponentiallySmoothedTaskRuntimeEstimator.SmoothedValue
                          .Rate ? value : 1.0 / value;

            if (rate == 0.0)
            {
                return(-1L);
            }
            double remainingTime = (1.0 - progress) / rate;

            return(sunkTime + (long)remainingTime);
        }