Link to page
Increasing buffer size on ROS
Increasing the buffer size in ROS (Robot Operating System) can help manage larger amounts of data and prevent loss of messages when dealing with high-throughput topics. This can be accomplished by adjusting the buffer size parameter in the subscriber's setup, allowing the system to handle more data before overwriting old messages.

In ROS, increasing the buffer size can refer to several aspects like publisher/subscriber queue size, network buffer size, or log file size. Here's a guide on how to increase these various buffer sizes:

1. Publisher/Subscriber Queue Size

Adjusting the publisher/subscriber queue size can help ensure that messages are not dropped due to overflow.
ROS1
Publisher Example:
import rospy from std_msgs.msg import String

pub = rospy.Publisher('chatter', String, queue_size=100)
# Increase queue size to 100

Subscriber Example:
import rospy from std_msgs.msg
import String
def callback(data):
rospy.loginfo(rospy.get_caller_id() + "I heard %s", data.data) rospy.init_node('listener', anonymous=True)
rospy.Subscriber('chatter', String, callback, queue_size=100)
# Increase queue size to 100

ROS2
In ROS2, the buffer size is controlled through the history and depth Quality of Service (QoS) settings.
Publisher Example:
# Python (ROS2)
import rclpy from rclpy.node
import Node from std_msgs.msg
import String from rclpy.qos
import QoSProfile, QoSDurabilityPolicy, QoSHistoryPolicy
class PublisherNode(Node):
def __init__(self):
super().__init__('publisher_node')
qos_profile = QoSProfile(
history=QoSHistoryPolicy.KEEP_LAST,
depth=100, # Increase depth
durability=QoSDurabilityPolicy.TRANSIENT_LOCAL
)
self.publisher = self.create_publisher(String, 'chatter', qos_profile)
rclpy.init()
node = PublisherNode()
Subscriber Example:
# Python (ROS2)
import rclpy from rclpy.node
import Node from std_msgs.msg
import String from rclpy.qos
import QoSProfile, QoSDurabilityPolicy, QoSHistoryPolicy

class SubscriberNode(Node):
def __init__(self):
super().__init__('subscriber_node')
qos_profile = QoSProfile(
history=QoSHistoryPolicy.KEEP_LAST,
depth=100, # Increase depth
durability=QoSDurabilityPolicy.TRANSIENT_LOCAL
)
self.subscription = self.create_subscription(String, 'chatter', self.callback, qos_profile)
def callback(self, msg):
self.get_logger().info('Received message: "%s"' % msg.data)
rclpy.init()
node = SubscriberNode()

2. Network Buffer Size

Increasing network buffer size can help in environments with high network latency. Steps as follow:
Open the socket options file with elevated permissions:
sudo nano /etc/sysctl.conf
Add the following lines at the end to increase the TCP buffer sizes:
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 65536 16777216
Apply the changes:
sudo sysctl -p

3. Log File Size

If you want to increase the maximum log file size:
Open the ROS log settings file (or create one):
mkdir -p ~/.ros
nano ~/.ros/rosconsole.config
Add or modify the following lines to adjust the log size:
log4j.logger.ros=INFO, A1
log4j.appender.A1.MaxFileSize=100MB # Adjust the file size
log4j.appender.A1.MaxBackupIndex=10
log4j.appender.A1.File=${user.home}/.ros/log/latest/ros.log
These steps should help you increase the buffer sizes for different components in ROS.
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.