C/C++高频消息发送程序

发布于 2024-12-19 12:29:34 字数 284 浏览 2 评论 0原文

最近我接触到了 POCO 和 ACE 网络框架,以及我已经了解的 Boost。

我的问题是,这些库传递消息的速度是否比使用 Berkeley 套接字的常规 C 程序更快?这些库只是因为添加了多线程等功能而流行,这有助于提高性能吗?

我想在 Linux 上编写一个高性能消息系统,但我不知道是否应该避免 ACE 、 POCO 和 Boost 而只使用 Linux 线程操作系统函数和 berkeley 套接字?

换句话说,我并不关心通用代码、使我的代码“STL 友好”等。我只想要原始性能(无需编写汇编!)。

Recently I have come across the POCO and ACE networking frameworks, along with Boost which I already knew about.

My question is, are these libraries any faster for passing messages than just a regular C program with Berkeley sockets? Are these libraries only popular because they add in the features of multi-threading etc, which helps the performance factor?

I want to write a high-performance messaging system on Linux, but I cant work out if I should avoid ACE , POCO and Boost and instead just using the Linux thread OS functions along with berkeley sockets?

In other words, I am not bothered about generic code, making my code "STL friendly" etc. I just want raw performance (without having to write assembly!).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

挖个坑埋了你 2024-12-26 12:29:34

您看过 0MQ(又名 ZeroMQ) 了吗?引用自他们的网站:

ØMQ \zeromq\:
 Ø  The socket library that acts as a concurrency framework.
 Ø  Faster than TCP, for clustered products and supercomputing.
 Ø  Carries messages across inproc, IPC, TCP, and multicast.
 Ø  Connect N-to-N via fanout, pubsub, pipeline, request-reply.
 Ø  Asynch I/O for scalable multicore message-passing apps.
 Ø  Large and active open source community.
 Ø  30+ languages including C, C++, Java, .NET, Python.
 Ø  Most OSes including Linux, Windows, OS X.
 Ø  LGPL free software with full commercial support from iMatix.

Have you looked at 0MQ (aka ZeroMQ) yet? Quoting from their website:

ØMQ \zeromq\:
 Ø  The socket library that acts as a concurrency framework.
 Ø  Faster than TCP, for clustered products and supercomputing.
 Ø  Carries messages across inproc, IPC, TCP, and multicast.
 Ø  Connect N-to-N via fanout, pubsub, pipeline, request-reply.
 Ø  Asynch I/O for scalable multicore message-passing apps.
 Ø  Large and active open source community.
 Ø  30+ languages including C, C++, Java, .NET, Python.
 Ø  Most OSes including Linux, Windows, OS X.
 Ø  LGPL free software with full commercial support from iMatix.
想挽留 2024-12-26 12:29:34

您问了很多问题,但没有分享太多有关您的用例的信息。从您所写的内容来看,您似乎需要在连接到网络的计算机之间进行消息传递。都是点对点的,还是有些机器是“服务器”,而其他机器是客户端?诸如 ACE 这样的库提供了一切,从用于包装任何类型的套接字通信和多线程的简单便利类,到完整的服务器,几乎使用您能想到的任何模型。

假设您需要某种服务器,那么关于是否应该使用线程或单线程异步存在着很大的争论。同样,根据用例,一个会比另一个“更好”(这实际上取决于您需要做什么)。

在网络部分,您是否需要可靠的有序消息,或者当您能够检测到数据包丢失时,每条消息是否已过时?为了可靠性,您通常会在 TCP 之上构建,但根据您需要执行的操作,您可以在 UDP 上设计一个运行速度更快的协议。

除非您的需求非常简单和基本,并且/或您之前编写过大量网络多线程代码,否则您最好使用编写良好的包,而不是尝试自己重新发明所有内容。

You are asking a lot without sharing much about your use case. From what you write, it seems you need to do messaging between machines connected to a network. Is it all peer to peer, or are some machines "servers", and others clients? Libraries such as ACE offer everything from simple convenience classes for wrapping any type of socket communication and multithreading, up to full blown servers, using virtually any model you can think of.

Assuming you need some kind of servers, there's the whole debate about whether you should go with threading, or single threaded async. Again, depending on the use case, one will be "better" than the other (it really depends on what you need to do).

On the network part, do you need reliable ordered messages, or is each message obsolete by the time you would be able to detect that a packet got lost? For reliability you would typically build on top of TCP, but depending on what you need to do, you could design a protocol on UDP which will run faster.

Unless you requirements are really simple and basic, and/or you've written lots of networked multithreaded code before, you are most likely better off to use a well written package than trying to reinvent everything on your own.

旧情别恋 2024-12-26 12:29:34

免责声明:我写的。

如果您正在寻找原始速度,尤其是信号的多个订阅者和简单的集成,我们尝试使用 DSTC(分布式 C)

优点

  • 包含一个头文件,链接两个库。
  • 没有存根代码生成或奇怪的构建步骤。
  • 一行 C 代码即可导出或导入远程函数。
  • 使用单核,通过 10GB 以太网每秒进行 10M RPC 调用。
  • 在一台像样的笔记本电脑上通过本地主机每秒进行 20M 次调用。
  • C/C++/Python 支持。

缺点:

  • 没有安全性,它必须在受保护的环境中运行。
  • 原始。它只做两件事:RPC 和 pub/sub。
  • 尽管可以使用回调,但没有返回值。

Disclaimer: I wrote it.

If you are looking for raw speed, especially with multiple subscribers for a signal, and simple integration, we tried to solve that problem with DSTC (Distributed C).

Upsides

  • One header file to include, two libraries to link.
  • No stub code generation or weird build steps.
  • One line of C code to export or import a remote function.
  • 10M RPC calls / second over a 10GB Ethernet, using a single core.
  • 20M calls / sec over localhost on a decent laptop.
  • C/C++/Python support.

Downsides:

  • No security, it must run in a protected environment.
  • Primitive. It does only two things, RPCs and pub/sub.
  • No return values, although callbacks are available.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文