ROS2机器人-C++和Python怎么选

发布选择:C++,开发选择:Python。

由于工作性质,教学过程中适当使用Python演示是可行的,但是一直致力于推介C++。

使用C++最大问题,学生C++基础比较薄弱。


discourse.ros.org/t/high-cpu-load-for-simple-python-nodes/28324


Marco:
I have been using in a project various nodes, some of which in C++, and some in Python. I noticed a huge difference, even for basic nodes that just do some publishing, in CPU usage between Python and C++. Python CPU usage is generally several times higher than a C++ node doing the same.
This happens for publisher nodes, as well as for server nodes, even in their idle state when no services or actions are actually requested, which I find extremely strange…

Did anyone notice similar issues? Does anyone have any recommendations for reducing the CPU usage of Python nodes?
The issue has been observed so far in ROS2

马可:
我在一个项目中使用了各种节点,其中一些在C++中,一些在Python中。我注意到Python和C++之间的CPU使用情况存在巨大差异,即使对于只做一些发布的基本节点也是如此。Python的CPU使用率通常比C++节点高几倍。
这种情况发生在发布者节点和服务器节点上,即使在它们的空闲状态下,实际上没有请求任何服务或操作,我觉得这非常奇怪…
有人注意到类似的问题吗?有人对减少Python节点的CPU使用有什么建议吗?
到目前为止,在不同的CPU架构(amd和arm)下,在ROS2银河系统中已经观察到了这个问题


aposhian:
I have observed this as well. For this reason, I only use rclpy for development, and never for production nodes.

阿波西安语:
我也观察到了这一点。因此,我只将rcpy用于开发,而从不用于生产节点。


matthews-jca:
Not just CPU overhead when spinning, but memory footprint as well. Mirroring Aposhian we usually prototype in python and then convert to C++ for release

马修斯jca:
不仅是旋转时的CPU开销,还包括内存占用。镜像Aposhian我们通常在python中创建原型,然后转换为C++发布


MoffKalast:
At the risk of sounding callous, you guys do realize you’re comparing a compiled language known for its memory efficiency and speed to one that’s none of those three things. The virtual machine will add overhead, so will the interpreter, and of course the language itself needs more processor cycles to run, given dynamic typing and other high level abstractions. Even if you’re not receiving anything there’s still a thread in the background that needs to periodically poll for new socket data I presume. Unlike C++ which will strip out all unused code at compile time, Python also needs to keep all imported modules loaded into memory.

But none of us are using Python because it’s fast or memory efficient, we’re using it because it cuts down development time by an order of magnitude 

莫夫卡拉斯特:
冒着听起来冷酷无情的风险,你们确实意识到,你们正在将一种以内存效率和速度著称的编译语言与这三种语言相比。虚拟机会增加开销,解释器也会增加开销。当然,考虑到动态类型和其他高级抽象,语言本身需要更多的处理器周期来运行。即使您没有收到任何消息,我想后台仍有一个线程需要定期轮询新的套接字数据。与C++不同,Python在编译时会删除所有未使用的代码,Python还需要将所有导入的模块加载到内存中。
但我们没有人使用Python是因为它速度快或内存效率高,我们使用它是因为它将开发时间缩短了一个数量级


物联沃分享整理
物联沃-IOTWORD物联网 » ROS2机器人-C++和Python怎么选

发表评论