交易应用程序权衡:数据库和低延迟

发布于 2024-12-03 03:55:48 字数 231 浏览 3 评论 0原文

几乎每个业务应用程序都需要数据库来存储数据以及针对该数据完成的事务。交易通常需要几毫秒的时间。同时,在交易应用程序中,根本不可接受的一件事是“延迟”。那么,在此类需要延迟上限的应用程序中需要进行哪些权衡呢?

例如,客户已经进行了一笔交易,它必须通过一些检查,这些检查存储在数据库中,需要数据库获取。然后,交易应传递至 OMS/ORS 或交易所。而且,在每一层,都需要在数据库中存储某种交易数据。如何在事务持久性和低延迟之间保持平衡?

Databases are required for almost every business application to store data and the transactions done on that data. The transactions typically take a time of the order of milliseconds. At the same time, in a trading application the one thing which is not at all acceptable is "latency". So, what are the trade-offs made in such applications which require an upper limit on latency?

For example, a trade has been placed by the customer, it must pass a few checks, which are stored in the database, requiring a DB fetch. Then, the trade should be passed on to an OMS/ORS or the exchange. And, at each layer, it would be required to store some sort of transaction data in the database. How should one maintain a balance between transaction persistence and low-latency?

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

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

发布评论

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

评论(2

眉目亦如画i 2024-12-10 03:55:48

两件事:

  • 缓存:在应用程序中缓存规则,这样您就不需要为每笔交易都访问数据库
  • 线程:将在数据库中存储交易数据的代码放入另一个线程中。这样,您可以立即将交易发送至交易所,并同时保护数据库中的数据。

Two things:

  • Caching: Cache the rules in your application, so you don't need to hit the database for every trade
  • Threading: Put the code that stores the transaction data in the database into another thread. Like this, you can route the trade to the exchange immediately and safe the data in the database parallel to that.
笑梦风尘 2024-12-10 03:55:48

如今,人们使用内存事务系统,因此可以减少数据库带来的网络延迟。

这里有一些你可以考虑的低延迟的事情

  • 为了在java中实现低延迟,你必须控制java中的GC,有很多方法可以做到这一点,例如预分配对象(即使用享元设计模式),使用原语对象 - trove 非常适合这一点,所有数据结构都基于原语,重用对象实例,例如创建系统范围的字典以减少创建新对象,从流/套接字/数据库读取数据时非常好的选择

- 尝试减少争用使用免等待算法(这有点困难),无锁算法。您可以找到大量的示例

- 使用内存计算。内存很便宜,内存中可以存储万亿字节的数据。

-使用机械同情-参考lmax Disruptor,优秀的框架

Now a days people use in-memory transaction system, so you cut down network latency that you get by database.

Here are some things that you can consider for low latency

  • To achieve low latency in java you have to take control of GC in java, there are many ways to do that for eg pre-allocate objects(i.e use flyweight design pattern), use primitive objects - trove is very good for that, all data structure are based on primitive, Reuse object instance for eg create system wide dictionary to reduce creating new objects, very good option when reading data from stream/socket/db

-Try to reduce contention use wait-free algo( which is bit difficult), lock free algo. You can find tons of example for that

-Use in-memory computing. Memory is cheap, you can have tera byte of data in memory.

-Use mechnical sympathy - Refer lmax disruptor, excellent framework

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