【分享】对无锁队列boost::lockfree::queue和moodycamel::ConcurrentQueue做一个性能对比测试

people waiting in row

people waiting in queue

本文我觉得对比测试挺有意义,适合给开发人员提供参考,故转载于此。

原文链接:

evpp性能测试(3): 对无锁队列boost::lockfree::queue和moodycamel::ConcurrentQueue做一个性能对比测试

我只贴出测试结果
当我们只有生产者和消费者都只有一个时,大多数测试结果表明moodycamel::ConcurrentQueue的性能是最的,大概比queue with std::mutex高出10%~50%左右的性能。boost::lockfree::queue比queue with std::mutex的性能只能高出一点点。由于我们的实现中,必须要求能够使用多生产者的写入,所以并没有测试boost中专门的单生产者单消费者的无锁队列boost::lockfree::spsc_queue,在这种场景下,boost稍稍有些吃亏,但并不影响整体测试结果及结论。

 
当我们有多个生产者线程和一个消费者线程时,boost::lockfree::queue的性能比queue with std::mutex高出75%~150%左右。 moodycamel::ConcurrentQueue的性能最,大概比boost::lockfree::queue高出25%~100%,比queue with std::mutex高出100%~500%。当生产者线程越多,也就是锁冲突概率越大时,moodycamel::ConcurrentQueue的性能优势体现得更加明显。

另外多说一点,该作者evpp性能测试都挺不错,具有参考意义,有兴趣可以参考更多性能对比:

evpp性能测试(1): 与muduo进行吞吐量测试

evpp性能测试(2): 与Boost.Asio进行吞吐量对比测试

文章的脚注信息由WordPress的wp-posturl插件自动生成



|2|left
打赏

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: