-
Notifications
You must be signed in to change notification settings - Fork 51
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
ServiceType use 'Local', subscriber can not receive data, in C++ binding language examples #496
Comments
@xfsaid Does this explanation solve your issue? |
OK, thank you very much. I am not familiar with the interface. |
@xfsaid The transmission latency (speed) should stay constant - independent of the structure size. Could you share your code snippet here that shows how you send and receive your large structure? Are you using the |
@elfenpiff I know the reason. My publisher sends messages at a frequency of 1000Hz. Now I know that the publisher needs to call this interface: max_slice_len(uint64_t). |
Please do not use Translated to your use case, it would mean if your construct the service with a payload of auto service = node.service_builder(ServiceName::create("Service With Dynamic Data")
.publish_subscribe<iox::Slice<TransmissionData>>()
.open_or_create()
.expect("successful service creation/opening"); But this is not want you want in your use case! When The summary:
|
…c-builder-methods [#496] disable slice specific builder methods
@elfenpiff I'll post my test code. examples/cxx/publish_subscribe/src/transmission_data.hpp #ifndef IOX2_EXAMPLES_TRANSMISSION_DATA_HPP
#define IOX2_EXAMPLES_TRANSMISSION_DATA_HPP
#include <cstdint>
#include <iostream>
struct TransmissionData {
std::int32_t x;
std::int32_t y;
double funky;
char c[1024*1024];
};
inline auto operator<<(std::ostream& stream, const TransmissionData& value) -> std::ostream& {
stream << "TransmissionData { x: " << value.x << ", y: " << value.y << ", funky: " << value.funky << " }";
return stream;
}
#endif examples/cxx/publish_subscribe/src/subscriber.cpp #include <iostream>
#include "iox/duration.hpp"
#include "iox2/node.hpp"
#include "iox2/service_name.hpp"
#include "iox2/service_type.hpp"
#include "transmission_data.hpp"
constexpr iox::units::Duration CYCLE_TIME = iox::units::Duration::fromMilliseconds(1); // fromMilliseconds fromSeconds
auto main() -> int {
using namespace iox2;
auto node = NodeBuilder().create<ServiceType::Ipc>().expect("successful node creation");
auto service = node.service_builder(ServiceName::create("My/Funk/ServiceName").expect("valid service name"))
.publish_subscribe<TransmissionData>()
// .history_size(100)
.subscriber_max_buffer_size(200) // 决定了缓存的大小
.subscriber_max_borrowed_samples(200) // 订阅者可以借用的最大样本数量
.open_or_create()
.expect("successful service creation/opening");
auto subscriber = service.subscriber_builder().create().expect("successful subscriber creation");
std::cout << "history_size:" << service.static_config().history_size() << std::endl;
std::cout << "subscriber_max_borrowed_samples:" << service.static_config().subscriber_max_borrowed_samples() << std::endl;
int counter = 0;
while (node.wait(CYCLE_TIME).has_value()) {
auto sample = subscriber.receive().expect("receive succeeds");
while (sample.has_value()) {
counter += 1;
if (counter % 1000 == 0)
{
std::cout << "received: " << sample->payload() << ", counter: " << counter << std::endl;
}
sample = subscriber.receive().expect("receive succeeds");
}
}
std::cout << "exit" << std::endl;
return 0;
} examples/cxx/publish_subscribe/src/publisher.cpp #include "iox/duration.hpp"
#include "iox2/node.hpp"
#include "iox2/sample_mut.hpp"
#include "iox2/service_name.hpp"
#include "iox2/service_type.hpp"
#include "transmission_data.hpp"
#include <iostream>
#include <utility>
constexpr iox::units::Duration CYCLE_TIME = iox::units::Duration::fromMilliseconds(1); // fromMilliseconds fromSeconds
auto main() -> int {
using namespace iox2;
auto node = NodeBuilder().create<ServiceType::Ipc>().expect("successful node creation");
auto service = node.service_builder(ServiceName::create("My/Funk/ServiceName").expect("valid service name"))
.publish_subscribe<TransmissionData>()
.subscriber_max_buffer_size(200) // 决定了缓存的大小
.subscriber_max_borrowed_samples(200) // 订阅者可以借用的最大样本数量
.open_or_create()
.expect("successful service creation/opening");
auto publisher = service.publisher_builder()
// .max_slice_len(1024 * 1024 + 100)
.create().expect("successful publisher creation");
auto counter = 0;
while (node.wait(CYCLE_TIME).has_value() && counter < (1000 * 60 * 60 + 5)) {
counter += 1;
auto sample = publisher.loan_uninit().expect("acquire sample");
sample.write_payload(TransmissionData { counter, counter * 3, counter * 812.12 }); // NOLINT
auto initialized_sample = assume_init(std::move(sample));
send(std::move(initialized_sample)).expect("send successful");
if (counter % 1000 == 0)
{
std::cout << "Send sample " << counter << " ..." << std::endl;
}
}
std::cout << "exit" << std::endl;
return 0;
} |
@xfsaid the high CPU usage is expected in the line But you can optimize it further by reducing the memory write operations. auto sample = publisher.loan_uninit().expect("acquire sample");
sample->x = 123;
sample->y = 856;
for(auto n = 0; n < 100; ++n) {
sample->c[n] = 5;
} |
@elfenpiff Regarding the problem that many header files are missing after executing the "make install" command, I will create a new issue. |
Operating system:
Ubuntu20.04.2 x86
Version:
cmake : 3.31.0-rc3
cargo : 1.82.0
gcc : 9.4.0
g++ : 9.4.0
Files:
examples/cxx/publish_subscribe/src/publisher.cpp
examples/cxx/publish_subscribe/src/subscriber.cpp
The text was updated successfully, but these errors were encountered: