Ansible 2.9.0 新增的 throttle 关键字

Ansible 2.9的CHANGELOG里是这么描述的:

- Added new `throttle` keyword, which can be used at the task, block, or play level to limit the number of workers (up to the specified forks or serial setting) allowed.

定义在lib/ansible/playbook/base.py里作为Base的成员,也就是说Play,Task,Block都可以使用这个关键字。
它的用途主要体现在Strategy里,跟StrategyBase.ALLOW_BASE_THROTTLING共同作用与WorkerProcess的创建。在StrategyBase中,ALLOW_BASE_THROTTLING默认为True,也就是允许节流。注释是这么写的(158-161行):

    # by default, strategies should support throttling but we allow individual
    # strategies to disable this and either forego supporting it or managing
    # the throttling internally (as `free` does)
    ALLOW_BASE_THROTTLING = True

在StrategyBase._queue_task里原本的代码上加了一块:

                # Determine the "rewind point" of the worker list. This means we start
                # iterating over the list of workers until the end of the list is found.
                # Normally, that is simply the length of the workers list (as determined
                # by the forks or serial setting), however a task/block/play may "throttle"
                # that limit down.
                rewind_point = len(self._workers)
                if throttle > 0 and self.ALLOW_BASE_THROTTLING:
                    if task.run_once:
                        display.debug("Ignoring 'throttle' as 'run_once' is also set for '%s'" % task.get_name())
                    else:
                        if throttle <= rewind_point:
                            display.debug("task: %s, throttle: %d" % (task.get_name(), throttle))
                            rewind_point = throttle
                if self._cur_worker >= rewind_point:
                    self._cur_worker = 0

简单解释就是throttle的值是在作用在forks基础之上的,因为forks是个选项,写在配置文件里的默认值是5。
Ansible启动的时候还是按照forks的大小去创建workers列表,但这个列表里具体有多少个槽位能用,是取决于throttle的。由于throttle可以在play,block,task中使用,然而至少就我们目前的应用场景而言,这个关键字比较鸡肋,我还没想到它能有啥用。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值