當前位置: 首頁>>代碼示例>>Python>>正文


Python UserServiceManager.getCacheStateFilter方法代碼示例

本文整理匯總了Python中uds.core.managers.UserServiceManager.UserServiceManager.getCacheStateFilter方法的典型用法代碼示例。如果您正苦於以下問題:Python UserServiceManager.getCacheStateFilter方法的具體用法?Python UserServiceManager.getCacheStateFilter怎麽用?Python UserServiceManager.getCacheStateFilter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在uds.core.managers.UserServiceManager.UserServiceManager的用法示例。


在下文中一共展示了UserServiceManager.getCacheStateFilter方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: reduceL1Cache

# 需要導入模塊: from uds.core.managers.UserServiceManager import UserServiceManager [as 別名]
# 或者: from uds.core.managers.UserServiceManager.UserServiceManager import getCacheStateFilter [as 別名]
    def reduceL1Cache(self, sp, cacheL1, cacheL2, assigned):
        logger.debug("Reducing L1 cache erasing a service in cache for {0}".format(sp))
        # We will try to destroy the newest cacheL1 element that is USABLE if the deployer can't cancel a new service creation
        cacheItems = sp.cachedUserServices().filter(UserServiceManager.getCacheStateFilter(services.UserDeployment.L1_CACHE)).order_by('-creation_date')
        if len(cacheItems) == 0:
            logger.debug('There is more services than configured, but could not reduce cache cause its already empty')
            return

        if cacheL2 < sp.cache_l2_srvs:
            valid = None
            for n in cacheItems:
                if n.needsOsManager():
                    if State.isUsable(n.state) is False or State.isUsable(n.os_state):
                        valid = n
                        break
                else:
                    valid = n
                    break

            if valid is not None:
                valid.moveToLevel(services.UserDeployment.L2_CACHE)
                return

        cache = cacheItems[0]
        cache.removeOrCancel()
開發者ID:aiminickwong,項目名稱:openuds,代碼行數:27,代碼來源:ServiceCacheUpdater.py

示例2: reduceL2Cache

# 需要導入模塊: from uds.core.managers.UserServiceManager import UserServiceManager [as 別名]
# 或者: from uds.core.managers.UserServiceManager.UserServiceManager import getCacheStateFilter [as 別名]
 def reduceL2Cache(self, sp, cacheL1, cacheL2, assigned):
     logger.debug("Reducing L2 cache erasing a service in cache for {0}".format(sp))
     if cacheL2 > 0:
         cacheItems = sp.cachedUserServices().filter(UserServiceManager.getCacheStateFilter(services.UserDeployment.L2_CACHE)).order_by('creation_date')
         # TODO: Look first for non finished cache items and cancel them
         cache = cacheItems[0]
         cache.removeOrCancel()
開發者ID:aiminickwong,項目名稱:openuds,代碼行數:9,代碼來源:ServiceCacheUpdater.py

示例3: growL1Cache

# 需要導入模塊: from uds.core.managers.UserServiceManager import UserServiceManager [as 別名]
# 或者: from uds.core.managers.UserServiceManager.UserServiceManager import getCacheStateFilter [as 別名]
    def growL1Cache(self, sp, cacheL1, cacheL2, assigned):
        '''
        This method tries to enlarge L1 cache.

        If for some reason the number of deployed services (Counting all, ACTIVE
        and PREPARING, assigned, L1 and L2) is over max allowed service deployments,
        this method will not grow the L1 cache
        '''
        logger.debug("Growing L1 cache creating a new service for {0}".format(sp))
        # First, we try to assign from L2 cache
        if cacheL2 > 0:
            valid = None
            with transaction.atomic():
                for n in sp.cachedUserServices().select_for_update().filter(UserServiceManager.getCacheStateFilter(services.UserDeployment.L2_CACHE)).order_by('creation_date'):
                    if n.needsOsManager():
                        if State.isUsable(n.state) is False or State.isUsable(n.os_state):
                            valid = n
                            break
                    else:
                        valid = n
                        break

            if valid is not None:
                valid.moveToLevel(services.UserDeployment.L1_CACHE)
                return
        try:
            UserServiceManager.manager().createCacheFor(sp.activePublication(), services.UserDeployment.L1_CACHE)
        except MaxServicesReachedException as e:
            log.doLog(sp, log.ERROR, 'Max number of services reached for this service', log.INTERNAL)
            logger.error(str(e))
        except:
            logger.exception('Exception')
開發者ID:aiminickwong,項目名稱:openuds,代碼行數:34,代碼來源:ServiceCacheUpdater.py

