java - ~1s 延迟控制应用程序 : is this suitable for Java?

标签 java c++ controls garbage-collection raii

在我的工作中,我们最近完成了一个控制应用程序的系统架构,该应用程序的最大延迟大约为一到两秒。它分布在通过 IP LAN 通信的小型 ARM 片上盒上。

我们最初预见到我们会使用 C 或 C++,因为它是一种经典的控制系统语言。在讨论了如何实现该应用程序之后,我们现在意识到 C++ 的库数量非常有限,缺乏内省(introspection),并且还有一些其他属性可能会减慢开发速度。然后我的同事建议 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

提到了并行 GC 的内存碎片 in this AMD article

如果 GC 延迟不是问题并且我们可以获得 RAII,我会喜欢使用 Java。所以 我还研究了其他具有 RAII 并且可以作为很好的替代品的语言,到目前为止我发现 D、Ada、VB、Perl、Python(C)、PHP、tcl 和 Lua 似乎有某种超出范围的回调。我的本能 react 是 D、Python 和 ADA 可能适合控制应用程序。 D 和 ADA 是我的最爱。

那么,我的问题是:您对此有什么建议吗? Java 是一个可行的选择吗?如果您可以选择任何一种语言,它会是什么?

最佳答案

如果您想使用 java,您可能需要概念证明,我建议您编写一个简单的原型(prototype)和压力测试,以检查在垃圾收集期间您在高负载下的延迟时间。然后检查不同的收集器类型,例如low pause collector .

RAII我不太明白的论点,恕我直言,在 C++ 中比在 Java 中更容易造成内存泄漏。

关于java - ~1s 延迟控制应用程序 : is this suitable for Java?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2916549/

相关文章:

java - Hibernate 按属性获取记录不起作用

c++ - 将 BSTR 字符串传递给 _bstr_t 或 CComBSTR 构造函数时出现访问冲突

c# - 访问动态创建的控件 C#

c# - 如何在 TrackBar 中使用 float

java - 如果一个 double 的结果能被另一个 double 整除是准确的吗?

java - 如何从字符串中获取第二个单词?

java - 如何在Java中显示小数点前没有前导零的 double

c++ - 同一个程序运行时间差异很大,有时达到1000+us

c++ - 使用 boost over socket 发送和接收压缩文件

swift - UIButton的自定义绘制