将数据从 Django 传递到 C++申请及返回

发布于 2024-12-03 01:52:15 字数 296 浏览 4 评论 0原文

我们正在创建一个交易应用程序,其后端完全采用 C++(使用 QuickFix 引擎)。我们想在这个后端之上用 Django 构建一个 Web 应用程序,用户可以在其中下订单。 Django (python) 和 C++ 应用程序都将在自己的进程和地址空间中运行。您认为将订单/消息从 Django 传递到 C++ 的最佳想法是什么?

此外,这是一个交易应用程序,因此延迟是最大的问题。因此,我不想将订单从 Django 放入数据库,然后从 C++ 应用程序中获取。

我目前正在考虑通过共享内存或其他一些 IPC 机制来实现这一点。这是个好主意吗?

We are creating a trading application, where the backend is totally in C++ (using QuickFix engine). We would like to build a web application in Django on top of this backend, where the user can place his orders. Both the Django (python) and the C++ application will be running in their own processes and address space. What do you think would be the best idea to pass orders/messages from Django to C++?

Also, this is a trading application, so latency is the biggest concern. So, I do not want to put orders into a database from Django and then fetch from C++ application.

I'm currently looking at doing it via shared memory or some other IPC mechanism. Is this a good idea?

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

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

发布评论

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

评论(5

初熏 2024-12-10 01:52:15

那么你必须使用一些 IPC 方法。这里没有提到的是让 C++ 进程监听套接字。这将增加灵活性(具有轻微的速度成本),这些进程甚至不需要在同一台机器上。

我一直在做类似的事情,来自 C++,但想用 python 编写 UX。我的计算后端是 C++,我编译一个 python 模块并使用 Flask 为 UX 生成 html。我的 C++ 和 python 生活在同一个进程中,所以我还没有在实践中解决你的核心问题。

我给出的一个建议是,将所有 IPC 内容保留在 C++ 中,并使用 Boost.Python 在 C++ 中编写一个小型 Python 模块。这将使 python 进程完成 pythony 世界中 95% 的工作,同时为您提供作为 C++ 开发人员所希望的对发送到 C++ 的数据的位级信心。 Boost.Python 使桥接 C++ 和 python Web 框架对我来说变得轻而易举。

Well you have to use some IPC method. One that you don't mention here is having the C++ process listen to a socket. That would add in flexibility (with slight speed cost) that the processes don't even need to be on the same machine.

I've been doing a sort of similar thing, coming from C++ but wanting to write UX in python. My computational backend is C++, and I compile a python module and generate html with flask for the UX. My C++ and python live in the same process so I haven't addressed your core question in practice yet.

One piece of advice I would give is to keep all of your IPC stuff in C++, and write a small python module in C++ using Boost.Python. This will let the python process doing 95% of the work in a pythony world, but give you the bit-level confidence I would want as a C++ dev for the data you are sending over to C++. Boost.Python has made bridging C++ and python web frameworks a breeze for me.

是伱的 2024-12-10 01:52:15

您必须提出一个现有协议或创建您自己的协议,以允许 C++ 和 Python 之间进行通信。我认为最简单的方法是使用一些 IPC,例如 ZeroC IceCORBA。或者,您可以将本机 C++ 代码放入 Python 并从 Django 使用它,也可以使用 QuickFIX。

如果您真的担心延迟(至少毫秒很重要,而不是纳秒) - 你根本不应该使用 QuickFIX 或 Python。

You have to come up with an existing protocol or create your own protocol that will allow communication between C++ and Python. The easiest way I believe would be to use some IPC like ZeroC Ice, or CORBA. Alternatively, you can throw in a native C++ code into Python and use that from Django, that could as well use QuickFIX.

And if you are really concerned about latency (at least milliseconds matter, not saying about nanoseconds) - you shouldn't use QuickFIX or Python at all.

懷念過去 2024-12-10 01:52:15

我会为 IPC 使用 zeromq

I would use zeromq for the IPC

情仇皆在手 2024-12-10 01:52:15

我可能会选择类似 JSON-RPC 并通过本地套接字或命名管道进行通信。

共享内存速度更快,但如果您必须自己执行此操作,则很难做到这一点(这意味着并发和锁定,在我看来,应该尽可能避免。)

这取决于消息大小和延迟要求。你总是可以尝试一种可以在共享内存上工作的 IPC 机制,就像下面评论中提到的 vlad 一样。

(请注意,拥有一个可以依靠管道/套接字的 IPC 系统可能是一件好事,以防您将来需要对系统进行集群)。

I'd probably go for something like JSON-RPC and communicate over local sockets or named pipes.

Shared memory is faster, but trickier to get right if you have to do it yourself (it implies concurrency and locking, which, IMO, one should avoid if possible.)

It depends on message sizes and latency requirements. And you could always try an IPC mechanism that can work over shared memory, like vlad mentions in the comment below.

(Do note that having an IPC-system thatn can fall back on pipes/sockets might be a good thing, in case you need to cluster your system in the future).

嗳卜坏 2024-12-10 01:52:15

您应该/可以将微服务架构与消息代理一起使用,这样您就无法轻松地将应用程序彼此连接起来。

You sould/can use Microservice Architecture with message-brokers so you cant easily connect your apps to each other.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文