引用我的locusfile.py
以下:
from locust import HttpLocust, TaskSet, between, task
import csv
class UserBehavior(TaskSet):
@task(1)
def index(l):
with open ('topURL.csv') as csvfile:
readCSV = csv.reader(csvfile, delimiter=',')
for row in readCSV:
l.client.get("%s" % (row[0]))
class WebsiteUser(HttpLocust):
task_set = UserBehavior
wait_time = between(5.0, 9.0)
当我执行这个脚本时,Locust 能够运行而没有任何错误。但是,它将遍历每一行并仅对最新的 URL 进行负载测试。在读取下一个 URL 时,不再对前一个 URL 进行负载测试。相反,我想要的是 Locust 在从 CSV 逐行读取时同时加载测试越来越多的 URL。
编辑
我设法通过设置
wait_time = between(0.0, 0.0)
来实现部分并发
最佳答案
尝试在设置时用您的 csv 数据填充一个数组并从中随机选择。
喜欢
def fill_array():
with open('topURL.csv') as csvfile:
readCSV = csv.reader(csvfile, delimiter=',')
for row in readCSV:
urls.append(row[0])
然后
@task(1)
def index(l):
l.client.get("%s" % (random.choice(urls)))
设置中的更多信息:
https://docs.locust.io/en/stable/writing-a-locustfile.html#setups-teardowns-on-start-and-on-stop
关于linux - 使用 Locust 对同时从 CSV 加载的多个 URL 运行负载测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60594591/