Skip to content

Commit

Permalink
set max window_size to avoid out-of-memory
Browse files Browse the repository at this point in the history
can't have infinite window size due to memory restrictions, only keep statistics for the last 10000 messages so as not to run out of memory

Signed-off-by: Chris Ye <[email protected]>
  • Loading branch information
yechun1 committed Sep 1, 2018
1 parent 062e814 commit 06bdaa3
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions ros2topic/ros2topic/verb/hz.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ def __init__(self, node, window_size, filter_expr=None, use_wtime=False):
self.use_wtime = use_wtime

# can't have infinite window size due to memory restrictions
if window_size < 0:
window_size = 50000
if window_size < 0 or window_size > 10000:
window_size = 10000
self.window_size = window_size

# Clock that has support for ROS time.
Expand Down Expand Up @@ -175,7 +175,7 @@ def callback_hz(self, m, topic=None):
:param m: Message instance
:param topic: Topic name
"""
# #694: ignore messages that don't match filter
# ignore messages that don't match filter
if self.filter_expr is not None and not self.filter_expr(m):
return
with self.lock:
Expand All @@ -200,7 +200,7 @@ def callback_hz(self, m, topic=None):
self.set_msg_tn(curr, topic=topic)

# only keep statistics for the last 10000 messages so as not to run out of memory
if len(self.get_times(topic=topic)) > 10000:
if len(self.get_times(topic=topic)) > self.window_size - 1:
self.get_times(topic=topic).pop(0)

def get_hz(self, topic=None):
Expand Down

0 comments on commit 06bdaa3

Please sign in to comment.