ROS2机器人-C++和Python怎么选
admin
2024-01-31 14:02:50

发布选择: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是因为它速度快或内存效率高,我们使用它是因为它将开发时间缩短了一个数量级


相关内容

热门资讯

从哈尔滨到长白山闺蜜5天4晚天... 从哈尔滨到长白山闺蜜5天4晚天池+延吉边境:拍照打卡真实体验 一、出发前的纠结:比老板还难搞的攻略,...
搭上低空经济、AI文旅?两连板... 来源:e公司 桂林旅游(000978)回应市场热点。 9月8日,桂林旅游再度涨停,斩获2连板。当天晚...
八达岭长城国庆怎么去最省心?坐... 八达岭长城是来北京必去的景点之一,尤其是第一次来北京的游客。但国庆期间去八达岭,最大的挑战不是爬长城...
秋日睦邻游园会热闹开锣!居民重... (来源:上观新闻) 近日,殷行街道包头路社区睦邻活动室里,举办了一场秋日睦邻趣味游园会,辖区居民、户...
带父母去长白山怎么玩?3天2晚... 带父母去长白山怎么玩?3天2晚天池攻略,有些坑帮你们踩过了 一句话总结:这次带父母去长白山,我选了黑...