示例#1
0
    def getInitialScheme(self):
        periodDB = shelve.open(periodRecoderFile)
        periodDB[periodRecoder] = None
        periodDB.close()

        fiboDB = shelve.open(fiboDataFile)
        fiboDB[fiboDataName] = None
        fiboDB.close()

        clearAllData()

        PerformanceDBUtil.clearPerformanceDataTable()
        WorkloadDBUtil.clearWorkloadTable()

        uiCount = UsingInstancesDBUtil.getUsingInstancesCount()

        if uiCount < initUsingInstancesNumbers:
            TomcatInstanceUtil.resetAllUsingInstances()
            self.acrcPlacementComponent.getPlacementScheme(
                initUsingInstancesNumbers - uiCount, True)
        elif uiCount > initUsingInstancesNumbers:
            self.acrcPlacementComponent.getPlacementScheme(
                uiCount - initUsingInstancesNumbers, False)
            TomcatInstanceUtil.resetAllUsingInstances()
        else:
            TomcatInstanceUtil.resetAllUsingInstances()
示例#2
0
    def getNumberOfVMsShouldBeScaled(self):
        if not self.predictor or not self.ruleChecker:
            raise Exception('no predictor or ruleChecker')

        newestHD = WorkloadDBUtil.getNewestWorkload()

        if not newestHD:
            raise Exception('Can not get newest workload')


        addWLToACRCWindow(newestHD['realWL'])
        predictWL = self.predictor.getNextPeriodWorkload()
        addPWLToACRCWindow(predictWL)

        #预测写入Workload表
        periodNoDB = shelve.open(periodRecoderFile)
        periodNo = periodNoDB.get(periodRecoder, None)
        if not periodNo:
            raise Exception('Can not get periodNo')
        WorkloadDBUtil.addPredictWorkloadToSpecificPeriod(periodNo, predictWL)

        #记录供给的虚拟机数目的分布
        provisionInfoDB = shelve.open(provisionInfoFile)

        #查询需要的VM
        predictVMNumbers = WorkloadVMMapDBUtil.getTargetVMsToSpecificWorkload(predictWL)

        provisionInfoDB[predictProvisionVMNumbers] = predictVMNumbers

        logger.info('PredictWorkload:' + str(predictWL) + ' predictVMNumbers:' + str(predictVMNumbers))

        addedVMNumbers = self.ruleChecker.getNextAddedVMs()

        provisionInfoDB[reactiveProvisionVMNumbers] = addedVMNumbers

        logger.info('addedVMNumbers:' + str(addedVMNumbers))

        provisionInfoDB.close()

        nextPeriodVMNumbers = predictVMNumbers + addedVMNumbers

        usingInstancesCount = UsingInstancesDBUtil.getUsingInstancesCount()
        gab = abs(usingInstancesCount - nextPeriodVMNumbers)

        if usingInstancesCount > nextPeriodVMNumbers:
            return {'vmNumbers':gab, 'isUp':False}
        elif usingInstancesCount < nextPeriodVMNumbers:
            return {'vmNumbers':gab, 'isUp':True}
        else:
            return {'vmNumbers':gab}
