【问题标题】:Locust is not running蝗虫没有跑
【发布时间】:2019-07-15 14:58:33
【问题描述】:

操作系统: Windows 7 **蝗虫版本:**0.11.0

我正在探索 locust 工具,看看我是否可以在我的项目中使用这个工具。

我创建了以下文件以进行动手操作,但显然脚本没有运行。

但我不确定原因。

有人可以帮帮我吗?

蝗虫.py

from locust import HttpLocust, TaskSet

def login(l):
    l.client.post("/login", {"username":"ellen_key", "password":"education"})

def logout(l):
    l.client.post("/logout", {"username":"ellen_key", "password":"education"})

def index(l):
    l.client.get("/")

def profile(l):
    l.client.get("/profile")

class UserBehavior(TaskSet):
    tasks = {index: 2, profile: 1}

def on_start(self):
    login(self)

def on_stop(self):
    logout(self)

class WebsiteUser(HttpLocust):
    task_set = UserBehavior
    min_wait = 5000
    max_wait = 9000

输出:-

工具一直运行如下。

【问题讨论】:

  • 你必须去localhost:8089运行它
  • 对我来说似乎是在运行。现在访问 web ui 并运行你的脚本
  • @DanielA.White 在命令行中指定主机时收到以下错误。 C DRive>locust -f IP ADDRESS:8089 Locustio.py [2019-07-15 23:11:51,436] DESKTOP-ER32D9B/ERROR/locust.main:找不到任何 locustfile!确保文件以 '.py' 结尾,并查看 --help 以获取可用选项。注意:.py 文件正确存在。
  • @CoreyGoldberg 我也无法通过网络访问。错误无法访问此站点 127.0.0.1 拒绝连接。

标签: locust


【解决方案1】:

使用默认参数,您需要访问localhost:8089 的网络监视器才能看到应用程序。

如果您想在没有 Web 前端的情况下运行,您需要指定参数(客户端、运行时、孵化率等),以便复制 Web 客户端参数。

【讨论】:

    【解决方案2】:

    使用以下参数以无头模式(无 UI)运行 locust 以自动开始测试

    locust -f locustio.py --headless -u 200 -r 10 --run-time 1h  
    

    -u 指定要生成的用户数。 -r 指定生成速率(每秒启动的用户数)。 如果要指定测试的运行时间,可以使用 --run-time-t

    您也可以使用 head/UI 运行 locust。

    locust -f locustio.py
    

    然后转到 Locust 的网页界面

    启动 Locust 后,您应该打开浏览器并将其指向 http://127.0.0.1:8089。然后你应该得到这样的问候:

    参考:https://docs.locust.io/en/stable/quickstart.html?#start-locust

    【讨论】:

      【解决方案3】:

      在 Windows 中,默认情况下 Web 主机正在侦听 IPv6,因此在使用 http://0.0.0.0:8089 访问站点时可能会产生 错误:无法访问此站点 127.0.0.1 拒绝连接。

      通过指定 web-host 作为参数运行 locust。然后网络就可以访问了。

      locust --web-host 0.0.0.0
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-10-13
        • 2019-01-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-04-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多