如何将不同的用户分配给蝗虫工人的不同“用户”实例?

发布于 2025-01-31 07:31:09 字数 1091 浏览 5 评论 0原文

我正在使用蝗虫进行性能测试,我想使用分布式负载功能。但是,在某种程度上,每个用户仅在一个会话中持续存在,因此每个用户实例应具有不同的登录用户。

在我的蝗虫文件的单个进程版本中,我使用一个全局集合到pop每个user实例的随机用户:

idle_users = {id for id in range(1, 65535)}

class MyUser(FastHttpUser):
    __user: int = None

    def get_one_user(self):
        global idle_users
        self.__user = idle_users.pop()

    def on_stop(self):
        global idle_users
        idle_users.add(self.__user)

我的问题是,当进入分布式版本时get_one_user,我如何访问全局idle_users设置,该设置位于一台计算机上的主实例上,从myuser在worker实例上产生那在另一台机器上吗?

请注意,我已经阅读了有关distribution-loading-loading 的文档,但是@events.test_start如果我希望在节点上的用户动态更改用户,那么Init似乎还为时过早。

更新:2022-05-24

关于用户的工作方式:myuser s登录,通过调用on_start 和通过on_stop登录。登录时,用户将从全局集合中随机获取。注销时,用户将被释放到全局集合,以便可以再次分发。也就是说,myuser实例中的用户以及剩余的IDLE_USERS在蜂拥而至时应动态更改。

I'm using Locust for performance testing, and I want to use the distributed load feature. However, there is some bound condition that each user persists for only one session so each user instance should have a different logged-in user.

In my single process version of the locust file, I use a global set to pop a random user for each User instance:

idle_users = {id for id in range(1, 65535)}

class MyUser(FastHttpUser):
    __user: int = None

    def get_one_user(self):
        global idle_users
        self.__user = idle_users.pop()

    def on_stop(self):
        global idle_users
        idle_users.add(self.__user)

My question is, When coming into a distributed version of get_one_user, how can I access the global idle_users set, which is on the master instance on one machine, from a MyUser spawning on a worker instance that is on another machine?

note that I've read the docs about the distributed-loading, but @events.test_start seems too early to init if I want the users on a node dynamically changes.

updated: 2022-05-24

About how the users work: MyUsers login by calling on_start and logout by on_stop. When logging in, a user is randomly fetched from the global set. When logout, the user is released to the global set so that it could be distributed again. That is, the users in MyUser instances and in remaining idle_users should dynamically change when swarming.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文