iris-ua / iris_lama_ros

LaMa on ROS
BSD 3-Clause "New" or "Revised" License
208 stars 59 forks source link

Enable TCP_NODELAY for LaserScan subscribers #22

Closed jcmonteiro closed 3 years ago

jcmonteiro commented 3 years ago

Why

TCP_NODELAY tends to reduce the latency when transmitting large messages at high rates.

Summary

I have noticed a significant improvement in repeatability by enabling TCP_NODELAY, especially when reconstructing maps from bag files. I cannot share the bags because they are from a private database, but maybe the following reports can aid the discussion.

Report without TCP_NODELAY

LaMa PF Slam2D - Report
 =======================
 Number of updates     1811
 Number of resamples   29
 Max memory usage      127.62 MiB
 Problem time span     29 minute(s) and 58 second(s)
 Execution time span   1 minute(s) and 58 second(s)
 Execution frequency   15.24 Hz
 Realtime factor       15.14x

 Execution time (mean ± std [min, max]) in milliseconds
 --------------------------------------------------------
 Update          65.624493 ± 24.572288 [16.365688, 204.315101]
   Optimization  15.406339 ± 6.583668 [4.105412, 64.503286]
   Normalizing   0.003712 ± 0.014701 [0.001416, 0.626481]
   Resampling    48.198855 ± 23.639840 [14.698563, 93.370426]
   Mapping       49.428003 ± 21.123442 [8.296447, 142.351808]

Report with TCP_NODELAY

 LaMa PF Slam2D - Report
 =======================
 Number of updates     1808
 Number of resamples   25
 Max memory usage      130.31 MiB
 Problem time span     29 minute(s) and 58 second(s)
 Execution time span   1 minute(s) and 54 second(s)
 Execution frequency   15.73 Hz
 Realtime factor       15.65x

 Execution time (mean ± std [min, max]) in milliseconds
 --------------------------------------------------------
 Update          63.586018 ± 23.778238 [13.311249, 168.210410]
   Optimization  14.644808 ± 5.956713 [3.533703, 57.413043]
   Normalizing   0.003259 ± 0.001786 [0.001344, 0.061546]
   Resampling    45.279249 ± 20.000452 [10.625678, 86.464556]
   Mapping       48.296392 ± 20.920238 [8.375613, 129.647679]

Multiple runs slightly change the memory usage and number of updates but have little impact on the execution time statistics.

facontidavide commented 3 years ago

Hi

I believe this is a good addition that certainly will not hurt. +1 to merge this.

Just curious. If you have a rosbag, why don't you use the offline map building? It seems like you are using rosbag play with the online mode of iris_lama.

If I remember correctly, in that mode there is no TCP communication at all, since the data is directly read from the rosbag.

jcmonteiro commented 3 years ago

Just curious. If you have a rosbag, why don't you use the offline map building? It seems like you are using rosbag play with the online mode of iris_lama.

I am actually using the offline node and not running the online on a rosbag play.

If I remember correctly, in that mode there is no TCP communication at all, since the data is directly read from the rosbag.

Hmm... As I understood the offline mode will actually read the bag and publish the data over ROS. Have a look here https://github.com/iris-ua/iris_lama_ros/blob/594b91957ff12dcb0c3bf46fbee7023865da9c12/src/offline_replay.cpp#L86-L120 and here https://github.com/iris-ua/iris_lama_ros/blob/594b91957ff12dcb0c3bf46fbee7023865da9c12/src/pf_slam2d_ros.cpp#L500-L512

facontidavide commented 3 years ago

ok, I didn't remember that correctly.

eupedrosa commented 3 years ago

:+1: