前面做了一套自动驾驶通信中间件,阅读了ROS 1.0 roscpp和ecal相关源码,接下来将逐步对ecal的核心源码进行简要分析。
1.什么是ecal
ecal是德国大陆开源的一套自动驾驶通信中间件。
The enhanced Communication Abstraction Layer (eCAL) is a middleware that enables scalable, high performance interprocess communication on a single computer node or between different nodes in a computer network. eCAL uses a publish - subscribe pattern to automatically connect different nodes in the network.
eCAL automatically chooses the best available data transport mechanism for each link:
- Shared memory for local communication (incredible fast!)
- UDP for network communication
如上所述,ecal是enhanced communication abstraction layer的首字母缩写,增强的通讯抽象层,是一套扩展性强、高性能的进程间通信中间件,可用于本机或者局域网内机器。ecal会自动去选择最优的通信方式去进行数据传输,例如:
- 对于本机内的进程,其通信方式自动选择为共享内存;
- 对于局域网内的跨机器之间的通信,会使用UDP组播的方式进行数据传输(最新版本支持TCP了)。
最初是没有TCP传输层,下面是添加tcp传输协议的Issue,因为对于大数据量传输,采用UDP的方式,如果丢了某一帧,则整个数据都无法使用。
TCP相对于UDP最大的优势就是可靠性高,因为是面向连接的,但是也有一些缺点:
- TCP是单播,要实现N:N多对多通信的模式会产生非常多的TCP连接,增加网络负担;
- TCP由于是面向连接的协议,单从协议层面比UDP的“传输负担”要大一些,但是因为其面向连接的可靠性传输保证,弥补了这一缺点。
2.ecal支持的功能
- eCAL is fast (1 - 10 GB/s, depends on payload size)
进程间数据传输效率非常高,1——10GB/s(依赖于数据载荷)。
下面是一组测试数据,测试的场景是:同一机器上的进程间(使用共享内存SHM)、一对一的publisher/subscriber在不同数据载荷下的数据传输延时、 数据载荷1kB—512kB时发送200000 samples,数据载荷大于512KB时发送10000 samples,单位为微秒(us),其中最后一列为Iceoryx的测试结果,Iceoryx是另外一个优秀的进程间通信的中间件,进程间数据传输可以做到真正的零拷贝(true zero-copy)。
Payload Size (kB) | Win10 AMD64 (µs)eCAL SHM | Ubuntu18 AMD64 (µs)eCAL SHM | Ubuntu18 AMD64 (µs)Iceoryx SHM |
---|---|---|---|
1 | 10 | 4 | 6 |
2 | 10 | 4 | 6 |
4 | 10 | 5 | 6 |
8 | 11 | 5 | 6 |
16 | 12 | 6 | 6 |
32 | 13 | 7 | 8 |
64 | 16 | 10 | 10 |
128 | 21 | 15 | 13 |
256 | 32 | 33 | 19 |
512 | 56 | 50 | 28 |
1024 | 103 | 154 | 82 |
2048 | 363 | 392 | 177 |
4096 | 867 | 877 | 420 |
8192 | 1814 | 1119 | 534 |
16384 | 3956 | 2252 | 1060 |
从上述测试结果可以看出来,在Ubuntu18上eCAL SHM和Iceoryx SHM的传输效率相当,发送16384KB的数据延时仅有2252us,也就是2毫秒左右。
- eCAL provides both publish-subscribe and server-client patterns
ecal提供了publish-subscribe和server-client通信模式。
- eCAL is brokerless
ecal是没有中间代理商的分布式网络架构。
- eCAL provides a C++ and C interface for easy integration into other languages (like python, csharp or rust)
ecal提供了c++和c的接口,API可以比较容易的进行扩展,目前已经支持python,csharp和rust。
- eCAL can be used in conjunction with Matlab Simulink as eCAL Simulink Toolbox for simulation and prototyping
ecal同时还开发了simulink对应的toolbox
- eCAL has powerful tools for recording, replay and monitoring all your data flows - decentralized
ecal提供了完备的外围工具,例如数据录制、回放、监控。
- eCAL is simple and zero-conf. No complex configuration for communication details and QOS settings are needed
ecal使用起来非常简单,基本不需要配置。不过QOS也是没法设置的。
- eCAL is message protocol agnostic. You choose the message protocol that fits to your needs like Google Protobuf, CapnProto, Flatbuffers…
ecal支持很多种类的数据序列化/反序列化方式,默认是google protobuf,还支持CapnProto和Flatbuffer等
- eCAL uses the standardized recording format HDF5
ecal数据录制的文件格式采用HDF5.
- eCAL integrates gently into your ROS2 environment with the eCAL RMW
ecal目前已经实现了ROS2对应的RMW.
- eCAL runs on a wide variety of operating systems
ecal可跨平台,支持Windows/Linux/QNX/MacOS/FreeBSD等。其外围工具,例如数据录制、回放、监控等GUI软件都是基于QT开发,可轻松跨平台。
3.开源协议
eCAL is licensed under Apache License 2.0. You are free to
- Use eCAL commercially
- Modify eCAL
- Distribute eCAL
eCAL is provided on an “as is” basis without warranties or conditions of any kind.
ecal遵循的是最友好的Apache License 2.0开源协议,所以你可以对ecal进行任意修改、商用等。