Locust:如何对 n 个用户 运行 执行 n 次任务而不是停止 Locust 运行?
Locust: How to run task n times on n users and than stop locust run?
我有一个简单的 Locust 脚本,其中包含一个带有 http 请求的任务。
我想对 10 个用户 运行 此任务执行 100 次,然后停止 运行 脚本。
有没有什么简单的方法可以做到。我知道 --运行-time 参数,但它只会在指定的时间后停止
下面是我的脚本:
from locust import HttpUser, task, between
class QuickstartUser(HttpUser):
wait_time = between(1, 2)
host = "https://allegro.pl"
@task(1)
def getHome(self):
self.client.get("/dzial/dom-i-ogrod", name = "Get Home and Garden")
如果你不是 运行 分布式你可以有一个全局计数器并在任务中递增它,一旦它达到所需的计数你就可以停止跑步者,比如:
from locust import HttpUser, task, between
counter=0
class QuickstartUser(HttpUser):
wait_time = between(1, 2)
host = "https://allegro.pl"
@task(1)
def getHome(self):
if counter == 100:
self.environment.runner.stop()
self.client.get("/dzial/dom-i-ogrod", name = "Get Home and Garden")
counter = counter + 1`
如果你是 运行 分布式,最好使用一些外部计数器来跟踪 redis 之类的请求。
locust-plugins 提供的另一个选项是 -i 参数:https://github.com/SvenskaSpel/locust-plugins#command-line-options
它应该更可靠一点,因为它明确调用了 runner.quit()
我有一个简单的 Locust 脚本,其中包含一个带有 http 请求的任务。 我想对 10 个用户 运行 此任务执行 100 次,然后停止 运行 脚本。 有没有什么简单的方法可以做到。我知道 --运行-time 参数,但它只会在指定的时间后停止
下面是我的脚本:
from locust import HttpUser, task, between
class QuickstartUser(HttpUser):
wait_time = between(1, 2)
host = "https://allegro.pl"
@task(1)
def getHome(self):
self.client.get("/dzial/dom-i-ogrod", name = "Get Home and Garden")
如果你不是 运行 分布式你可以有一个全局计数器并在任务中递增它,一旦它达到所需的计数你就可以停止跑步者,比如:
from locust import HttpUser, task, between
counter=0
class QuickstartUser(HttpUser):
wait_time = between(1, 2)
host = "https://allegro.pl"
@task(1)
def getHome(self):
if counter == 100:
self.environment.runner.stop()
self.client.get("/dzial/dom-i-ogrod", name = "Get Home and Garden")
counter = counter + 1`
如果你是 运行 分布式,最好使用一些外部计数器来跟踪 redis 之类的请求。
locust-plugins 提供的另一个选项是 -i 参数:https://github.com/SvenskaSpel/locust-plugins#command-line-options
它应该更可靠一点,因为它明确调用了 runner.quit()