示例#3
0
    def getNumberOfVMsShouldBeScaled(self):
        if not self.predictor or not self.ruleChecker:
            raise Exception('no predictor or ruleChecker')

        newestHD = WorkloadDBUtil.getNewestWorkload()

        if not newestHD:
            raise Exception('Can not get newest workload')

        addWLToACRCWindow(newestHD['realWL'])
        predictWL = self.predictor.getNextPeriodWorkload()
        addPWLToACRCWindow(predictWL)

        # 预测写入Workload表
        periodNoDB = shelve.open(periodRecoderFile)
        periodNo = periodNoDB.get(periodRecoder, None)
        if not periodNo:
            raise Exception('Can not get periodNo')

        # do linear regression in given windowSize
        # TODO: temporarily use default windowSize = sys.maxint
        pairs = WorkloadDBUtil.getRealWorkloadAndRealTotalCalculationInPairs()
        wl = pairs[0]
        tc = pairs[1]
        # TODO: do not fix the interception temporarily, might let the line cross the origin later
        regression = np.polyfit(wl, tc, 1)
        k = float(regression[0])
        b = float(regression[1])

        if k < 0 or wl.__len__() == 1:
            # actually k should be positive, here to eliminate corner case when there's not much log
            logger.warning("k = " + str(k) +
                           " is negative or length of log is 0!")
            k = tc[-1] / wl[-1]
            b = 0
            logger.warning("using k = " + str(k) + " b = 0 instead")

        predictVMNumbers = math.ceil(
            k * predictWL /
            (TomcatInstanceUtil.getCalculationCapacityPerInstance() - b))

        predictTC = k * predictWL + predictVMNumbers * b

        WorkloadDBUtil.addPredictWorkloadAndPredictTotalCalculationToSpecificPeriod(
            periodNo, predictWL, predictTC)

        # 记录供给的虚拟机数目的分布
        provisionInfoDB = shelve.open(provisionInfoFile)

        provisionInfoDB[predictProvisionVMNumbers] = predictVMNumbers

        logger.info('PredictWorkload:' + str(predictWL) +
                    ' predictVMNumbers:' + str(predictVMNumbers) +
                    ' predictTC: ' + str(predictTC))

        addedVMNumbers = self.ruleChecker.getNextAddedVMs()

        provisionInfoDB[reactiveProvisionVMNumbers] = addedVMNumbers

        logger.info('addedVMNumbers:' + str(addedVMNumbers))

        provisionInfoDB.close()

        nextPeriodVMNumbers = predictVMNumbers + addedVMNumbers

        usingInstancesCount = UsingInstancesDBUtil.getUsingInstancesCount()
        gab = abs(usingInstancesCount - nextPeriodVMNumbers)

        if usingInstancesCount > nextPeriodVMNumbers:
            rt = {'vmNumbers': gab, 'isUp': False}
        elif usingInstancesCount < nextPeriodVMNumbers:
            rt = {'vmNumbers': gab, 'isUp': True}
        else:
            rt = {'vmNumbers': gab}

        logger.info('return with:' + str(rt))

        return rt
示例#4
0
文件: res.py 项目: csfldf/CloudExSDK
#!/usr/bin/env python
# encoding: utf-8

from DBUtil.PerformanceDBUtil import PerformanceDBUtil
from DBUtil.WorkloadDBUtil import WorkloadDBUtil

print WorkloadDBUtil.getAllWorkloadInfo()

print PerformanceDBUtil.getPerformanceDataCount()
示例#5
0
#!/usr/bin/env python
# encoding: utf-8

from DBUtil.PerformanceDBUtil import PerformanceDBUtil
from DBUtil.WorkloadDBUtil import WorkloadDBUtil

WorkloadDBUtil.clearWorkloadTable()
WorkloadDBUtil.addFirstPeriodRealWorkload(5000)
WorkloadDBUtil.addPredictWorkloadToSpecificPeriod(2, 300)
WorkloadDBUtil.addRealWorkloadToSpecificPeriod(2, 305)
print WorkloadDBUtil.getAllWorkloadInfo()

performanceData = {
    'minResponseTime': 105.8,
    'maxResponseTime': 13.2,
    'avgResponseTime': 22.3,
    'breakSLAPercent': 0.2,
    'avgCpuUtil': 0.3,
    'avgMemoryUtil': 0.6
}
PerformanceDBUtil.addPerformanceDataToSpecificPeriod(6, performanceData)

