示例#1
0
 def actuate(self, input):
     self._logger.debug('input = %f' % input)
     self.cluster.stateLock.acquire()
     try:            
         currPerf = getPerformance(self.cluster.servers[Server.ON])
         sat = input / currPerf
                 
         if round(sat - self.controller._setPoint, 5) != 0:
             newPerf = input / self.controller._setPoint           
             newPerf = min(getMaxPerformance(self.cluster.servers[Server.ON]), newPerf)
             self._logger.debug('allocation = %f' % newPerf)
             
             output = None
             try:                    
                 output = self.balancePerformance(newPerf, self.cluster.servers[Server.ON])
                 #output = self.balancePerformanceNaive(newPerf, self.cluster.servers[Server.ON])                                    
             except Exception:
                 self._logger.exception('balancePerformance has failed with args: (%s, %s)' % (newPerf, self.cluster.servers[Server.ON]))
             else:
                 try:
                     self.applyPerfRegulation(output)
                 except Exception:
                     self._logger.exception('applyPerfRegulation has failed! Input was: %s' % output)
     finally:
         self.cluster.stateLock.release()
示例#2
0
    def actuate(self, input):
        self._logger.debug('input = %f' % input)
        self.cluster.stateLock.acquire()
        try:
            currPerf = getPerformance(self.cluster.servers[Server.ON])
            sat = input / currPerf

            if round(sat - self.controller._setPoint, 5) != 0:
                newPerf = input / self.controller._setPoint
                newPerf = min(
                    getMaxPerformance(self.cluster.servers[Server.ON]),
                    newPerf)
                self._logger.debug('allocation = %f' % newPerf)

                output = None
                try:
                    output = self.balancePerformance(
                        newPerf, self.cluster.servers[Server.ON])
                    #output = self.balancePerformanceNaive(newPerf, self.cluster.servers[Server.ON])
                except Exception:
                    self._logger.exception(
                        'balancePerformance has failed with args: (%s, %s)' %
                        (newPerf, self.cluster.servers[Server.ON]))
                else:
                    try:
                        self.applyPerfRegulation(output)
                    except Exception:
                        self._logger.exception(
                            'applyPerfRegulation has failed! Input was: %s' %
                            output)
        finally:
            self.cluster.stateLock.release()
示例#3
0
def main():
    filename = '../tmp/config.txt'
    
    c = ConfigReader()
    c.parse(filename)
    cluster = c.readCluster()

    maxPerf = getMaxPerformance(cluster.availableServers)    
    
    outline = readOutlineFile('../tmp/outline.txt')
    trace = generateTrace(outline, maxPerf, 20)
        
    if Gnuplot is not None:
        data = Data(trace, with_='l')
        g = Gnuplot()
        g('set ytics 0, 100')
        g('set xtics 0, 20')
        g('set grid')
        g.plot(data)
        raw_input()
    
    file = open('../tmp/trace_gen.txt','w')
    for value in trace:
        file.write('%f\n' % value)
    file.close()
示例#4
0
 def testRamp(self):
     '''
     Will build a ramp to test configurations
     All configurations must be able to cope with the load.
     '''
     trace = range(0, int(getMaxPerformance(self.configurator._efficientServerList)))
     reversed = trace[:]
     reversed.reverse()
     trace.extend(reversed)
     
     config = self.configurator._efficientServerList
     for load in trace:
         config = self.configurator.getConfiguration(load, config, self.configurator._gamma)
         perf = getMaxPerformance(config)
         #print 'load =',load,'perf =',perf
         if perf < load:
             self.fail("Configuration can't cope with load")
示例#5
0
def main():    
    c = ConfigReader()
    c.parse('../../tmp/config.txt')
    cluster = c.readCluster()
    
    configurator = ConfiguratorBuilder().build(c, cluster, None)
    
    servers = cluster.availableServers * 100000
    maxPerf = getMaxPerformance(servers)
    cProfile.runctx('configurator.getConfiguration(maxPerf, servers,  1.0)',globals=globals(),locals=locals())
示例#6
0
def scale(data, servers, maxUtil=0.90, minPerf=0):
    '''
    Scales a trace based on the maximum load for the cluster
    '''    
    trace_min, trace_max = min(data), max(data)
    maxPerf = getMaxPerformance(servers) * 0.90
    
    #scales the trace file
    for i in range(len(data)):
        data[i] = (data[i] - trace_min) / (trace_max - trace_min) * (maxPerf - minPerf) + minPerf
