简体   繁体   English

Chronicle Queue:多路复用生产者写入单个队列的推荐方法是什么?

[英]Chronicle Queue: What is the recommended way to multiplex producers to write into a single queue?

Let there be 5 producer threads, and 1 queue.假设有 5 个生产者线程和 1 个队列。 It seems like I have 2 options:好像我有两个选择:

  • create an appender for each producer thread, append concurrently and let chronicle queue deal with synchronization (enable double-buffereing?)为每个生产者线程创建一个 appender,并发 append 并让编年史队列处理同步(启用双缓冲?)

  • synchronize the 5 producer threads first (lockfree mechanism eg disruptor), create 1 extra thread with 1 appender that writes into chronicle queue首先同步 5 个生产者线程(无锁机制,例如 disruptor),创建 1 个额外的线程和 1 个写入编年史队列的附加程序

Why this question?为什么这么问?

I had the initial impression that writing to a chronicle queue is lock-free and should therefore be really fast.我最初的印象是写入编年史队列是无锁的,因此应该非常快。 But github documentation mentioned multiple times there is a write lock that serializes concurrent writes.但是 github 文档多次提到有一个写锁可以序列化并发写入。 So I wonder if a lockfree disruptor placed in front of the chronicle queue would increase performance?所以我想知道在编年史队列前面放置一个无锁干扰器是否会提高性能?

What you suggest can improve the writer's performance, esp if you have an expensive serialization/marshalling strategy.你的建议可以提高作者的表现,特别是如果你有一个昂贵的序列化/编组策略。 However, if you are writing to a real disk, you will find the performance of the drive is possibly your biggest issue.但是,如果您正在写入一个真正的磁盘,您会发现驱动器的性能可能是您最大的问题。 (Even a fast NVMe drive) You might find the time to read the data is worse. (即使是快速的 NVMe 驱动器)您可能会发现读取数据的时间更短。

Let's say you spend 1 microsecond writing a 512-byte message, and you are writing at 200K/s messages.假设您花费 1 微秒编写一条 512 字节的消息,并且您正在以 200K/s 的速度编写消息。 This means that your 80%ile will be an extra 1 us waiting for the queue due to contention.这意味着您的 80%ile 将因争用而额外等待队列 1 us。 However, you will be writing 360 GB/h as will very quickly fill a fast NVMe drive.但是,您将以 360 GB/h 的速度写入,因为这将很快填满一个快速 NVMe 驱动器。 If instead, you have a relatively low volume of 20K/s messages, you are increasing your 98%ile latency by 1 us.相反,如果您的 20K/s 消息量相对较少,则您将 98%ile 延迟增加了 1 us。

In short, if write contention is a problem, your drive is probably a much bigger problem.简而言之,如果写争用是一个问题,那么您的驱动器可能是一个更大的问题。 Adding a disruptor could help the writer, but it will delay the read time of every message.添加干扰器可以帮助编写者,但它会延迟每条消息的读取时间。

I recommend building a latency benchmark for a realistic throughput first.我建议首先为实际吞吐量构建延迟基准。 You can double buffer the data yourself by writing first to a Wire and only copying the bytes while holding the lock.您可以通过先写入 Wire 并仅在持有锁时复制字节来自己双重缓冲数据。

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

相关问题 编年史队列-阅读器修改msg - Chronicle Queue - reader modifying msg 使用ScheduledThreadPoolExecutor建立有界队列的最佳方法是什么? - What is best way to have Bounded Queue with ScheduledThreadPoolExecutor? Java“分层队列”实现快速生产者,减缓消费者 - Java “Tiered Queue” implementation for fast Producers, slow Consumers 在两个生产者和一个消费者的线程安全队列中提升条件不起作用 - boost conditional not working on thread safe queue with two producers and one consumer 并发访问队列(多个生产者和消费者)的问题-C ++,Boost - Issue with Concurrent Access of a Queue (Multiple Producers and Consumers) - C++, Boost .NET 在单独(单)线程上管理任务队列的最佳方式 - Best way in .NET to manage queue of tasks on a separate (single) thread dispatch_queue_create中的队列属性是什么 - What is queue attributes in dispatch_queue_create Java:具有长期使用者的并发队列以及短期生产者的处理保证 - Java: Concurrent queue with long-lived consumers and processing guarantees for short-lived producers 从队列中取出的正确方法? - Correct way to take from queue? GCD 中的“全局队列”和“主队列”有什么区别? - What's the difference between the “global queue” and the “main queue” in GCD?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM