-
Notifications
You must be signed in to change notification settings - Fork 261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Circular Message Cache implementation for snapshot feature #844
Circular Message Cache implementation for snapshot feature #844
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@camm73 Thank you for your contribution.
Implementation of MessageCacheCircularBufer
with linked list looks very reasonable, however I would recommend to keep the same interface as for MessageCacheBuffer
i.e. will need to change return type for MessageCacheCircularBuffer::data()
from list to the vector.
Inside MessageCacheCircularBuffer::data()
you can create new std::vector<buffer_element_t>
for returning value and push elements in it from your internal buffer_
which is linked list.
We are operating with shared_pointers
to the messages in linked list and vector and copying elements will not cause a significant overhead since it will be copied only a few bytes for each shared pointer. And whole purpose of the circular buffer is to get data occasionally by request. There are no expectations that request for data from circular buffer will occur in tight loop.
Adhere to the common interface with MessageCacheBuffer
will allow to better design structure of the classes. It will be more reasonable to create common pure virtual interface class or base class for message cache buffers.
rosbag2_cpp/src/rosbag2_cpp/cache/message_cache_circular_buffer.cpp
Outdated
Show resolved
Hide resolved
rosbag2_cpp/include/rosbag2_cpp/cache/message_cache_circular_buffer.hpp
Outdated
Show resolved
Hide resolved
Sorry to put this out there so late - but did you see https://github.com/cameron314/readerwriterqueue/blob/master/readerwritercircularbuffer.h - that the same lock-free queue library we were using has a circular implementation? It would be worth trying this out, as it's probably much more tuned and performant than anything we could build ourselves. EDIT: I just remembered that we are currently only using the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comment about the linkedlist implementation, and about the Cache type hierarchy. We might be better off using somebody else's implementation rather than creating our own (though it is a fun exercise to do) - but if we do build it ourselves, a vector should provide much better performance than a linked list.
rosbag2_cpp/include/rosbag2_cpp/cache/circular_message_cache.hpp
Outdated
Show resolved
Hide resolved
rosbag2_cpp/src/rosbag2_cpp/cache/message_cache_circular_buffer.cpp
Outdated
Show resolved
Hide resolved
rosbag2_cpp/include/rosbag2_cpp/cache/message_cache_circular_buffer.hpp
Outdated
Show resolved
Hide resolved
rosbag2_cpp/src/rosbag2_cpp/cache/message_cache_circular_buffer.cpp
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's certainly getting better, however I would like to request several changes, mostly a nitpicks but still very important:
-
Please remove
Base
prefix from newly defined interfacesBaseMessageCacheInterface
andBaseCacheBufferInterface
it's really interfaces without any implementations in it.
Wordbase
is extra in this case and introduce confusion. -
Please move interfaces out of the
cache_interfaces
and put them insiderosbag2_cpp/cache/
folder and namespace, for the sake of the simplification and avoiding long names in the code. -
See my other comments in code.
rosbag2_cpp/include/rosbag2_cpp/cache_interfaces/base_cache_buffer_interface.hpp
Outdated
Show resolved
Hide resolved
rosbag2_cpp/include/rosbag2_cpp/cache/message_cache_circular_buffer.hpp
Outdated
Show resolved
Hide resolved
rosbag2_cpp/include/rosbag2_cpp/cache_interfaces/base_message_cache_interface.hpp
Outdated
Show resolved
Hide resolved
95ab166
to
5fecccc
Compare
Thanks for the comments @MichaelOrlov. Just pushed changes for those |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking great - just asking for a quick namespace and docstring update then I think we're good to go
rosbag2_cpp/include/rosbag2_cpp/cache/cache_buffer_interface.hpp
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
rosbag2_cpp/include/rosbag2_cpp/cache/circular_message_cache.hpp
Outdated
Show resolved
Hide resolved
Oof just a couple of compiler warnings - so close! I'll try and push a commit fixing those, since I think @camm73 may not be reachable for a few days |
Signed-off-by: Cameron Miller <[email protected]>
Signed-off-by: Cameron Miller <[email protected]>
Signed-off-by: Cameron Miller <[email protected]>
Signed-off-by: Cameron Miller <[email protected]>
Signed-off-by: Cameron Miller <[email protected]>
Signed-off-by: Cameron Miller <[email protected]>
Signed-off-by: Cameron Miller <[email protected]>
Signed-off-by: Cameron Miller <[email protected]>
Signed-off-by: Cameron Miller <[email protected]>
Signed-off-by: Cameron Miller <[email protected]>
Signed-off-by: Cameron Miller <[email protected]>
Signed-off-by: Cameron Miller <[email protected]>
Signed-off-by: Cameron Miller <[email protected]>
Signed-off-by: Cameron Miller <[email protected]>
Signed-off-by: Cameron Miller <[email protected]>
Signed-off-by: Cameron Miller <[email protected]>
88a128b
to
d24c327
Compare
…64_t for buffer sizes Signed-off-by: Emerson Knapp <[email protected]>
d24c327
to
ccbf1f9
Compare
Rebased and definitely fixed Clang warnings - took a best guess at Windows, it seems like something changed underneath us for |
a600d06
to
ea68b1a
Compare
Signed-off-by: Emerson Knapp <[email protected]>
ea68b1a
to
9390c8d
Compare
* Add circular message cache buffer implementation to be used for in-memory snapshot mode Signed-off-by: Cameron Miller <[email protected]> Co-authored-by: Emerson Knapp <[email protected]> Signed-off-by: 兰陈昕 <[email protected]>
* Add circular message cache buffer implementation to be used for in-memory snapshot mode Signed-off-by: Cameron Miller <[email protected]> Co-authored-by: Emerson Knapp <[email protected]>
* Add circular message cache buffer implementation to be used for in-memory snapshot mode Signed-off-by: Cameron Miller <[email protected]> Co-authored-by: Emerson Knapp <[email protected]>
* Add circular message cache buffer implementation to be used for in-memory snapshot mode Signed-off-by: Cameron Miller <[email protected]> Co-authored-by: Emerson Knapp <[email protected]>
Part of #663
Implements the first part of the new snapshot feature by creating a
MessageCacheCircularBuffer
class which implements a circular buffer used to store messages until the buffers are flipped. This class is used byCircularMessageCache
to create two circular buffers where the primary buffer is continuously filled with messages, overwriting old messages when full, until a buffer swap is triggered. Once the swap occurs, the recorded messages for the snapshot can now be accessed.