示例4: servicesPoolsNeedingCacheUpdate

# 需要導入模塊: from uds.core.managers.UserServiceManager import UserServiceManager [as 別名]
# 或者: from uds.core.managers.UserServiceManager.UserServiceManager import getCacheStateFilter [as 別名]
    def servicesPoolsNeedingCacheUpdate(self):
        # State filter for cached and inAssigned objects
        # First we get all deployed services that could need cache generation
        DeployedService.objects.update()
        # We start filtering out the deployed services that do not need caching at all.
        whichNeedsCaching = DeployedService.objects.filter(Q(initial_srvs__gte=0) | Q(cache_l1_srvs__gte=0)).filter(max_srvs__gt=0, state=State.ACTIVE,
                                                                                                                    service__provider__maintenance_mode=False)[:]

        # We will get the one that proportionally needs more cache
        servicesPools = []
        for sp in whichNeedsCaching:
            sp.userServices.update()  # Cleans cached queries
            # If this deployedService don't have a publication active and needs it, ignore it
            if sp.activePublication() is None and sp.service.getInstance().publicationType is not None:
                logger.debug('Needs publication but do not have one, cache test ignored')
                continue
            # If it has any running publication, do not generate cache anymore
            if sp.publications.filter(state=State.PREPARING).count() > 0:
                logger.debug('Stopped cache generation for deployed service with publication running: {0}'.format(sp))
                continue

            if sp.isRestrained():
                ServiceCacheUpdater.__notifyRestrain(sp)
                continue

            # Get data related to actual state of cache
            inCacheL1 = sp.cachedUserServices().filter(UserServiceManager.getCacheStateFilter(services.UserDeployment.L1_CACHE)).count()
            inCacheL2 = sp.cachedUserServices().filter(UserServiceManager.getCacheStateFilter(services.UserDeployment.L2_CACHE)).count()
            inAssigned = sp.assignedUserServices().filter(UserServiceManager.getStateFilter()).count()
            # if we bypasses max cache, we will reduce it in first place. This is so because this will free resources on service provider
            logger.debug("Examining {0} with {1} in cache L1 and {2} in cache L2, {3} inAssigned".format(
                         sp, inCacheL1, inCacheL2, inAssigned))
            totalL1Assigned = inCacheL1 + inAssigned
            # We have more than we want
            if totalL1Assigned > sp.max_srvs:
                logger.debug('We have more services than max configured')
                servicesPools.append((sp, inCacheL1, inCacheL2, inAssigned))
                continue
            # We have more in L1 cache than needed
            if totalL1Assigned > sp.initial_srvs and inCacheL1 > sp.cache_l1_srvs:
                logger.debug('We have more services in cache L1 than configured')
                servicesPools.append((sp, inCacheL1, inCacheL2, inAssigned))
                continue

            # If we have more in L2 cache than needed, decrease L2 cache, but int this case, we continue checking cause L2 cache removal
            # has less priority than l1 creations or removals, but higher. In this case, we will simply take last l2 oversized found and reduce it
            if inCacheL2 > sp.cache_l2_srvs:
                logger.debug('We have more services in L2 cache than configured, decreasing it')
                servicesPools.append((sp, inCacheL1, inCacheL2, inAssigned))
                continue

            # If this service don't allows more starting user services, continue
            if UserServiceManager.manager().canInitiateServiceFromDeployedService(sp) is False:
                logger.debug('This provider has the max allowed starting services running: {0}'.format(sp))
                continue

            # If wee need to grow l2 cache, annotate it
            # Whe check this before checking the total, because the l2 cache is independent of max services or l1 cache.
            # It reflects a value that must be keeped in cache for futre fast use.
            if inCacheL2 < sp.cache_l2_srvs:
                logger.debug('Needs to grow L2 cache for {}'.format(sp))
                servicesPools.append((sp, inCacheL1, inCacheL2, inAssigned))
                continue

            # We skip it if already at max
            if totalL1Assigned == sp.max_srvs:
                continue

            if totalL1Assigned < sp.initial_srvs or inCacheL1 < sp.cache_l1_srvs:
                logger.debug('Needs to grow L1 cache for {}'.format(sp))
                servicesPools.append((sp, inCacheL1, inCacheL2, inAssigned))

        # We also return calculated values so we can reuse then
        return servicesPools
開發者ID:aiminickwong,項目名稱:openuds,代碼行數:76,代碼來源:ServiceCacheUpdater.py


注:本文中的uds.core.managers.UserServiceManager.UserServiceManager.getCacheStateFilter方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。