在 C++ 创建高性能网络服务器
我需要用 C++ 为交易应用程序创建一个网络服务器。该网络服务器需要执行以下任务:
处理客户端身份验证并为每个客户端提供会话 ID session.
处理来自客户的订单并通知客户 他们的执行。
处理客户端要求的其他数据请求并将数据发送回 处理
我计划使用 Boost.Asio 网络库和 Google 协议缓冲区来实现从客户端发送到服务器的消息。基于 XML-RPC 或 SOAP 的方法是严格禁止的,因为延迟是一个大问题。
我向 stackoverflow 社区提出以下问题:
使用协议实现这些消息是个好主意吗 缓冲区?我也在考虑发送消息Boost序列化 库来实现这一点。当我查看代码时,我发现自己 更有信心通过增强序列化来实现这一点,并且 Google protobuf 标头看起来太重量级了。这些方法中哪一个 会a)更易于维护并且b)需要更少的努力吗?我猜, 这两种方法都可以跨不同平台工作。
是否还有其他我应该单独查看的网络库 来自 Boost.Asio。?就 C++ 编码而言,我发现 ACE 有点过时了 风格很重要。
最终我想让这个网络服务器在 SSL 上运行, 但是,我没有任何实施 SSL 的经验。如何 以后迁移到 SSL 需要付出很大的努力。我应该开始吗 使用 SSL 还是可以稍后添加?
有人知道一个好的开源网络项目吗? 使用 Boost.Asio 实现了类似的网络服务器,以获得 受到启发吗?
I need to create a network server in C++ for a trading application. This network server needs to perform the following tasks:
handle authentication of clients and provide session id for each
session.handle orders originating from the clients and inform clients about
their execution.handle other data request asked for by the clients and send data back
to them.
I am planning to use Boost.Asio networking library and Google protocol buffers to implement the messages being sent from the clients to the server. XML-RPC or SOAP based approaches are a strict no-no as latency is a big concern.
I have the following questions for the stackoverflow community:
Is it a good idea to implement these messages using protocol
buffers? I am also considering sending messages Boost serialization
library to implement this. When I look at the code, I find myself
more confident of implementing this with boost serialization and
Google protobuf headers look too heavyweight. Which of these methods
will be a) more maintainable and b) require less effort? I guess,
both these approaches will work across different platforms.Is there any other networking library which I should look at apart
from Boost.Asio.?I find ACE a little dated as far as C++ coding
style is concerned.Eventually I would like to make this network server run on SSL,
however, I do not have any experience with implementing SSL. How
much effort would it require to move to SSL later on. Should I start
with SSL or can it be added later on?Does anybody know of a good open source network project, which might
have implemented a similar network server using Boost.Asio, to get
inspired from?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您还应该查看 Apache Thrift(源自 Facebook)或 Apache Etch(最初由思科开发)。它们是 RPC 框架,可以轻松开发满足您的需求(或多或少)的服务器和客户端。有关使用 protobuf 和 boost.asio 开发的框架,请查看 server1 项目。
You should also look at Apache Thrift (originated at Facebook) or Apache Etch (initially developed by Cisco). They are RPC frameworks that make it easy to develop both servers and clients meeting your needs (more or less). For a framework developed using protobuf and boost.asio, look at the server1 project.
BSON ( http://www.mongodb.org/display/DOCS/BSON 和 < a href="http://bsonspec.org" rel="nofollow">http://bsonspec.org )是一种非常快速的二进制协议。 C++ 实现可以从 mongodb 轻松获得。事实上,它基本上是 JSON,这使得它非常容易实现和维护。
SSL 实现不会向基于 asio 的服务器添加太多额外代码:使用证书路径和一些握手逻辑进行 SSL 上下文初始化。
BSON ( http://www.mongodb.org/display/DOCS/BSON and http://bsonspec.org ) is a very fast binary protocol. C++ implementation is readily available from mongodb. The fact that it is basically JSON makes it quite easy to implement and maintain.
SSL implementation doesn't add up much extra code to the asio-based server: SSL context initialization with certificate paths and some handshake logic.
您应该查看 MessagePack http://msgpack.org/
You should look into MessagePack http://msgpack.org/
如果您被允许购买现成的网络库,请查看 JetBytes 服务器框架 满足您的网络需求。我记得读到过它为 PayPoint 带来了繁重的工作。 Len Holgate(公司和图书馆的幕后黑手)在这些论坛上很活跃。
If you are allowed to purchase off the shelf library for networking then take a look at JetBytes Server Framework for your networking needs. I remember reading that it did the heavy lifting for the PayPoint. Len Holgate (the man behind the company and the library) is active on these forums to.
看看 www.zeromq.org
它并不完全是你所要求的,但它肯定会解决你的问题并加速你的开发。
Zeromq 是一个轻量级消息队列,具有多种不同的传输方式,并且具有多种语言的绑定。
它也被用于很多交易服务器。
Take a look into www.zeromq.org
It's is not exactly what you asked, but it is something that will definitively solve your problem and speed up your development.
zeromq is a lightweight message queue, with a lot of different transports, and it has bindings for a lot of languages.
It is also used in a lot of trading servers.
我参加聚会有点晚了 - 但我想把 POCO (http://pocoproject.org/) 扔进戒指也是如此。我不会说它比 ASIO 更好(因为它不是),但它同样好。如果您不是模板之神 - 您会发现 POCO 令人愉快。绝对是比 ACE 更好的选择,因为 ACE 已经有点久远了。
I'm kinda late to the party - but I wanted to throw POCO (http://pocoproject.org/) into the ring as well. I wont say it is better than ASIO (because it isn't) but it is as good. And if you are not a template god - you will find POCO delightful. Definitely a better bet than ACE which is getting a little long in the tooth.
如果您从一开始就拥有 SSL,那么您可以拥有服务器和客户端身份验证,这将涵盖
无需向客户端/服务器应用程序添加额外的自定义身份验证即可完成此任务。
If you have SSL from the beginning then you can have server and client auth which would cover
this task without having to add additional custom auth to your client/server apps.