安装好lucust后,将下面脚本保存为test.py
# This locust test script example will simulate a user
# browsing the Locust documentation on https://docs.locust.io
import random
from locust import HttpUser, between, task
from pyquery import PyQuery
class AwesomeUser(HttpUser):
host = "https://docs.locust.io/en/latest/"
# we assume someone who is browsing the Locust docs,
# generally has a quite long waiting time (between
# 10 and 600 seconds), since there's a bunch of text
# on each page
wait_time = between(10, 600)
def on_start(self):
# start by waiting so that the simulated users
# won't all arrive at the same time
self.wait()
# assume all users arrive at the index page
self.index_page()
self.urls_on_current_page = self.toc_urls
@task(10)
def index_page(self):
r = self.client.get("")
pq = PyQuery(r.content)
link_elements = pq(".toctree-wrapper a.internal")
self.toc_urls = [
l.attrib["href"] for l in link_elements
]
@task(50)
def load_page(self):
url = random.choice(self.toc_urls)
r = self.client.get(url)
pq = PyQuery(r.content)
link_elements = pq("a.internal")
self.urls_on_current_page = [
l.attrib["href"] for l in link_elements
]
@task(30)
def load_sub_page(self):
url = random.choice(self.urls_on_current_page)
r = self.client.get(url)
然后在命令行执行lucust test.py --host=http
打开浏览器输入http://127.0.0.1:8089后就好了
网友回复
有没有开源的项目将图片视频声音文字转场特效编排自动生成剪映草稿json文件?
有没有摄像头捕获眼球转动操作鼠标的开源代码?
localstorage如何生成自增的键值对进行增删改查?
python有没有将python脚本与python运行环境一键打包成exe的代码?
nodejs如何执行浏览器中运行的js代码?
iframe中如何阻止其他域名网页的打开或跳转?
webrtc如何实现多人音频电话会议?
如何实现uni.connectSocket兼容web与小程序app端的websocket通讯?
webrtc如何浏览器中实现多人群音视频通话会议?
indexdb中的表结构与数据如何导出导入恢复?