短耳提升单线程性能 [英] Boost Asio single threaded performance

查看:123
本文介绍了短耳提升单线程性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现,需要保持长期生活的连接非常大的数字(10万以上)的自定义服务器。服务器简单地插座之间传递消息,它不会做任何严重的数据处理。消息虽小,但很多都是接受/发送每一秒。减少延迟的目标之一。我认识到,使用多个内核不会提高性能,因此我决定打电话给在单线程运行服务器 run_one 调查 io_service对象对象>方法。反正多线程服务器将更难实现。

I am implementing custom server that needs to maintain very large number (100K or more) of long lived connections. Server simply passes messages between sockets and it doesn't do any serious data processing. Messages are small, but many of them are received/send every second. Reducing latency is one of the goals. I realize that using multiple cores won't improve performance and therefore I decided to run the server in a single thread by calling run_one or poll methods of io_service object. Anyway multi-threaded server would be much harder to implement.

什么是可能的瓶颈?系统调用,带宽,完成队列/事件多路分离?我怀疑,调度处理程序可能需要锁定(由ASIO库内部完成的)。是否有可能在Boost.Asio的禁用甚至队列锁(或其他锁定)?

What are the possible bottlenecks? Syscalls, bandwidth, completion queue / event demultiplexing? I suspect that dispatching handlers may require locking (that is done internally by asio library). Is it possible to disable even queue locking (or any other locking) in boost.asio?

编辑:相关的问题。是否系统调用性能多线程改进?我的感觉是因为系统调用是原子/内核加入更多的线程不会提高速度保持同步。

related question. Does syscall performance improve with multiple threads? My feeling is that because syscalls are atomic/synchronized by the kernel adding more threads won't improve speed.

推荐答案

您可能需要阅读我的问题从几年前,我问它,当第一次调查Boost.Asio的的可扩展性,同时开发用于蓝色基因/ Q超级计算机

You might want to read my question from a few years ago, I asked it when first investigating the scalability of Boost.Asio while developing the system software for the Blue Gene/Q supercomputer.

缩放到100K或多个连接不应该是一个问题,但你需要知道的明显的资源限制,如打开的文件描述符的最大数量。如果你还没有看过开创性 C10K纸,我建议阅读。

Scaling to 100k or more connections should not be a problem, though you will need to be aware of the obvious resource limitations such as the maximum number of open file descriptors. If you haven't read the seminal C10K paper, I suggest reading it.

在您已实现使用单线程和单一的 io_service对象,我建议研究一个线程调用 io_service对象::运行库(你的应用程序),然后才寄希望于调查的 io_service对象来一个特定的线程和/或CPU。有包括短耳文档所有这三个设计的多个实例,并几个问题提供更多信息,以便对的。要知道,当你引进多个线程调用 :: io_service对象的run()则可能需要实施 s到保证处理程序必须共享数据结构独占访问。

After you have implemented your application using a single thread and a single io_service, I suggest investigating a pool of threads invoking io_service::run(), and only then investigate pinning an io_service to a specific thread and/or cpu. There are multiple examples included in the Asio documentation for all three of these designs, and several questions on SO with more information. Be aware that as you introduce multiple threads invoking io_service::run() you may need to implement strands to ensure the handlers have exclusive access to shared data structures.

这篇关于短耳提升单线程性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