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


Python StandardAutoscaler.update方法代碼示例

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


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

示例1: testDelayedLaunch

# 需要導入模塊: from ray.autoscaler.autoscaler import StandardAutoscaler [as 別名]
# 或者: from ray.autoscaler.autoscaler.StandardAutoscaler import update [as 別名]
    def testDelayedLaunch(self):
        config_path = self.write_config(SMALL_CLUSTER)
        self.provider = MockProvider()
        autoscaler = StandardAutoscaler(
            config_path,
            LoadMetrics(),
            max_launch_batch=5,
            max_concurrent_launches=5,
            max_failures=0,
            update_interval_s=0)
        assert len(self.provider.non_terminated_nodes({})) == 0

        # Update will try to create, but will block until we set the flag
        self.provider.ready_to_create.clear()
        autoscaler.update()
        assert autoscaler.num_launches_pending.value == 2
        assert len(self.provider.non_terminated_nodes({})) == 0

        # Set the flag, check it updates
        self.provider.ready_to_create.set()
        self.waitForNodes(2)
        assert autoscaler.num_launches_pending.value == 0

        # Update the config to reduce the cluster size
        new_config = SMALL_CLUSTER.copy()
        new_config["max_workers"] = 1
        self.write_config(new_config)
        autoscaler.update()
        assert len(self.provider.non_terminated_nodes({})) == 1
開發者ID:robertnishihara,項目名稱:ray,代碼行數:31,代碼來源:test_autoscaler.py

示例2: testMaxFailures

# 需要導入模塊: from ray.autoscaler.autoscaler import StandardAutoscaler [as 別名]
# 或者: from ray.autoscaler.autoscaler.StandardAutoscaler import update [as 別名]
 def testMaxFailures(self):
     config_path = self.write_config(SMALL_CLUSTER)
     self.provider = MockProvider()
     self.provider.throw = True
     autoscaler = StandardAutoscaler(
         config_path, LoadMetrics(), max_failures=2, update_interval_s=0)
     autoscaler.update()
     autoscaler.update()
     self.assertRaises(Exception, autoscaler.update)
開發者ID:adgirish,項目名稱:ray,代碼行數:11,代碼來源:autoscaler_test.py

示例3: testScaleUp

# 需要導入模塊: from ray.autoscaler.autoscaler import StandardAutoscaler [as 別名]
# 或者: from ray.autoscaler.autoscaler.StandardAutoscaler import update [as 別名]
 def testScaleUp(self):
     config_path = self.write_config(SMALL_CLUSTER)
     self.provider = MockProvider()
     autoscaler = StandardAutoscaler(
         config_path, LoadMetrics(), max_failures=0, update_interval_s=0)
     self.assertEqual(len(self.provider.nodes({})), 0)
     autoscaler.update()
     self.assertEqual(len(self.provider.nodes({})), 2)
     autoscaler.update()
     self.assertEqual(len(self.provider.nodes({})), 2)
開發者ID:adgirish,項目名稱:ray,代碼行數:12,代碼來源:autoscaler_test.py

示例4: testScaleUp

# 需要導入模塊: from ray.autoscaler.autoscaler import StandardAutoscaler [as 別名]
# 或者: from ray.autoscaler.autoscaler.StandardAutoscaler import update [as 別名]
 def testScaleUp(self):
     config_path = self.write_config(SMALL_CLUSTER)
     self.provider = MockProvider()
     autoscaler = StandardAutoscaler(
         config_path, LoadMetrics(), max_failures=0, update_interval_s=0)
     assert len(self.provider.non_terminated_nodes({})) == 0
     autoscaler.update()
     self.waitForNodes(2)
     autoscaler.update()
     self.waitForNodes(2)
開發者ID:robertnishihara,項目名稱:ray,代碼行數:12,代碼來源:test_autoscaler.py

示例5: testUpdateThrottling

# 需要導入模塊: from ray.autoscaler.autoscaler import StandardAutoscaler [as 別名]
# 或者: from ray.autoscaler.autoscaler.StandardAutoscaler import update [as 別名]
 def testUpdateThrottling(self):
     config_path = self.write_config(SMALL_CLUSTER)
     self.provider = MockProvider()
     autoscaler = StandardAutoscaler(
         config_path, LoadMetrics(), max_concurrent_launches=5,
         max_failures=0, update_interval_s=10)
     autoscaler.update()
     self.assertEqual(len(self.provider.nodes({})), 2)
     new_config = SMALL_CLUSTER.copy()
     new_config["max_workers"] = 1
     self.write_config(new_config)
     autoscaler.update()
     self.assertEqual(len(self.provider.nodes({})), 2)  # not updated yet
開發者ID:adgirish,項目名稱:ray,代碼行數:15,代碼來源:autoscaler_test.py

示例6: testLaunchNewNodeOnOutOfBandTerminate

# 需要導入模塊: from ray.autoscaler.autoscaler import StandardAutoscaler [as 別名]
# 或者: from ray.autoscaler.autoscaler.StandardAutoscaler import update [as 別名]
 def testLaunchNewNodeOnOutOfBandTerminate(self):
     config_path = self.write_config(SMALL_CLUSTER)
     self.provider = MockProvider()
     autoscaler = StandardAutoscaler(
         config_path, LoadMetrics(), max_failures=0, update_interval_s=0)
     autoscaler.update()
     autoscaler.update()
     self.assertEqual(len(self.provider.nodes({})), 2)
     for node in self.provider.mock_nodes.values():
         node.state = "terminated"
     self.assertEqual(len(self.provider.nodes({})), 0)
     autoscaler.update()
     self.assertEqual(len(self.provider.nodes({})), 2)
開發者ID:adgirish,項目名稱:ray,代碼行數:15,代碼來源:autoscaler_test.py

示例7: testDynamicScaling

# 需要導入模塊: from ray.autoscaler.autoscaler import StandardAutoscaler [as 別名]
# 或者: from ray.autoscaler.autoscaler.StandardAutoscaler import update [as 別名]
    def testDynamicScaling(self):
        config_path = self.write_config(SMALL_CLUSTER)
        self.provider = MockProvider()
        autoscaler = StandardAutoscaler(
            config_path, LoadMetrics(), max_concurrent_launches=5,
            max_failures=0, update_interval_s=0)
        self.assertEqual(len(self.provider.nodes({})), 0)
        autoscaler.update()
        self.assertEqual(len(self.provider.nodes({})), 2)

        # Update the config to reduce the cluster size
        new_config = SMALL_CLUSTER.copy()
        new_config["max_workers"] = 1
        self.write_config(new_config)
        autoscaler.update()
        self.assertEqual(len(self.provider.nodes({})), 1)

        # Update the config to reduce the cluster size
        new_config["min_workers"] = 10
        new_config["max_workers"] = 10
        self.write_config(new_config)
        autoscaler.update()
        self.assertEqual(len(self.provider.nodes({})), 6)
        autoscaler.update()
        self.assertEqual(len(self.provider.nodes({})), 10)
開發者ID:adgirish,項目名稱:ray,代碼行數:27,代碼來源:autoscaler_test.py

示例8: testDontScaleBelowTarget

# 需要導入模塊: from ray.autoscaler.autoscaler import StandardAutoscaler [as 別名]
# 或者: from ray.autoscaler.autoscaler.StandardAutoscaler import update [as 別名]
    def testDontScaleBelowTarget(self):
        config = SMALL_CLUSTER.copy()
        config["min_workers"] = 0
        config["max_workers"] = 2
        config["target_utilization_fraction"] = 0.5
        config_path = self.write_config(config)
        self.provider = MockProvider()
        lm = LoadMetrics()
        autoscaler = StandardAutoscaler(
            config_path, lm, max_failures=0, update_interval_s=0)
        assert len(self.provider.non_terminated_nodes({})) == 0
        autoscaler.update()
        assert autoscaler.num_launches_pending.value == 0
        assert len(self.provider.non_terminated_nodes({})) == 0

        # Scales up as nodes are reported as used
        local_ip = services.get_node_ip_address()
        lm.update(local_ip, {"CPU": 2}, {"CPU": 0})  # head
        # 1.0 nodes used => target nodes = 2 => target workers = 1
        autoscaler.update()
        self.waitForNodes(1)

        # Make new node idle, and never used.
        # Should hold steady as target is still 2.
        lm.update("172.0.0.0", {"CPU": 0}, {"CPU": 0})
        lm.last_used_time_by_ip["172.0.0.0"] = 0
        autoscaler.update()
        assert len(self.provider.non_terminated_nodes({})) == 1

        # Reduce load on head => target nodes = 1 => target workers = 0
        lm.update(local_ip, {"CPU": 2}, {"CPU": 1})
        autoscaler.update()
        assert len(self.provider.non_terminated_nodes({})) == 0
開發者ID:robertnishihara,項目名稱:ray,代碼行數:35,代碼來源:test_autoscaler.py

示例9: testConfiguresNewNodes

