Skip to content
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

Merged
merged 18 commits into from
Sep 13, 2021

Conversation

camm73
Copy link
Contributor

@camm73 camm73 commented Aug 11, 2021

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 by CircularMessageCache 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.

@camm73 camm73 requested a review from a team as a code owner August 11, 2021 22:02
@camm73 camm73 requested review from lihui815 and david-prody and removed request for a team August 11, 2021 22:02
@emersonknapp emersonknapp self-requested a review August 12, 2021 02:38
Copy link
Contributor

@MichaelOrlov MichaelOrlov left a 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.

@emersonknapp
Copy link
Collaborator

emersonknapp commented Aug 31, 2021

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 shared_queues_vendor/moodycamel queue in the Player, not in the Recorder flow right now. However, maybe it's worth taking a look at regardless - the fewer advanced data structures we have to maintain/bugfix/performance-tune, the better.

Copy link
Collaborator

@emersonknapp emersonknapp left a 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.

Copy link
Contributor

@MichaelOrlov MichaelOrlov left a 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 interfaces BaseMessageCacheInterface and BaseCacheBufferInterface it's really interfaces without any implementations in it.
    Word base is extra in this case and introduce confusion.

  • Please move interfaces out of the cache_interfaces and put them inside rosbag2_cpp/cache/ folder and namespace, for the sake of the simplification and avoiding long names in the code.

  • See my other comments in code.

@camm73 camm73 force-pushed the cameron/circular-buffer-message-cache branch from 95ab166 to 5fecccc Compare September 8, 2021 19:07
@camm73
Copy link
Contributor Author

camm73 commented Sep 8, 2021

Thanks for the comments @MichaelOrlov. Just pushed changes for those

Copy link
Collaborator

@emersonknapp emersonknapp left a 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

Copy link
Contributor

@MichaelOrlov MichaelOrlov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@emersonknapp
Copy link
Collaborator

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@emersonknapp
Copy link
Collaborator

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

Cameron Miller added 9 commits September 10, 2021 15:56
Signed-off-by: Cameron Miller <cammlle@amazon.com>
Signed-off-by: Cameron Miller <cammlle@amazon.com>
Signed-off-by: Cameron Miller <cammlle@amazon.com>
Signed-off-by: Cameron Miller <cammlle@amazon.com>
Signed-off-by: Cameron Miller <cammlle@amazon.com>
Signed-off-by: Cameron Miller <cammlle@amazon.com>
Signed-off-by: Cameron Miller <cammlle@amazon.com>
Signed-off-by: Cameron Miller <cammlle@amazon.com>
Signed-off-by: Cameron Miller <cammlle@amazon.com>
Cameron Miller added 7 commits September 10, 2021 15:56
Signed-off-by: Cameron Miller <cammlle@amazon.com>
Signed-off-by: Cameron Miller <cammlle@amazon.com>
Signed-off-by: Cameron Miller <cammlle@amazon.com>
Signed-off-by: Cameron Miller <cammlle@amazon.com>
Signed-off-by: Cameron Miller <cammlle@amazon.com>
Signed-off-by: Cameron Miller <cammlle@amazon.com>
Signed-off-by: Cameron Miller <cammlle@amazon.com>
@emersonknapp emersonknapp force-pushed the cameron/circular-buffer-message-cache branch from 88a128b to d24c327 Compare September 11, 2021 00:41
…64_t for buffer sizes

Signed-off-by: Emerson Knapp <eknapp@amazon.com>
@emersonknapp emersonknapp force-pushed the cameron/circular-buffer-message-cache branch from d24c327 to ccbf1f9 Compare September 11, 2021 00:46
@emersonknapp
Copy link
Collaborator

Rebased and definitely fixed Clang warnings - took a best guess at Windows, it seems like something changed underneath us for create_subscription, the warning came from a package untouched in this PR. In the interest of going green, touched that file in rosbag2_transport

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@emersonknapp emersonknapp force-pushed the cameron/circular-buffer-message-cache branch from a600d06 to ea68b1a Compare September 13, 2021 19:04
@emersonknapp
Copy link
Collaborator

emersonknapp commented Sep 13, 2021

🤞

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

Signed-off-by: Emerson Knapp <emerson.b.knapp@gmail.com>
@emersonknapp emersonknapp force-pushed the cameron/circular-buffer-message-cache branch from ea68b1a to 9390c8d Compare September 13, 2021 19:53
@emersonknapp emersonknapp merged commit 622b0ad into ros2:master Sep 13, 2021
YXL76 pushed a commit to YXL76/rosbag2 that referenced this pull request Nov 18, 2022
* Add circular message cache buffer implementation to be used for in-memory snapshot mode

Signed-off-by: Cameron Miller <cammlle@amazon.com>
Co-authored-by: Emerson Knapp <emerson.b.knapp@gmail.com>
Signed-off-by: 兰陈昕 <lanchenxin@megvii.com>
YXL76 pushed a commit to YXL76/rosbag2 that referenced this pull request Nov 18, 2022
* Add circular message cache buffer implementation to be used for in-memory snapshot mode

Signed-off-by: Cameron Miller <cammlle@amazon.com>
Co-authored-by: Emerson Knapp <emerson.b.knapp@gmail.com>
YXL76 pushed a commit to YXL76/rosbag2 that referenced this pull request Nov 18, 2022
* Add circular message cache buffer implementation to be used for in-memory snapshot mode

Signed-off-by: Cameron Miller <cammlle@amazon.com>
Co-authored-by: Emerson Knapp <emerson.b.knapp@gmail.com>
YXL76 pushed a commit to YXL76/rosbag2 that referenced this pull request Nov 18, 2022
* Add circular message cache buffer implementation to be used for in-memory snapshot mode

Signed-off-by: Cameron Miller <cammlle@amazon.com>
Co-authored-by: Emerson Knapp <emerson.b.knapp@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants