Ale*_*ing 7 c++ java controls garbage-collection raii
在我的工作中,我们最近完成了控制应用程序的系统架构,其最大延迟大约为一到两秒.它分布在通过IP LAN进行通信的小型ARM片上盒中.
我们最初预见到我们会使用C或C++,因为它是一种经典的控制系统语言.在讨论了如何实现应用程序之后,我们现在意识到C++具有相当有限的库,缺乏内省,并且具有一些可能减慢开发的其他属性.我的同事随后建议Java可能会胜任这项工作.
我真的害怕为控制应用程序运行GC的延迟,我也不愿意放弃RAII,因为应用程序将使用大量外部资源(套接字,文件句柄,外部库等句柄等).
pro/con列表目前如下:
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
Run Code Online (Sandbox Code Playgroud)
如果GC延迟不成问题,我很乐意使用Java,我们可以获得RAII.因此,我也研究了其他具有RAII并且可以作为替代品的langs,到目前为止,我发现D,Ada,VB,Perl,Python(C),PHP,tcl和Lua似乎有某种形式超出范围的回调.我的自然反应可能是D,Python和ADA可能适合控制应用程序.D和ADA是我的最爱.
所以,我的问题是:你有什么建议吗?Java是一个可行的选择,如果你可以选择任何语言,它会是什么?
GC仅用于从被丢弃的对象中回收内存。丢弃非常少的资源,您将得到非常少、更短的 GC。
您可能会使用大量套接字、文件句柄、外部库的句柄,但是您丢弃它们的速度有多快?
完整 GC 旨在消除碎片。它通过复制所有内存来连续使用它来实现这一点。这就是它昂贵的原因,因此如果延迟对您很重要,您希望最大限度地减少这些。也就是说,如果完整 GC 花费的时间超过 100 毫秒,则存在严重的性能问题。不应该那么高。
恕我直言,我认为您应该能够开发一个延迟远低于 10 毫秒(99%+ 的时间)的控制系统。