Locust 脚本-集合点

集合点

这样实现的集合点只在开始运行时等待所有用户初始化,对于需要并发的业务来说,一般情况下是够用的。

from locust import HttpLocust, TaskSet, task, events
from gevent._semaphore import Semaphore
all_locusts_spawned = Semaphore()
all_locusts_spawned.acquire()

def on_hatch_complete(**kwargs):
    all_locusts_spawned.release()

events.hatch_complete += on_hatch_complete

class UserBehavior(TaskSet):
	@task(2)
	def index(self):
		self.client.get("/1111")

	@task(1)
	def profile(self):
		self.client.get("/")

	def on_start(self):
		all_locusts_spawned.wait()

class WebsiteUser(HttpLocust):
    task_set = UserBehavior
    min_wait = 100
    max_wait = 1000

参考:https://www.cnblogs.com/grandlulu/p/9455794.html

你可能感兴趣的:(性能测试,locust)