示例#7
0
def scale(data, servers, maxUtil=0.90, minPerf=0):
    '''
    Scales a trace based on the maximum load for the cluster
    '''
    trace_min, trace_max = min(data), max(data)
    maxPerf = getMaxPerformance(servers) * 0.90

    #scales the trace file
    for i in range(len(data)):
        data[i] = (data[i] - trace_min) / (trace_max - trace_min) * (
            maxPerf - minPerf) + minPerf
示例#8
0
def main():
    c = ConfigReader()
    c.parse('../../tmp/config.txt')
    cluster = c.readCluster()

    configurator = ConfiguratorBuilder().build(c, cluster, None)

    servers = cluster.availableServers * 100000
    maxPerf = getMaxPerformance(servers)
    cProfile.runctx('configurator.getConfiguration(maxPerf, servers,  1.0)',
                    globals=globals(),
                    locals=locals())
示例#9
0
 def balancePerformanceNaive(self, load, servers):
     '''
     Will balance the performance according to each server max capacity, granting
     proportional throughput among servers.
     '''       
     perfList = []
     maxLoad = getMaxPerformance(servers)
     for server in servers:
         serverPerf = ServerPerf(server)
         serverPerf.perf = load * (server.energyModel.peakPerf[-1] / maxLoad)
         perfList.append(serverPerf)
         
     return perfList
示例#10
0
    def balancePerformanceNaive(self, load, servers):
        '''
        Will balance the performance according to each server max capacity, granting
        proportional throughput among servers.
        '''
        perfList = []
        maxLoad = getMaxPerformance(servers)
        for server in servers:
            serverPerf = ServerPerf(server)
            serverPerf.perf = load * (server.energyModel.peakPerf[-1] /
                                      maxLoad)
            perfList.append(serverPerf)

        return perfList
示例#11
0
def main():
    c = ConfigReader()
    c.parse('../../tmp/config.txt')
    cluster = c.readCluster()

    configurator = ConfiguratorBuilder().build(c, cluster, None)

    tests = 1000
    maxMultiplier = 200
    step = 20

    for mult in xrange(1, maxMultiplier, step):
        servers = cluster.availableServers * mult
        maxPerf = getMaxPerformance(servers)

        ti = time.time()
        for i in xrange(tests):
            configurator.getConfiguration(maxPerf, servers, 1.0)
        tf = time.time()

        print len(servers), (tf - ti) * 1000.0 / tests
示例#12
0
def main():    
    c = ConfigReader()
    c.parse('../../tmp/config.txt')
    cluster = c.readCluster()
    
    configurator = ConfiguratorBuilder().build(c, cluster, None)
    
    tests = 1000
    maxMultiplier = 200
    step = 20
        
    for mult in xrange(1,maxMultiplier,step):
        servers = cluster.availableServers * mult
        maxPerf = getMaxPerformance(servers)
           
        ti = time.time()
        for i in xrange(tests):    
            configurator.getConfiguration(maxPerf, servers,  1.0)            
        tf = time.time()
        
        print len(servers), (tf-ti) * 1000.0 / tests 
示例#13
0
def actuate(self, qos):
    assert self._policyServers is not None
                           
    self._policyMutex.acquire()
    
    newPerf = self.perfList[self.perfIndex % len(self.perfList)] * getMaxPerformance(self._policyServers)
    self.perfIndex += 1
     
    try:
        output = None
        try:
            self._logger.debug('balancing: ' + str(newPerf))                
            output = self.balancePerformanceNaive(newPerf, self._policyServers)
        except Exception:
            self._logger.exception('balancePerformance has failed with args: (%s, %s)' % (newPerf, self._policyServers))
        else:
            try:
                self.applyPerfRegulation(output)
            except Exception:
                self._logger.exception('applyPerfRegulation has failed! Input was: %s' % output)
    finally:   
        self._policyMutex.release()
