在我的工作中,我们最近完成了一个控制应用程序的系统架构,该应用程序的最大延迟大约为一到两秒。它分布在通过 IP LAN 通信的小型 ARM 片上盒上。
我们最初预计我们将使用 C 或 C++,因为它是一种经典的控制系统语言。在讨论了如何实现应用程序之后,我们现在意识到 C++ 的库数量非常有限,缺乏自省,并且还有一些其他属性可能会减慢开发速度。然后我的同事建议 Java 可能胜任这项工作。
我真的很害怕为控制应用程序运行 GC 的延迟,而且我也不愿意放弃 RAII,因为该应用程序将使用大量外部资源(套接字、文件句柄、来自外部库的句柄等)。
目前的优缺点列表如下:
C++
+ RAII - Easy resource management - it will be a complex system
+ System language - speed if we cant't find a JIT VM for our ARM
+ No GC - no big worst case latencies from the GC
+ Easy to integrate with some shared mem libs that we have to interface with
- Fewer free as in beer libs
- Lacks introspection - Mapping classes to DB and external data formats (XML)
would benefit from this (ORM /JAXB) approach
- Easy to shoot one self in the foot - hard and expensive to find programmers
which don't make big mistakes
- Memory fragmentation - needs tuning and workarounds
Java
+ Huge amount of libs
+ Introspection - serialization becomes a breeze (see C++ section)
+ Easier to find 'good enough' programmers
- No RAII - Client has to remember finally or you leak
resources. IMO Java programmers tend to ignore this
problem unless they have server app background.
- No System Language - possibly slower although ARMj could alleviate this
- GC - latency might go up (don't know if parallel GC will work - seems that
you might get fragmentation, see note below).
- Need to write JNI for the shared mem libs that we interface with
- Maybe ORACLE will eat us
这篇 AMD 文章中提到了并行 GC 的内存碎片
如果 GC 延迟不是问题并且我们可以获得 RAII,我很乐意使用 Java。因此,我还研究了其他具有 RAII 并且可以作为很好的替代品的语言,到目前为止,我发现 D、Ada、VB、Perl、Python(C)、PHP、tcl 和 Lua 似乎有某种超出范围的回调。我的自发反应也许 D、Python 和 ADA 可能适用于控制应用程序。D 和 ADA 是我的最爱。
所以,我的问题是:你对此有什么建议吗?Java 是一个可行的选择吗?如果你可以选择任何一种语言,你会选择什么?