Boost Asio 沿一次性对象共享相同 io_service
Boost Asio share same io_service along disposible objects
我正在开发一个程序,它由一堆活动对象组成,可以相互发送消息。我正在使用一个相同的 io_service 来初始化所有这些对象。所以他们正在努力结束软件生命。
我正在使用活动对象,比方说,一个用于文件操作,另一个用于串行 IO,另一个用于本地数据库连接,一个用于通信所有这些。
但是我不能确定寿命短的物体。我正在使用短暂的对象打开 tcp 套接字以向远程端点发送快速消息,然后立即处理套接字。我正在考虑让这些也异步。
问题是,我应该为这些短暂的对象使用相同的 io_service 还是应该为每个套接字创建一个新的 io_service?
I'm developing a program, which consists of bunch of Active Objects, that sending messages to each other. I'm using one same io_service to initialize all these objects. So they're working to end of the software life.
听起来很合适。如果您需要在具有多个处理器的机器上提高操作效率,我建议使用 Chris Kohlhoff 的 recipe。
However I couldn't be sure about the objects with short lives. I'm using the short lived objects to open tcp socket to send a quick message to a remote endpoint then dispose the socket immediately. I'm thinking to make these also asynchronous.
拥有少量(呃)长期存在的 asio io_service 对象(例如,您可以创建与机器上的处理器数量相同的 io_service 对象)并没有什么错使用 io_service 的活对象。我会说这也更有效,因为您不必启动一个线程来调用 io_service::run
每个(短暂的?) io_service 并且您可以避免不必要的上下文切换。
如果您 want/need 避免在线程中阻塞,尤其是在存在网络问题等情况下,也需要使套接字异步。
我正在开发一个程序,它由一堆活动对象组成,可以相互发送消息。我正在使用一个相同的 io_service 来初始化所有这些对象。所以他们正在努力结束软件生命。
我正在使用活动对象,比方说,一个用于文件操作,另一个用于串行 IO,另一个用于本地数据库连接,一个用于通信所有这些。
但是我不能确定寿命短的物体。我正在使用短暂的对象打开 tcp 套接字以向远程端点发送快速消息,然后立即处理套接字。我正在考虑让这些也异步。
问题是,我应该为这些短暂的对象使用相同的 io_service 还是应该为每个套接字创建一个新的 io_service?
I'm developing a program, which consists of bunch of Active Objects, that sending messages to each other. I'm using one same io_service to initialize all these objects. So they're working to end of the software life.
听起来很合适。如果您需要在具有多个处理器的机器上提高操作效率,我建议使用 Chris Kohlhoff 的 recipe。
However I couldn't be sure about the objects with short lives. I'm using the short lived objects to open tcp socket to send a quick message to a remote endpoint then dispose the socket immediately. I'm thinking to make these also asynchronous.
拥有少量(呃)长期存在的 asio io_service 对象(例如,您可以创建与机器上的处理器数量相同的 io_service 对象)并没有什么错使用 io_service 的活对象。我会说这也更有效,因为您不必启动一个线程来调用 io_service::run
每个(短暂的?) io_service 并且您可以避免不必要的上下文切换。
如果您 want/need 避免在线程中阻塞,尤其是在存在网络问题等情况下,也需要使套接字异步。