
[英]Getting BlockingIOError (WinError 10035) when accepting a socket
[英]Unable to perform RMQ publish from Locust "BlockingIOError: [WinError 10035]"
我的项目需要客户端直接向 Rabbit MQ 发送消息,我们需要为此做负载测试。
我尝试了 PIKA,在普通的 python 文件中工作正常,但是当我尝试在 Locust 中实现它时,由于兼容性问题,我开始出现错误
我试过 PIKA Async、B-Rabbit 等。没有一个适用于 Locust(Gevent)
我不必与蝗虫集成,但只需在这些 python 文件上导入蝗虫就足以触发错误。
我在几个博客中读到 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()
错误:
BlockingIOError: [WinError 10035] A non-blocking socket operation could not be completed immediately
有人请让我知道解决这个问题的可能方法
注意:B-rabbit 确实说它是线程安全的,但是当我延迟 12 秒发布“从服务器读取超时”时它仍然会抛出错误,只有当我使用 locust 时才会发生这种情况,否则它很快
Pika 有一个GeventConnection
连接 class。这是你应该使用的。
注意: RabbitMQ 团队负责监控rabbitmq-users
邮件列表,有时只在 StackOverflow 上回答问题。
试过了
**Pika** = not compatible with Gevent Locust (esp windows)
**B-rabbit**, **Rabbit-py** = Slow with locust and times out
我可以确认Kombu与 Locust 完美配合,任何想用 Locust 实现队列的人都是这个解决方案
@卢克·巴肯:
我为我的公司使用我自己的定制框架,解耦这一点并不那么简单..所以我为 Kombu 创建了一个快速片段 class
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.