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

Fix the high latency on the subscriber due to zenoh bytes conversion #340

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions rmw_zenoh_cpp/src/detail/rmw_subscription_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <string>
#include <utility>
#include <variant>
#include <vector>

#include "attachment_helpers.hpp"
#include "cdr.hpp"
Expand All @@ -43,7 +44,7 @@ namespace rmw_zenoh_cpp
{
///=============================================================================
SubscriptionData::Message::Message(
zenoh::Bytes p,
std::vector<uint8_t> && p,
uint64_t recv_ts,
AttachmentData && attachment_)
: payload(std::move(p)), recv_timestamp(recv_ts), attachment(std::move(attachment_))
Expand Down Expand Up @@ -224,7 +225,7 @@ bool SubscriptionData::init()

sub_data->add_new_message(
std::make_unique<SubscriptionData::Message>(
sample.get_payload().clone(),
sample.get_payload().as_vector(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hm, I have a serious concern about this, but I'll leave a comment in the other PR since it is already merged.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. Also answered in that PR 😄.

std::chrono::system_clock::now().time_since_epoch().count(),
std::move(attachment_data)),
std::string(sample.get_keyexpr().as_string_view()));
Expand Down Expand Up @@ -287,8 +288,6 @@ bool SubscriptionData::init()
zenoh::Subscriber<void> sub = context_impl->session()->declare_subscriber(
sub_ke,
[data_wp](const zenoh::Sample & sample) {
zenoh::KeyExpr keystr(std::string(sample.get_keyexpr().as_string_view()));

auto sub_data = data_wp.lock();
if (sub_data == nullptr) {
RMW_ZENOH_LOG_ERROR_NAMED(
Expand All @@ -310,10 +309,10 @@ bool SubscriptionData::init()
AttachmentData attachment_data(attachment_value);
sub_data->add_new_message(
std::make_unique<SubscriptionData::Message>(
sample.get_payload().clone(),
payload.as_vector(),
std::chrono::system_clock::now().time_since_epoch().count(),
std::move(attachment_data)),
std::string(keystr.as_string_view()));
std::string(sample.get_keyexpr().as_string_view()));
},
zenoh::closures::none,
std::move(sub_options),
Expand Down Expand Up @@ -491,7 +490,7 @@ rmw_ret_t SubscriptionData::take_one_message(
std::unique_ptr<Message> msg_data = std::move(message_queue_.front());
message_queue_.pop_front();

auto payload_data = msg_data->payload.as_vector();
auto & payload_data = msg_data->payload;

if (payload_data.size() > 0) {
// Object that manages the raw buffer
Expand Down Expand Up @@ -550,7 +549,7 @@ rmw_ret_t SubscriptionData::take_serialized_message(
std::unique_ptr<Message> msg_data = std::move(message_queue_.front());
message_queue_.pop_front();

auto payload_data = msg_data->payload.as_vector();
auto & payload_data = msg_data->payload;

if (payload_data.size() > 0) {
if (serialized_message->buffer_capacity < payload_data.size()) {
Expand Down
5 changes: 3 additions & 2 deletions rmw_zenoh_cpp/src/detail/rmw_subscription_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <string>
#include <unordered_map>
#include <variant>
#include <vector>

#include <zenoh.hxx>

Expand All @@ -50,13 +51,13 @@ class SubscriptionData final : public std::enable_shared_from_this<SubscriptionD
struct Message
{
explicit Message(
zenoh::Bytes p,
std::vector<uint8_t> && p,
uint64_t recv_ts,
AttachmentData && attachment);

~Message();

zenoh::Bytes payload;
std::vector<uint8_t> payload;
uint64_t recv_timestamp;
AttachmentData attachment;
};
Expand Down
Loading