performanceData = {
    'minResponseTime': 205.3,
    'maxResponseTime': 13.2,
    'avgResponseTime': 22.3,
    'breakSLAPercent': 0.2,
    'avgCpuUtil': 0.3,
    'avgMemoryUtil': 0.6
}
PerformanceDBUtil.addPerformanceDataToSpecificPeriod(5, performanceData)
示例#6
0
    def periodPerformanceDataHandler2(self, req):
        minResponseTime = req.params.get('minResponseTime')
        avgResponseTime = req.params.get('avgResponseTime')
        maxResponseTime = req.params.get('maxResponseTime')
        totalRequestCount = req.params.get('totalRequestCount')
        breakSLACount = req.params.get('breakSLACount')
        jumpServer = req.params.get('jumpServer')
        infos = SampleUtil.getThreadInfosOverAllUsingInstances(jumpServer)
        avgCpuUtil = round(infos[0] / 100.0, 4)
        totalCalculation = round(infos[1] / 100.0, 4)
        avgMemoryUtil = round(SampleUtil.getAllUsingInstancesPeriodAVGMemoryUtil() / 100.0, 4)

        if not (isDecimal(minResponseTime) or isNumber(minResponseTime)) \
                or not (isDecimal(maxResponseTime) or isNumber(maxResponseTime)) \
                or not (isDecimal(avgResponseTime) or isNumber(avgResponseTime)) \
                or not isNumber(totalRequestCount) \
                or not isNumber(breakSLACount):
            return errorResultJson('Please pass the params correctly')
        elif avgCpuUtil == None or avgMemoryUtil == None or totalCalculation == None:
            raise Exception("can not get avgCpuUtil or avgMemoryUtil or totalCalculation data")
        else:
            minResponseTime = float(minResponseTime)
            avgResponseTime = float(avgResponseTime)
            maxResponseTime = float(maxResponseTime)
            totalRequestCount = int(totalRequestCount)
            breakSLACount = int(breakSLACount)

            # 确认periodNo
            periodNoDB = shelve.open(periodRecoderFile)
            periodNo = periodNoDB.get(periodRecoder, None)

            if not periodNo:
                periodNo = 1

            periodNoDB[periodRecoder] = periodNo + 1
            periodNoDB.close()

            # 计算breakSLAPercent
            breakSLAPercent = float(breakSLACount) / totalRequestCount
            breakSLAPercent = round(breakSLAPercent, 4)

            # 计算刚刚过去的这个周期的可用性
            placementTool = ACRCPlacementComponent()
            availabilityData = placementTool.calculateAvailability()

            # 得到刚刚过去这个周期的虚拟机数目
            vmNumbers = UsingInstancesDBUtil.getUsingInstancesCount()

            # 添加上个周期应该提供的虚拟机数目
            shouldVMNumbers = WorkloadVMMapDBUtil.getTargetVMsToSpecificWorkload(totalRequestCount)

            if periodNo == 1:
                ppVMNumbers = vmNumbers
                rpVMNumbers = 0
            else:
                provisionInfoDB = shelve.open(provisionInfoFile)
                ppVMNumbers = provisionInfoDB.get(predictProvisionVMNumbers, None)
                rpVMNumbers = provisionInfoDB.get(reactiveProvisionVMNumbers, None)

            # 添加performanceData
            performanceData = {'minResponseTime': minResponseTime, 'maxResponseTime': maxResponseTime,
                               'avgResponseTime': avgResponseTime, 'breakSLAPercent': breakSLAPercent,
                               'avgCpuUtil': avgCpuUtil, 'avgMemoryUtil': avgMemoryUtil,
                               'availability': availabilityData, 'vmNumbers': vmNumbers,
                               'shouldVMNumbers': shouldVMNumbers, 'predictProvisionVMNumbers': ppVMNumbers,
                               'reactiveProvisionVMNumbers': rpVMNumbers}
            PerformanceDBUtil.addPerformanceDataToSpecificPeriod(periodNo, performanceData)

            # 向数据库中添加workload信息
            if periodNo == 1:
                WorkloadDBUtil.addFirstPeriodRealWorkloadAndRealTotalCalculation(totalRequestCount, totalCalculation)
            else:
                WorkloadDBUtil.addRealWorkloadAndRealTotalCalculationToSpecificPeriod(periodNo, totalRequestCount,
                                                                                      totalCalculation)

            acrCtl = ACRController()
            acrCtl.autonomicPeriodHandler()

            TomcatInstanceUtil.ensureAllUsingInstancesActive()
            return UsingInstancesDBUtil.getAllUsingInstancesInfo()