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中使用,然而至少就我们目前的应用场景而言,这个关键字比较鸡肋,我还没想到它能有啥用。
