49c5056968
In the common.streaming_algorithms module, we add the base for the streaming algorithms that take values from the input stream and compute certain quantities needed for the benchmark results processing. These algorithms should use constant memory and be able to scale. Two streaming algorithms for computing mean and standard deviation are implemented. There is also a new "max_outliers" SLA that checks for the maximum number of outliers based on the mean and standard deviation of the durations, computed using these new streaming algorithms. By default, the outliers are detected only when the total number of iterations reaches 10 (can be configured). Example: 3.1 4.2 3.6 4.5 2.8 3.3 4.1 3.8 4.3 2.9 10.2 11.2 3.4 has 2 outliers (10.2 and 11.2), so: {"outliers": {"max": 2}} -> PASS {"outliers": {"max": 1}} -> FAIL Bonus: * Add gate testing of different SLAs with the Dummy scenario * Add samples for all SLAs * Fix detailed message for max_avg_duration Change-Id: I7c4f77c418c7b61f71b43216110fa4c7aaccc2f5
69 lines
2.5 KiB
Python
69 lines
2.5 KiB
Python
# Copyright 2015: Mirantis Inc.
|
|
# All Rights Reserved.
|
|
#
|
|
# Licensed 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.
|
|
|
|
import math
|
|
|
|
from rally.common import streaming_algorithms as algo
|
|
from rally import exceptions
|
|
from tests.unit import test
|
|
|
|
|
|
class MeanStreamingComputationTestCase(test.TestCase):
|
|
|
|
def test_empty_stream(self):
|
|
mean_computation = algo.MeanStreamingComputation()
|
|
self.assertRaises(exceptions.RallyException, mean_computation.result)
|
|
|
|
def test_one_value(self):
|
|
mean_computation = algo.MeanStreamingComputation()
|
|
mean_computation.add(10.0)
|
|
self.assertEqual(10.0, mean_computation.result())
|
|
|
|
def test_stream(self):
|
|
stream = range(10)
|
|
mean_computation = algo.MeanStreamingComputation()
|
|
for value in stream:
|
|
mean_computation.add(value)
|
|
excepted_mean = float(sum(stream)) / len(stream)
|
|
self.assertEqual(excepted_mean, mean_computation.result())
|
|
|
|
|
|
class StdDevStreamingComputationTestCase(test.TestCase):
|
|
|
|
def test_empty_stream(self):
|
|
std_computation = algo.StdDevStreamingComputation()
|
|
self.assertRaises(exceptions.RallyException, std_computation.result)
|
|
|
|
def test_one_value(self):
|
|
std_computation = algo.StdDevStreamingComputation()
|
|
std_computation.add(10.0)
|
|
self.assertRaises(exceptions.RallyException, std_computation.result)
|
|
|
|
def test_two_values(self):
|
|
std_computation = algo.StdDevStreamingComputation()
|
|
std_computation.add(10.0)
|
|
std_computation.add(10.0)
|
|
self.assertEqual(0.0, std_computation.result())
|
|
|
|
def test_stream(self):
|
|
stream = range(10)
|
|
std_computation = algo.StdDevStreamingComputation()
|
|
for value in stream:
|
|
std_computation.add(value)
|
|
mean = float(sum(stream)) / len(stream)
|
|
excepted_std = math.sqrt(sum((x - mean) ** 2 for x in stream) /
|
|
(len(stream) - 1))
|
|
self.assertEqual(excepted_std, std_computation.result())
|