压测RabbitMQ消费能力
最近运维反馈线上监控到消费RabbitMQ消息队列过慢,目前只有20左右,监控平台会有消息积压的告警。
开发修改了一版应用服务的版本,提交给我做压测验证。
之前没有做过消息中间件的压测,网上找了一圈测试方法,并且和开发沟通,最终确认通过压测RabbitMQ event消息处理的接口来完成本次的压测验证。
压测脚本:
import pika
import multiprocessing as mp
import time
def main(counter):
routing_key = "busi.mc.event.XXXX" # 被压测的应用服务的key,指定消息的消费者
credentials = pika.PlainCredentials('guest', 'guest')
parameters = pika.ConnectionParameters('XXX.XX.XXX.XX',
5672,
'/',
credentials)
connection = pika.BlockingConnection(parameters) # 连接 RabbitMQ
channel = connection.channel() # 创建频道
for i in range(1, counter): # 循环生产信息,供消费者(被压测的应用服务)消费
channel.basic_publish(exchange='mc-direct-exchange', routing_key=routing_key,
body='{"clientId":"5e8J8aoi4F380gpDS4sdfd","eventType":1}',
properties=pika.BasicProperties(
content_type="text/plain",
delivery_mode=1))
time.sleep(0.1)
# if counter % 600 == 0:
# time.sleep(1)
connection.close() # 关闭连接
def loop_test(counter):
for i in range(1, counter):
main()
if counter % 100 == 0:
time.sleep(1) # 单个频率
if __name__ == "__main__":
# Define an output queue
output = mp.Queue()
# Setup a list of processes that we want to run
processes = [mp.Process(target=main, args=(100000,)) for x in range(20)] # 消息总条数 并发数
# Run processes
for p in processes:
p.start()
# Exit the completed processes
for p in processes:
p.join()
# Get process results from the output queue
# results = [output.get() for p in processes]
# print(results)
脚本运行后,通过RabbitMQ的web管理后台,查看消费消息的TPS已经可以稳定在200左右,本次验证通过了~~
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)