# 需要導入模塊: from ray.autoscaler.autoscaler import StandardAutoscaler [as 別名]
# 或者: from ray.autoscaler.autoscaler.StandardAutoscaler import update [as 別名]
 def testConfiguresNewNodes(self):
     config_path = self.write_config(SMALL_CLUSTER)
     self.provider = MockProvider()
     runner = MockProcessRunner()
     autoscaler = StandardAutoscaler(
         config_path,
         LoadMetrics(),
         max_failures=0,
         process_runner=runner,
         update_interval_s=0)
     autoscaler.update()
     autoscaler.update()
     self.waitForNodes(2)
     for node in self.provider.mock_nodes.values():
         node.state = "running"
     autoscaler.update()
     self.waitForNodes(2, tag_filters={TAG_RAY_NODE_STATUS: "up-to-date"})
開發者ID:robertnishihara,項目名稱:ray,代碼行數:19,代碼來源:test_autoscaler.py

示例10: testDelayedLaunchWithFailure

# 需要導入模塊: from ray.autoscaler.autoscaler import StandardAutoscaler [as 別名]
# 或者: from ray.autoscaler.autoscaler.StandardAutoscaler import update [as 別名]
    def testDelayedLaunchWithFailure(self):
        config = SMALL_CLUSTER.copy()
        config["min_workers"] = 10
        config["max_workers"] = 10
        config_path = self.write_config(config)
        self.provider = MockProvider()
        autoscaler = StandardAutoscaler(
            config_path,
            LoadMetrics(),
            max_launch_batch=5,
            max_concurrent_launches=8,
            max_failures=0,
            update_interval_s=0)
        assert len(self.provider.non_terminated_nodes({})) == 0

        # update() should launch a wave of 5 nodes (max_launch_batch)
        # Force this first wave to block.
        rtc1 = self.provider.ready_to_create
        rtc1.clear()
        autoscaler.update()
        # Synchronization: wait for launchy thread to be blocked on rtc1
        if hasattr(rtc1, '_cond'):  # Python 3.5
            waiters = rtc1._cond._waiters
        else:  # Python 2.7
            waiters = rtc1._Event__cond._Condition__waiters
        self.waitFor(lambda: len(waiters) == 1)
        assert autoscaler.num_launches_pending.value == 5
        assert len(self.provider.non_terminated_nodes({})) == 0

        # Call update() to launch a second wave of 3 nodes,
        # as 5 + 3 = 8 = max_concurrent_launches.
        # Make this wave complete immediately.
        rtc2 = threading.Event()
        self.provider.ready_to_create = rtc2
        rtc2.set()
        autoscaler.update()
        self.waitForNodes(3)
        assert autoscaler.num_launches_pending.value == 5

        # The first wave of 5 will now tragically fail
        self.provider.fail_creates = True
        rtc1.set()
        self.waitFor(lambda: autoscaler.num_launches_pending.value == 0)
        assert len(self.provider.non_terminated_nodes({})) == 3

        # Retry the first wave, allowing it to succeed this time
        self.provider.fail_creates = False
        autoscaler.update()
        self.waitForNodes(8)
        assert autoscaler.num_launches_pending.value == 0

        # Final wave of 2 nodes
        autoscaler.update()
        self.waitForNodes(10)
        assert autoscaler.num_launches_pending.value == 0
開發者ID:robertnishihara,項目名稱:ray,代碼行數:57,代碼來源:test_autoscaler.py

示例11: testLaunchConfigChange

# 需要導入模塊: from ray.autoscaler.autoscaler import StandardAutoscaler [as 別名]
# 或者: from ray.autoscaler.autoscaler.StandardAutoscaler import update [as 別名]
    def testLaunchConfigChange(self):
        config_path = self.write_config(SMALL_CLUSTER)
        self.provider = MockProvider()
        autoscaler = StandardAutoscaler(
            config_path, LoadMetrics(), max_failures=0, update_interval_s=0)
        autoscaler.update()
        self.waitForNodes(2)

        # Update the config to change the node type
        new_config = SMALL_CLUSTER.copy()
        new_config["worker_nodes"]["InstanceType"] = "updated"
        self.write_config(new_config)
        self.provider.ready_to_create.clear()
        for _ in range(5):
            autoscaler.update()
        self.waitForNodes(0)
        self.provider.ready_to_create.set()
        self.waitForNodes(2)
開發者ID:robertnishihara,項目名稱:ray,代碼行數:20,代碼來源:test_autoscaler.py

示例12: testLaunchConfigChange

# 需要導入模塊: from ray.autoscaler.autoscaler import StandardAutoscaler [as 別名]
# 或者: from ray.autoscaler.autoscaler.StandardAutoscaler import update [as 別名]
    def testLaunchConfigChange(self):
        config_path = self.write_config(SMALL_CLUSTER)
        self.provider = MockProvider()
        autoscaler = StandardAutoscaler(
            config_path, LoadMetrics(), max_failures=0, update_interval_s=0)
        autoscaler.update()
        self.assertEqual(len(self.provider.nodes({})), 2)

        # Update the config to change the node type
        new_config = SMALL_CLUSTER.copy()
        new_config["worker_nodes"]["InstanceType"] = "updated"
        self.write_config(new_config)
        existing_nodes = set(self.provider.nodes({}))
        for _ in range(5):
            autoscaler.update()
        new_nodes = set(self.provider.nodes({}))
        self.assertEqual(len(new_nodes), 2)
        self.assertEqual(len(new_nodes.intersection(existing_nodes)), 0)
開發者ID:adgirish,項目名稱:ray,代碼行數:20,代碼來源:autoscaler_test.py

示例13: testReportsConfigFailures

# 需要導入模塊: from ray.autoscaler.autoscaler import StandardAutoscaler [as 別名]
# 或者: from ray.autoscaler.autoscaler.StandardAutoscaler import update [as 別名]
 def testReportsConfigFailures(self):
     config_path = self.write_config(SMALL_CLUSTER)
     self.provider = MockProvider()
     runner = MockProcessRunner(fail_cmds=["cmd1"])
     autoscaler = StandardAutoscaler(
         config_path, LoadMetrics(), max_failures=0, process_runner=runner,
         verbose_updates=True, node_updater_cls=NodeUpdaterThread,
         update_interval_s=0)
     autoscaler.update()
     autoscaler.update()
     self.assertEqual(len(self.provider.nodes({})), 2)
     for node in self.provider.mock_nodes.values():
         node.state = "running"
     assert len(self.provider.nodes(
         {TAG_RAY_NODE_STATUS: "Uninitialized"})) == 2
     autoscaler.update()
     self.waitFor(
         lambda: len(self.provider.nodes(
             {TAG_RAY_NODE_STATUS: "UpdateFailed"})) == 2)
開發者ID:adgirish,項目名稱:ray,代碼行數:21,代碼來源:autoscaler_test.py

示例14: testTerminateOutdatedNodesGracefully

# 需要導入模塊: from ray.autoscaler.autoscaler import StandardAutoscaler [as 別名]
# 或者: from ray.autoscaler.autoscaler.StandardAutoscaler import update [as 別名]
    def testTerminateOutdatedNodesGracefully(self):
        config = SMALL_CLUSTER.copy()
        config["min_workers"] = 5
        config["max_workers"] = 5
        config_path = self.write_config(config)
        self.provider = MockProvider()
        self.provider.create_node({}, {TAG_RAY_NODE_TYPE: "Worker"}, 10)
        autoscaler = StandardAutoscaler(
            config_path, LoadMetrics(), max_failures=0, update_interval_s=0)
        self.assertEqual(len(self.provider.nodes({})), 10)

        # Gradually scales down to meet target size, never going too low
        for _ in range(10):
            autoscaler.update()
            self.assertLessEqual(len(self.provider.nodes({})), 5)
            self.assertGreaterEqual(len(self.provider.nodes({})), 4)

        # Eventually reaches steady state
        self.assertEqual(len(self.provider.nodes({})), 5)
開發者ID:adgirish,項目名稱:ray,代碼行數:21,代碼來源:autoscaler_test.py

示例15: testIgnoresCorruptedConfig

# 需要導入模塊: from ray.autoscaler.autoscaler import StandardAutoscaler [as 別名]
# 或者: from ray.autoscaler.autoscaler.StandardAutoscaler import update [as 別名]
    def testIgnoresCorruptedConfig(self):
        config_path = self.write_config(SMALL_CLUSTER)
        self.provider = MockProvider()
        autoscaler = StandardAutoscaler(
            config_path,
            LoadMetrics(),
            max_launch_batch=10,
            max_concurrent_launches=10,
            max_failures=0,
            update_interval_s=0)
        autoscaler.update()
        self.waitForNodes(2)

        # Write a corrupted config
        self.write_config("asdf")
        for _ in range(10):
            autoscaler.update()
        time.sleep(0.1)
        assert autoscaler.num_launches_pending.value == 0
        assert len(self.provider.non_terminated_nodes({})) == 2

        # New a good config again
        new_config = SMALL_CLUSTER.copy()
        new_config["min_workers"] = 10
        new_config["max_workers"] = 10
        self.write_config(new_config)
        autoscaler.update()
        self.waitForNodes(10)
開發者ID:robertnishihara,項目名稱:ray,代碼行數:30,代碼來源:test_autoscaler.py


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