ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
If you want optimal performance then the thread count you choose will depend on how many cores your computer has and how many other processor intensive tasks you will need to run concurrently to this node. For example if I have an 8 core computer and I'm running a processor intensive lidar driver node and RVIZ displaying large amounts of information, I could choose 6 threads. This would leave one core spare for the driver and RVIZ, this is with the caveat that the OS is ultimately in control of what runs where. But choosing more threads than you have physical cores will start to degrade performance because there will be unnecessary context switching going on.
To be honest, I'm not sure how ros::spinOnce() interacts with the AsyncSpinner, but also think calling it would be completely unnecessary, sleeping a rate object would achieve the same thing.
2 | No.2 Revision |
If you want optimal performance then the thread count you choose will depend on how many cores your computer has and how many other processor intensive tasks you will need to run concurrently to this node. For example if I have an 8 core computer and I'm running a processor intensive lidar driver node and RVIZ displaying large amounts of information, I could choose 6 threads. This would leave one core spare for the driver and RVIZ, this is with the caveat that the OS is ultimately in control of what runs where. But choosing more threads than you have physical cores will start to degrade performance because there will be unnecessary context switching going on.
To be honest, I'm not sure how ros::spinOnce() interacts with the AsyncSpinner, but also think calling it would be completely unnecessary, sleeping a rate object would achieve the same thing. thing.
Regarding which callback is assigned to which thread, the answer is they aren't. The is a thread pool of three threads and the are assigned as messages are received. For example if messages arrive quickly on your point_cloud_1
topic so that one callback is still running when the next message arrives, then another thread will start running the same callback. So you will have two or even three instances of callback1
running in different threads at the same time.