简体   繁体   English

无法从 Locust 执行 RMQ 发布“BlockingIOError:[WinError 10035]”

[英]Unable to perform RMQ publish from Locust "BlockingIOError: [WinError 10035]"

My project requires client sending messages directly to Rabbit MQ and we need to do load testing for this.我的项目需要客户端直接向 Rabbit MQ 发送消息,我们需要为此做负载测试。

I tried PIKA, works fine in a plain python file but as soon as I tried to implement this in Locust I start getting error due to compatibility issues我尝试了 PIKA,在普通的 python 文件中工作正常,但是当我尝试在 Locust 中实现它时,由于兼容性问题,我开始出现错误

I tried PIKA Async, B-Rabbit, etc.. none works with Locust(Gevent)我试过 PIKA Async、B-Rabbit 等。没有一个适用于 Locust(Gevent)

I dont have to integrate with locust but just importing locust on these python file is enough to trigger the error.我不必与蝗虫集成,但只需在这些 python 文件上导入蝗虫就足以触发错误。

I have read in several blogs that Gevent is not compatible with pika.我在几个博客中读到 Gevent 与 pika 不兼容。

class RMQ:

    def __init__(self) -> None:
        self.connection = pika.BlockingConnection(pika.ConnectionParameters('localhost', credentials=pcredentails))
        self.channel = self.connection.channel()

    def connect(self):
        self.channel.basic_publish(exchange='locust_events', routing_key='python3', body='Hello World!')
        print("[x] Sent 'Hello World!'")

    def close(self):
        self.channel.close()
        self.connection.close()

Error:错误:

BlockingIOError: [WinError 10035] A non-blocking socket operation could not be completed immediately

Some one please let me know a possible way to solve this有人请让我知道解决这个问题的可能方法

Note: B-rabbit did say it is thread safe but it still throws error when I publish "Time out reading from server" with 12s delay, this happens only when I use locust else it is fast注意:B-rabbit 确实说它是线程安全的,但是当我延迟 12 秒发布“从服务器读取超时”时它仍然会抛出错误,只有当我使用 locust 时才会发生这种情况,否则它很快

Pika has a GeventConnection connection class. That is what you should be using. Pika 有一个GeventConnection连接 class。这是你应该使用的。


NOTE: the RabbitMQ team monitors the rabbitmq-users mailing list and only sometimes answers questions on StackOverflow.注意: RabbitMQ 团队负责监控rabbitmq-users邮件列表,有时只在 StackOverflow 上回答问题。

Having tried试过了

**Pika** = not compatible with Gevent Locust (esp windows)

**B-rabbit**, **Rabbit-py** = Slow with locust and times out

I can confirm Kombu works perfectly with Locust, anyone looking to implement queues with locust this is the solution我可以确认Kombu与 Locust 完美配合,任何想用 Locust 实现队列的人都是这个解决方案

https://github.com/celery/kombu https://github.com/celery/kombu

在此处输入图像描述

@luke Bakken: @卢克·巴肯:

Im using my own bespoke framework for my company, its not so simple to decouple this bit.. so I created a quick snippet class for Kombu我为我的公司使用我自己的定制框架,解耦这一点并不那么简单..所以我为 Kombu 创建了一个快速片段 class

from locust import HttpClient, TaskSet, task, SingleRunner from kombu import Connection, Exchange, Queue from locust import HttpClient, TaskSet, task, SingleRunner 来自 kombu import Connection, Exchange, Queue

class KombuClient(HttpClient):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.connection = Connection('amqp://guest:guest@localhost:5672//')
        self.channel = self.connection.channel()

    def send_message(self, message):
        exchange = Exchange('test_exchange', type='direct')
        queue = Queue('test_queue', exchange, routing_key='test_key')
        queue.maybe_bind(self.connection)
        queue.declare()

        producer = self.connection.Producer(exchange=exchange, routing_key='test_key')
        producer.publish(message)
        print(" [x] Sent message: '{}'".format(message))

    def close_connection(self):
        self.connection.release()

class UserBehavior(TaskSet):
    @task
    def send_hello_message(self):
        self.client.send_message('Hello World!')

class WebsiteUser(HttpUser):
    tasks = [UserBehavior]
    min_wait = 5000
    max_wait = 9000
    client = KombuClient

def main():
    runner = SingleRunner(http_user_cls=WebsiteUser)
    runner.run(options={
        "host": "http://example.com",
        "num_users": 1000,
        "hatch_rate": 100
    })

if __name__ == "__main__":
    main()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM