如何使用BigDecimal会影响应用程序性能? [英] How using BigDecimal would affect application performance?

查看:153
本文介绍了如何使用BigDecimal会影响应用程序性能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用BigDecimal来表示低延迟交易应用程序中的任意精度数字,如价格和金额,每秒有数千个订单和执行报告。

I want to use BigDecimal to represent arbitrary precision numbers like prices and amounts in a low-latency trading application with thousands of orders and execution reports per second.

我不会对它们进行很多数学运算,所以问题不在于BigDecimal本身的性能,而在于大量BigDecimal对象的性能影响应用程序的性能。

I won't be doing many math operations on them, so the question is not about performance of the BigDecimal per se, but rather about how large volumes of BigDecimal objects would affect performance of the application.

我担心的是,大量短命的BigDecimal对象会给GC带来压力并导致更大的Stop-The-World暂停在CMS收集器中 - 这绝对是我想避免的。

My concern is that huge amount of short-lived BigDecimal objects will put a strain on a GC and result in larger Stop-The-World pauses in CMS collector - and this is definitely what I would like to avoid.

您能否确认我的疑虑并建议使用BigD的替代方案?此外,如果您认为我的担忧是错误的 - 请解释原因。

Can you please confirm my concerns and suggest alternatives to using BigD? Also, if you think my concerns are wrong - please explain why.

更新

感谢所有回答的人。我现在确信使用BigDecimal会损害我的应用程序的延迟(即使我仍然计划测量它)。

Thanks for all who answered. I am now convinced that using BigDecimal will hurt latency of my application (even though I still plan to measure it).

目前我们决定坚持非常非OOP解决方案(但没有精确命中) - 使用两个 int s,一个用于尾数,另一个用于指数。这背后的基本原理是基元放在堆栈上,而不是堆,因此不受垃圾收集。

For the time being we decided to stick with "very non-OOP" solution (but without accuracy hit) - use two ints, one for mantissa and another one for exponent. Rationale behind this is that primitives are placed on stack, not heap, and hence are not subject to garbage collection.

推荐答案

如果你正在开发一个低延迟交易程序,你真的想在延迟方面竞争,然后 BigDecimal 不适合你,就这么简单。微秒很重要,对象创建和任何十进制数学都太贵了。

If you are developing a low-latency trading program and you genuinely want to compete in latency terms, then BigDecimal is not for you, it is as simple as that. Where microseconds matter, object creation and any decimal math is just too expensive.

我认为几乎其他所有人,使用 BigDecimal 是不费脑子的,因为它对应用程序性能几乎没有可见影响。

I would argue that for almost everyone else, using BigDecimal is a no-brainer because it will have little visible impact on application performance.

In制定交易决策的延迟关键系统,任何不可预测的垃圾收集暂停都是完全不可能的,所以当前的垃圾收集算法在正常使用中非常棒,它们不一定适合延迟5毫秒可能会花费你很多钱。我希望大型系统是以非OOP风格编写的,除了一些实际的字符串(代码等)之外几乎没有使用任何对象。

In latency-critical systems making trading decisions, any unpredictable garbage-collection pauses are completely out-of-the-question so whilst the current garbage-collection algos are fantastic in normal use, they are not necessarily appropriate when a delay of 5 milliseconds may cost you a lot of money. I would expect that large systems were written in a very non-OOP style, with little or no objects being used aside from some interned Strings (for codes and the like).

你当然需要使用 double (甚至 float )并准确命中。

You'll certainly need to use double (or even float) and take the accuracy hit.

这篇关于如何使用BigDecimal会影响应用程序性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