简体   繁体   English

boost::interprocess message_queue 性能 - 相当慢?

[英]boost::interprocess message_queue performance - rather slow?

I need an ultra-fast MQ mechanism, where both sender and receiver are written in C++, on Windows platform.我需要一个超快的 MQ 机制,发送方和接收方都用 Windows 平台上的 C++ 编写。

My current implementation using RCF-C++ for IPC is clocking at around 20,000 msg/sec over Windows Named Pipes.我当前使用RCF-C++进行 IPC 的实现在 Windows 命名管道上的时钟速度约为 20,000 msg/sec。

I am testing the perf of boost::interprocess Message Queues according to the demo app , and am measuring around 48,000 messages/sec, which is surprisingly slow, considering that when I cooked up a simple Memory Mapped File communication on the same machine (in C# using code from this blog post ), I got around 150,000 messages/sec.我正在根据演示应用程序测试 boost::interprocess Message Queues 的性能,并且测量到大约 48,000 条消息/秒,考虑到当我在同一台机器上制作一个简单的 Memory 映射文件通信时(在C# 使用此博客文章中的代码),我每秒收到大约 150,000 条消息。

Any idea about why I'm getting such slow performance out of boost message_queue, and what I can try to improve it?关于为什么我从 boost message_queue 中获得如此缓慢的性能以及我可以尝试改进它的任何想法?

Daniel's answer is part of it, but there is a bigger issue here: boost::interprocess basically maintains the queue as an array in shared memory, and upon sending a message, the boost::interprocess:message_queue does a binary search based on the new message's priority to find where the message should be placed in the array, and then std::backward_copy s all the other messages to make room for it.丹尼尔的回答是其中的一部分,但这里有一个更大的问题: boost::interprocess 基本上将队列维护为共享 memory 中的数组,并且在发送消息时, boost::interprocess:message_queue 基于新消息的优先级来查找消息应该放在数组中的哪个位置,然后std::backward_copy为所有其他消息腾出空间。 If you always use the same priority, your message will be placed at the beginning (since it's the newest), and so whatever messages you have in the buffer at that time will be backwards_copied to make room for it, which takes time.如果您始终使用相同的优先级,则您的消息将被放置在开头(因为它是最新的),因此您当时在缓冲区中的任何消息都将被向后复制以腾出空间,这需要时间。 (See implementation of the queue_free_msg method). (参见queue_free_msg方法的实现)。

If you don't need messages to have priorities, and just want a regular FIFO queue, then this approach is a lot slower than using a Circular Buffer : the performance of insertions (sends) deteriorates rapidly as the size of the queue grows.如果您不需要消息具有优先级,而只需要一个常规的 FIFO 队列,那么这种方法比使用循环缓冲区要慢得多:插入(发送)的性能会随着队列大小的增长而迅速恶化。

UPDATE: I wrote a version of the message_queue that uses a circular buffer internally, with help from the notes on wikipedia , and this was a big success.更新:在 wikipedia 上的注释的帮助下,我编写了一个在内部使用循环缓冲区的 message_queue 版本,这是一个巨大的成功。

As Boost document states , boost::interprocess::shared_memory_object is implemented using memory mapped file in Win32.正如 Boost 文档所述,boost::interprocess::shared_memory_object 是使用 Win32 中的memory映射文件实现的。 And, boost's message queue is using that simulated shared memory object as well.而且,boost 的消息队列也在使用模拟的共享 memory object。 (For native Win32 shared memory, boost provides windows_shared_memory class separately.) (对于原生 Win32 共享 memory,boost 单独提供 windows_shared_memory class。)

For better performance of message queue, therefore, you have to implement your own version of message queue using native Win32 shared memory object.因此,为了获得更好的消息队列性能,您必须使用本机 Win32 共享 memory object 实现自己的消息队列版本。 In my experiments, after replacing it, performance increased noticeably.在我的实验中,更换它后,性能明显提高。

Note that, if you change to Win32 native shared memory, you must take care of 'deletion' of the shared memory.请注意,如果您更改为 Win32 本机共享 memory,则必须注意“删除”共享 memory。 POSIX shared memory and Win32 shared memory has different policy of deletion. POSIX 共享 memory 和 Win32 共享 memory 有不同的删除策略。

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

相关问题 boost interprocess message_queue和fork - boost interprocess message_queue and fork boost :: interprocess :: message_queue权限被拒绝 - boost::interprocess::message_queue permission denied boost::interprocess::message_queue 在第二个进程中没有收到消息 - boost::interprocess::message_queue no message received in second process boost :: interprocess message_queue-Windows 7低完整性进程 - boost::interprocess message_queue - Windows 7 low integrity process 使用boost :: interprocess :: message_queue多个应用程序安全吗? - Is it safe to consume a boost::interprocess::message_queue multiple applications? 错误:“ size_type”不是“ boost :: interprocess :: message_queue”的成员 - error: ‘size_type’ is not a member of ‘boost::interprocess::message_queue’ boost :: interprocess :: message_queue使用Visual C ++停止在发布模式下工作 - boost::interprocess::message_queue stops working in Release mode with visual C++ Boost进程间message_queue具有非常量get_num_msg()。 为什么? - Boost interprocess message_queue has non const get_num_msg(). Why? 我可以通过boost :: interprocess :: message_queue发送C ++类对象吗? - Can I send a C++ class object via boost::interprocess::message_queue? 如何知道boost :: interprocess :: message_queue已从系统中删除? - How to get know that boost::interprocess::message_queue was removed from system?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM