如何测量消息到达RabbitMQ消息队列所花费的时间?
我有一个生产者类,它将消息发送到消息代理 RabbitMQ。 我正在使用 Quartz 调度程序定期发送消息。
我想测量单个作业执行/完成所需的时间。 我该怎么办?
我想找到一段时间内完成一项工作所需的平均时间。所以我想测量每个单独的时间,然后找到平均值。
I have a producer class which sends messages to a message broker, RabbitMQ.
I am using Quartz scheduler to send the messages at regular intervals.
I want to measure the time taken for a single job to get executed/completed.
How do I go about it?
I want to find the average time it takes for a job to be completed over a period of time. So I want to measure each individual time and then find the mean.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我过去采取的方法是创建一个作业日志队列,该队列采用作业名称、开始时间、结束时间的简单数据结构,并在每个作业完成后,将包含该信息的消息发送到作业记录队列。
然后,只需编写一个侦听器,从作业日志记录队列中提取数据并将其写入数据库,更新用于报告的内部内存结构,发送电子邮件等。这一切都假设您有权更改以下代码:执行工作。
如果你没有机会获得这些工作,那就更难了。 RabbitMQ 有一个插件 API,因此您可以构建一个插件来计算每个特定作业需要多长时间。 rabbitmq 管理插件 将为您提供粗粒度指标,例如每秒发送或确认的消息数/ 秒。确认通常表示任务完成,但根据代码的构建方式,作业可能会在完成之前得到确认,在这种情况下,您唯一的选择是更改执行作业的代码。
The approach I've taken to this in the past is to create a job logging queue that takes a simple data structure of job name, start time, end time and after the completion of each job, send a message with that information to a the job logging queue.
Then, just write a listener that pulls data out of the job logging queue and either writes it to a database, updates an internal memory structure for reporting, sends an email, etc. This all assumes that you have access to change the code that is performing the jobs.
If you don't have access to the jobs, it will be harder. RabbitMQ has a plug-in API, so you could build a plug-in that calculates how long each particular job takes. The rabbitmq management plugin will give you coarse grain metrics, such as number of messages delivered / sec or acknowledged / sec. An acknowledgement ususally indicates completion of a task, but depending on how you the code is built a job could be acknowledged before completion in which case your only option is to change the code performing the job.