示例#14
0
def main():
    traceFilename = '../../tmp/wc98_1.txt'
    configFilename = '../../tmp/dynGamma.txt'
    cReader = ConfigReader()
    cReader.parse(configFilename)
    cluster = cReader.readCluster()
    predictor = cReader.readPredictor()
    lb = cReader.readLoadBalancer(cluster)
    cluster.loadBalancer = lb

    config = cluster._availableServers[:]
    bestConfig = config[:]
    predConfig = config[:]
    reactiveConfig = config[:]

    bestConfigurator = cReader.readConfigurator(cluster, DummyFilter())
    bestConfigurator.setEfficientServerList(cluster._availableServers)
    bestConfigurator.gamma = 1.0  #do not change!!

    predConfigurator = cReader.readConfigurator(cluster, predictor)
    predConfigurator.setEfficientServerList(cluster._availableServers)
    predConfigurator._gamma = 1.0

    reactiveConfigurator = cReader.readConfigurator(cluster, DummyFilter())
    reactiveConfigurator.setEfficientServerList(cluster._availableServers)
    #reactiveConfigurator._gamma = 0.55

    step = predConfigurator.windowSize

    #reads the trace file
    data = file2data(1, traceFilename)[0]
    scale(data, cluster.availableServers)

    predCounter, reactiveCounter, bestCounter = 0, 0, 0  #configuration counter
    pred_upCounter, pred_downCounter = 0, 0
    best_upCounter, best_downCounter = 0, 0
    reactive_upCounter, reactive_downCounter = 0, 0
    bestPerf = getMaxPerformance(bestConfig)
    reactivePerf = getMaxPerformance(bestConfig)
    predPerf = getMaxPerformance(bestConfig)

    avgs = []
    reactivePerfs = []
    predPerfs = []
    bestPerfs = []
    gammas = []
    for i in range(len(data) / step):
        avgData = 0.0
        for j in range(step):
            avgData += data[i * step + j]
        avgData /= step
        avgs.append(avgData)

        reactivePerfs.append(reactivePerf)
        predPerfs.append(predPerf)

        optimumConfig = None
        '''
        Will use the efficient list to create the optimumConfig
        '''
        optimumConfig = [bestConfigurator._efficientServerList[0]]
        k = 1
        while getMaxPerformance(optimumConfig) < avgData:
            optimumConfig.append(bestConfigurator._efficientServerList[k])
            k += 1
        '''
        Calculates the appropriate configuration, 'knowing' that avgData is true
        '''
        if i > 0:  #calculates false alarms
            tmp = bestConfigurator.getConfiguration(avgData, bestConfig,
                                                    bestConfigurator._gamma)
            if tmp != bestConfig:
                bestCounter += 1
                bestConfig = tmp
                bestPerf = getMaxPerformance(bestConfig)
            bestPerfs.append(bestPerf)
            '''
            Compares the chosen configuration with a least powerful one
            '''
            if avgData > bestPerf:
                best_downCounter += 1
            elif getMaxPerformance(bestConfig) > getMaxPerformance(
                    optimumConfig):
                best_upCounter += 1

            if avgData > reactivePerf:
                reactive_downCounter += 1
            elif getMaxPerformance(reactiveConfig) > getMaxPerformance(
                    optimumConfig):
                reactive_upCounter += 1

            if avgData > predPerf:
                pred_downCounter += 1
            elif getMaxPerformance(predConfig) > getMaxPerformance(
                    optimumConfig):
                pred_upCounter += 1

            elif len(bestConfig) < len(predConfig):
                pred_upCounter += 1

        prediction = predictor.apply(avgData)
        #actuation = prediction
        actuation = max(prediction, avgData)

        tmp = predConfigurator.getConfiguration(actuation, predConfig,
                                                predConfigurator._gamma)
        if set(tmp) != set(predConfig):
            predCounter += 1
            predConfig = tmp
            predPerf = getMaxPerformance(predConfig)

        if reactiveConfigurator.dynGamma:
            idealConfig = bestConfigurator.getConfiguration(
                avgData, reactiveConfig, reactiveConfigurator.MAX_GAMMA)
            idealPerf = round(getMaxPerformance(idealConfig), 5)
            currPerf = round(getMaxPerformance(reactiveConfig), 5)

            reactiveConfigurator._gamma = reactiveConfigurator.adjustGamma(
                currPerf - idealPerf)
            gammas.append(reactiveConfigurator._gamma)

        tmp = reactiveConfigurator.getConfiguration(
            avgData, reactiveConfig, reactiveConfigurator._gamma)
        if set(tmp) != set(reactiveConfig):
            reactiveCounter += 1
            reactiveConfig = tmp
            reactivePerf = getMaxPerformance(reactiveConfig)

    print 'Best       - False alarms: up = %d, down = %d' % (best_upCounter,
                                                             best_downCounter)
    print 'Predictive - False alarms: up = %d, down = %d' % (pred_upCounter,
                                                             pred_downCounter)
    print 'Reactive   - False alarms: up = %d, down = %d' % (
        reactive_upCounter, reactive_downCounter)
    print 'Best Configs = %d, Predictive Configs = %d, Reactive Configs = %d' %\
          (bestCounter, predCounter, reactiveCounter)

    g = Gnuplot(debug=0)
    g('reset')
    #g('set size 0.65,0.65')
    g('set encoding iso_8859_1')
    g('set terminal postscript eps enhanced monochrome')
    g('set output "carlos2.ps"')
    g('set key top left')
    g('set xlabel "Tempo (s)"')
    g('set xrange [0:%d]' % (len(data) / step))
    spacing = 15
    tics = ','.join([
        '"%d" %d' % (x * step * spacing, x * spacing)
        for x in range(1,
                       len(data) / (step * spacing) + 1)
    ])
    g('set xtics (%s)' % tics)
    g('set ylabel "Requisições"'.encode('iso_8859_1'))
    g('set grid')

    #plot incoming requests avg
    with_plot = 'steps'

    #plot configurations
    pi1 = Data(avgs, with_=with_plot, title='Carga')
    pi2 = Data(reactivePerfs, with_=with_plot, title='Reativo')
    pi_gamma = Data(gammas, with_=with_plot, title='Gamma')
    #pi3 = Data(predPerfs, with_=with_plot,title='Preditivo')
    #pi4 = Data(bestPerfs, with_=with_plot,title='Perfect')
    #g.plot(pi1,pi2)
    #g.plot(pi_gamma)

    #raw_input()

    print 'Done'
示例#15
0
def main():
    traceFilename = '../../tmp/nasa_3.txt'
    configFilename = '../../tmp/probSub.txt'
    cReader = ConfigReader()
    cReader.parse(configFilename)
    cluster = cReader.readCluster()
    lb = cReader.readLoadBalancer(cluster)
    cluster.loadBalancer = lb
    
    bestConfigurator = cReader.readConfigurator(cluster, DummyFilter())
    bestConfigurator.setEfficientServerList(cluster._availableServers)
    bestConfigurator.gamma = 1.0 #do not change!!
    
    reactiveConfigurator = cReader.readConfigurator(cluster, DummyFilter())
    reactiveConfigurator.setEfficientServerList(cluster._availableServers)
    
    step = bestConfigurator.windowSize
    
    #reads the trace file
    data = file2data(1, traceFilename)[0]
    scale(data, cluster.availableServers)
    
    gamma = 0.0
    while round(gamma,5) <= MAX_GAMMA:
        config = cluster._availableServers[:]
        bestConfig = config[:]
        reactiveConfig = config[:] 
        reactiveConfigurator._gamma = gamma        
                            
        reactiveCounter, bestCounter = 0, 0 #configuration counter
        best_upCounter, best_downCounter = 0, 0
        reactive_upCounter, reactive_downCounter = 0, 0
        bestPerf = getMaxPerformance(bestConfig)
        reactivePerf = getMaxPerformance(bestConfig)
        
        subestimated = 0.0
        for i in range(len(data) / step):
            avgData = 0.0
            for j in range(step):
                avgData += data[i * step + j]
            avgData /= step
                        
            optimumConfig = None
            '''
            Will use the efficient list to create the optimumConfig
            '''
            optimumConfig = [bestConfigurator._efficientServerList[0]]
            k = 1
            while getMaxPerformance(optimumConfig) < avgData:
                optimumConfig.append(bestConfigurator._efficientServerList[k])
                k += 1        
            
            '''
            Calculates the appropriate configuration, 'knowing' that avgData is true
            '''     
            if i > 0: #calculates false alarms                           
                tmp = bestConfigurator.getConfiguration(avgData, bestConfig, bestConfigurator._gamma)
                if tmp != bestConfig:                
                    bestCounter += 1                
                    bestConfig = tmp                
                    bestPerf = getMaxPerformance(bestConfig)
                '''
                Compares the chosen configuration with a least powerful one
                '''
                if avgData > bestPerf:                
                    best_downCounter += 1
                elif getMaxPerformance(bestConfig) > getMaxPerformance(optimumConfig):
                    best_upCounter += 1
                
                if avgData > reactivePerf:                
                    reactive_downCounter += 1                    
                elif getMaxPerformance(reactiveConfig) > getMaxPerformance(optimumConfig):
                    reactive_upCounter += 1
                
                for j in range(step):
                    subestimated += max(data[i * step + j] - reactivePerf, 0)
               
            if reactiveConfigurator.dynGamma:
                idealConfig = bestConfigurator.getConfiguration(avgData, reactiveConfig, reactiveConfigurator.MAX_GAMMA)
                idealPerf = round(getMaxPerformance(idealConfig),5)
                currPerf = round(getMaxPerformance(reactiveConfig),5)
                
                reactiveConfigurator._gamma = reactiveConfigurator.adjustGamma(currPerf - idealPerf)
                
            tmp = reactiveConfigurator.getConfiguration(avgData, reactiveConfig, reactiveConfigurator._gamma)        
            if set(tmp) != set(reactiveConfig):
                reactiveCounter += 1
                reactiveConfig = tmp
                reactivePerf = getMaxPerformance(reactiveConfig)
        
        #print 'Gamma = %f' % gamma
        #print 'Best       - super = %d, sub = %d' % (best_upCounter, best_downCounter)
        #print 'Reactive   - super = %d, sub = %d' % (reactive_upCounter, reactive_downCounter)
        #print 'Best Configs = %d, Reactive Configs = %d' %\
        #     (bestCounter, reactiveCounter)
        
        print gamma, 1.0 - reactive_downCounter / (float(len(data) - step) / step), reactiveCounter
        gamma += GAMMA_INCREMENT
示例#16
0
def main():
    traceFilename = '../../tmp/nasa_3.txt'
    configFilename = '../../tmp/probSub.txt'
    cReader = ConfigReader()
    cReader.parse(configFilename)
    cluster = cReader.readCluster()
    lb = cReader.readLoadBalancer(cluster)
    cluster.loadBalancer = lb

    bestConfigurator = cReader.readConfigurator(cluster, DummyFilter())
    bestConfigurator.setEfficientServerList(cluster._availableServers)
    bestConfigurator.gamma = 1.0  #do not change!!

    reactiveConfigurator = cReader.readConfigurator(cluster, DummyFilter())
    reactiveConfigurator.setEfficientServerList(cluster._availableServers)

    step = bestConfigurator.windowSize

    #reads the trace file
    data = file2data(1, traceFilename)[0]
    scale(data, cluster.availableServers)

    gamma = 0.0
    while round(gamma, 5) <= MAX_GAMMA:
        config = cluster._availableServers[:]
        bestConfig = config[:]
        reactiveConfig = config[:]
        reactiveConfigurator._gamma = gamma

        reactiveCounter, bestCounter = 0, 0  #configuration counter
        best_upCounter, best_downCounter = 0, 0
        reactive_upCounter, reactive_downCounter = 0, 0
        bestPerf = getMaxPerformance(bestConfig)
        reactivePerf = getMaxPerformance(bestConfig)

        subestimated = 0.0
        for i in range(len(data) / step):
            avgData = 0.0
            for j in range(step):
                avgData += data[i * step + j]
            avgData /= step

            optimumConfig = None
            '''
            Will use the efficient list to create the optimumConfig
            '''
            optimumConfig = [bestConfigurator._efficientServerList[0]]
            k = 1
            while getMaxPerformance(optimumConfig) < avgData:
                optimumConfig.append(bestConfigurator._efficientServerList[k])
                k += 1
            '''
            Calculates the appropriate configuration, 'knowing' that avgData is true
            '''
            if i > 0:  #calculates false alarms
                tmp = bestConfigurator.getConfiguration(
                    avgData, bestConfig, bestConfigurator._gamma)
                if tmp != bestConfig:
                    bestCounter += 1
                    bestConfig = tmp
                    bestPerf = getMaxPerformance(bestConfig)
                '''
                Compares the chosen configuration with a least powerful one
                '''
                if avgData > bestPerf:
                    best_downCounter += 1
                elif getMaxPerformance(bestConfig) > getMaxPerformance(
                        optimumConfig):
                    best_upCounter += 1

                if avgData > reactivePerf:
                    reactive_downCounter += 1
                elif getMaxPerformance(reactiveConfig) > getMaxPerformance(
                        optimumConfig):
                    reactive_upCounter += 1

                for j in range(step):
                    subestimated += max(data[i * step + j] - reactivePerf, 0)

            if reactiveConfigurator.dynGamma:
                idealConfig = bestConfigurator.getConfiguration(
                    avgData, reactiveConfig, reactiveConfigurator.MAX_GAMMA)
                idealPerf = round(getMaxPerformance(idealConfig), 5)
                currPerf = round(getMaxPerformance(reactiveConfig), 5)

                reactiveConfigurator._gamma = reactiveConfigurator.adjustGamma(
                    currPerf - idealPerf)

            tmp = reactiveConfigurator.getConfiguration(
                avgData, reactiveConfig, reactiveConfigurator._gamma)
            if set(tmp) != set(reactiveConfig):
                reactiveCounter += 1
                reactiveConfig = tmp
                reactivePerf = getMaxPerformance(reactiveConfig)

        #print 'Gamma = %f' % gamma
        #print 'Best       - super = %d, sub = %d' % (best_upCounter, best_downCounter)
        #print 'Reactive   - super = %d, sub = %d' % (reactive_upCounter, reactive_downCounter)
        #print 'Best Configs = %d, Reactive Configs = %d' %\
        #     (bestCounter, reactiveCounter)

        print gamma, 1.0 - reactive_downCounter / (float(len(data) - step) /
                                                   step), reactiveCounter
        gamma += GAMMA_INCREMENT
示例#17
0
def main():
    traceFilename = '../../tmp/wc98_1.txt'
    configFilename = '../../tmp/dynGamma.txt'
    cReader = ConfigReader()
    cReader.parse(configFilename)
    cluster = cReader.readCluster()
    predictor = cReader.readPredictor()
    lb = cReader.readLoadBalancer(cluster)
    cluster.loadBalancer = lb
    
    config = cluster._availableServers[:]
    bestConfig = config[:]
    predConfig = config[:]
    reactiveConfig = config[:]    
    
    bestConfigurator = cReader.readConfigurator(cluster, DummyFilter())
    bestConfigurator.setEfficientServerList(cluster._availableServers)
    bestConfigurator.gamma = 1.0 #do not change!!
    
    predConfigurator = cReader.readConfigurator(cluster, predictor)
    predConfigurator.setEfficientServerList(cluster._availableServers)
    predConfigurator._gamma = 1.0
    
    reactiveConfigurator = cReader.readConfigurator(cluster, DummyFilter())
    reactiveConfigurator.setEfficientServerList(cluster._availableServers)
    #reactiveConfigurator._gamma = 0.55
    
    step = predConfigurator.windowSize
    
    #reads the trace file
    data = file2data(1, traceFilename)[0]
    scale(data, cluster.availableServers)

    predCounter, reactiveCounter, bestCounter = 0, 0, 0 #configuration counter
    pred_upCounter, pred_downCounter = 0, 0
    best_upCounter, best_downCounter = 0, 0
    reactive_upCounter, reactive_downCounter = 0, 0
    bestPerf = getMaxPerformance(bestConfig)
    reactivePerf = getMaxPerformance(bestConfig)
    predPerf = getMaxPerformance(bestConfig)
    
    avgs = []
    reactivePerfs = []
    predPerfs = []
    bestPerfs = []
    gammas = []
    for i in range(len(data) / step):
        avgData = 0.0
        for j in range(step):
            avgData += data[i * step + j]
        avgData /= step
        avgs.append(avgData)
        
        reactivePerfs.append(reactivePerf)
        predPerfs.append(predPerf)
        
        optimumConfig = None
        '''
        Will use the efficient list to create the optimumConfig
        '''
        optimumConfig = [bestConfigurator._efficientServerList[0]]
        k = 1
        while getMaxPerformance(optimumConfig) < avgData:
            optimumConfig.append(bestConfigurator._efficientServerList[k])
            k += 1           
        
        
        '''
        Calculates the appropriate configuration, 'knowing' that avgData is true
        '''     
        if i > 0: #calculates false alarms                           
            tmp = bestConfigurator.getConfiguration(avgData, bestConfig, bestConfigurator._gamma)
            if tmp != bestConfig:                
                bestCounter += 1                
                bestConfig = tmp                
                bestPerf = getMaxPerformance(bestConfig)
            bestPerfs.append(bestPerf)
            '''
            Compares the chosen configuration with a least powerful one
            '''
            if avgData > bestPerf:                
                best_downCounter += 1
            elif getMaxPerformance(bestConfig) > getMaxPerformance(optimumConfig):
                best_upCounter += 1
            
            if avgData > reactivePerf:                
                reactive_downCounter += 1
            elif getMaxPerformance(reactiveConfig) > getMaxPerformance(optimumConfig):
                reactive_upCounter += 1
                
            if avgData > predPerf:                
                pred_downCounter += 1
            elif getMaxPerformance(predConfig) > getMaxPerformance(optimumConfig):
                pred_upCounter += 1
                
            elif len(bestConfig) < len(predConfig):
                pred_upCounter += 1
        
        prediction = predictor.apply(avgData)
        #actuation = prediction
        actuation = max(prediction, avgData)
        
        tmp = predConfigurator.getConfiguration(actuation, predConfig, predConfigurator._gamma)
        if set(tmp) != set(predConfig):
            predCounter += 1
            predConfig = tmp
            predPerf = getMaxPerformance(predConfig)        

        if reactiveConfigurator.dynGamma:
            idealConfig = bestConfigurator.getConfiguration(avgData, reactiveConfig, reactiveConfigurator.MAX_GAMMA)
            idealPerf = round(getMaxPerformance(idealConfig),5)
            currPerf = round(getMaxPerformance(reactiveConfig),5)
            
            reactiveConfigurator._gamma = reactiveConfigurator.adjustGamma(currPerf - idealPerf)
            gammas.append(reactiveConfigurator._gamma)
            
        tmp = reactiveConfigurator.getConfiguration(avgData, reactiveConfig, reactiveConfigurator._gamma)        
        if set(tmp) != set(reactiveConfig):
            reactiveCounter += 1
            reactiveConfig = tmp
            reactivePerf = getMaxPerformance(reactiveConfig)
        
        
                
    print 'Best       - False alarms: up = %d, down = %d' % (best_upCounter, best_downCounter)
    print 'Predictive - False alarms: up = %d, down = %d' % (pred_upCounter, pred_downCounter)
    print 'Reactive   - False alarms: up = %d, down = %d' % (reactive_upCounter, reactive_downCounter)
    print 'Best Configs = %d, Predictive Configs = %d, Reactive Configs = %d' %\
          (bestCounter, predCounter, reactiveCounter)
    
    
    g = Gnuplot(debug=0)
    g('reset')
    #g('set size 0.65,0.65')
    g('set encoding iso_8859_1')
    g('set terminal postscript eps enhanced monochrome')    
    g('set output "carlos2.ps"')
    g('set key top left')
    g('set xlabel "Tempo (s)"')
    g('set xrange [0:%d]' % (len(data) / step))
    spacing = 15
    tics = ','.join(['"%d" %d' % (x * step * spacing, x * spacing) for x in range(1, len(data) / (step * spacing) + 1)])
    g('set xtics (%s)' % tics)
    g('set ylabel "Requisições"'.encode('iso_8859_1'))
    g('set grid')
    
    #plot incoming requests avg
    with_plot = 'steps'    
    
    #plot configurations
    pi1 = Data(avgs, with_=with_plot,title='Carga')
    pi2 = Data(reactivePerfs, with_=with_plot,title='Reativo')
    pi_gamma = Data(gammas, with_=with_plot,title='Gamma')
    #pi3 = Data(predPerfs, with_=with_plot,title='Preditivo')    
    #pi4 = Data(bestPerfs, with_=with_plot,title='Perfect')
    #g.plot(pi1,pi2)
    #g.plot(pi_gamma)
    
    #raw_input()
        
    print 'Done'