From 78429912e8ab2679c8d4838584c9bf7afd12d67b Mon Sep 17 00:00:00 2001 From: ivanpauno Date: Fri, 22 Feb 2019 17:55:40 -0300 Subject: [PATCH] Added variable message length. Added script for reproduce tests made. --- rclcpp_performance/CMakeLists.txt | 2 +- rclcpp_performance/msg/MatchingPublisher.msg | 1 + rclcpp_performance/scripts/performance_test | 154 ++++++++++++++++++ .../src/communication_performance.cpp | 15 +- 4 files changed, 170 insertions(+), 2 deletions(-) create mode 100755 rclcpp_performance/scripts/performance_test diff --git a/rclcpp_performance/CMakeLists.txt b/rclcpp_performance/CMakeLists.txt index 15c6fb2c20..f65df4e960 100644 --- a/rclcpp_performance/CMakeLists.txt +++ b/rclcpp_performance/CMakeLists.txt @@ -39,7 +39,7 @@ ament_export_dependencies(rosidl_default_runtime) ament_package() install( - PROGRAMS scripts/posprocess_logging + PROGRAMS scripts/posprocess_logging scripts/performance_test DESTINATION lib/${PROJECT_NAME} ) diff --git a/rclcpp_performance/msg/MatchingPublisher.msg b/rclcpp_performance/msg/MatchingPublisher.msg index 7505064356..4aa1524f83 100644 --- a/rclcpp_performance/msg/MatchingPublisher.msg +++ b/rclcpp_performance/msg/MatchingPublisher.msg @@ -1,2 +1,3 @@ uint64 publisher_id uint64 message_id +uint8[] data diff --git a/rclcpp_performance/scripts/performance_test b/rclcpp_performance/scripts/performance_test new file mode 100755 index 0000000000..3c56fe1cbd --- /dev/null +++ b/rclcpp_performance/scripts/performance_test @@ -0,0 +1,154 @@ +#!/bin/bash + +TEST_FOLDERS=( + "test_intra_shared_10ms_n100_m10000_l100000" + "test_inter_shared_10ms_n100_m10000_l100000" + "test_intra_unique_10ms_n100_m10000_l100000" + "test_inter_unique_10ms_n100_m10000_l100000" + + "test_intra_shared_10ms_n10_m10000_l1000000" + "test_inter_shared_10ms_n10_m10000_l1000000" + "test_intra_unique_10ms_n10_m10000_l1000000" + "test_inter_unique_10ms_n10_m10000_l1000000" + + "test_intra_shared_10ms_n1_m10000_l10000000" + "test_inter_shared_10ms_n1_m10000_l10000000" + "test_intra_unique_10ms_n1_m10000_l10000000" + "test_inter_unique_10ms_n1_m10000_l10000000" + + # These tests below suffers of starvation + # "test_intra_shared_10ms_n5_m100_l10000000" + # "test_inter_shared_10ms_n5_m100_l10000000" +) + +COMMAND_ARGUMENTS=( + "-p 10 -n 100 -m 10000 -l 100000 -intra" + "-p 10 -n 100 -m 10000 -l 100000" + "-p 10 -n 100 -m 10000 -l 100000 -intra -unique" + "-p 10 -n 100 -m 10000 -l 100000 -unique" + + "-p 10 -n 10 -m 10000 -l 1000000 -intra" + "-p 10 -n 10 -m 10000 -l 1000000" + "-p 10 -n 10 -m 10000 -l 1000000 -intra -unique" + "-p 10 -n 10 -m 10000 -l 1000000 -unique" + + "-p 10 -n 1 -m 10000 -l 10000000 -intra" + "-p 10 -n 1 -m 10000 -l 10000000" + "-p 10 -n 1 -m 10000 -l 10000000 -intra -unique" + "-p 10 -n 1 -m 10000 -l 10000000 -unique" + + # "-p 10 -n 5 -m 10000 -l 10000000 -intra" + # "-p 10 -n 5 -m 10000 -l 10000000" +) + + +DESCRIPTION=( + "Intraprocess, shared publish, 100 pubs/subs, 10000 messages, 100000 bytes length, 10ms period." + "Interprocess, shared publish, 100 pubs/subs, 10000 messages, 100000 bytes length, 10ms period." + "Intraprocess, unique publish, 100 pubs/subs, 10000 messages, 100000 bytes length, 10ms period." + "Interprocess, unique publish, 100 pubs/subs, 10000 messages, 100000 bytes length, 10ms period." + + "Intraprocess, shared publish, 10 pubs/subs, 10000 messages, 1000000 bytes length, 10ms period." + "Interprocess, shared publish, 10 pubs/subs, 10000 messages, 1000000 bytes length, 10ms period." + "Intraprocess, unique publish, 10 pubs/subs, 10000 messages, 1000000 bytes length, 10ms period." + "Interprocess, unique publish, 10 pubs/subs, 10000 messages, 1000000 bytes length, 10ms period." + + "Intraprocess, shared publish, 1 pubs/subs, 10000 messages, 10000000 bytes length, 10ms period." + "Interprocess, shared publish, 1 pubs/subs, 10000 messages, 10000000 bytes length, 10ms period." + "Intraprocess, unique publish, 1 pubs/subs, 10000 messages, 10000000 bytes length, 10ms period." + "Interprocess, unique publish, 1 pubs/subs, 10000 messages, 10000000 bytes length, 10ms period." + + # "Intraprocess, shared publish, 5 pubs/subs, 10000 messages, 10000000 bytes length, 10ms period." + # "Interprocess, shared publish, 5 pubs/subs, 10000 messages, 10000000 bytes length, 10ms period." +) + +main() +{ + set -e + parse_arguments "$@" + if [[ $skip -eq 0 ]]; then + run_tests + fi + show_results +} + +parse_arguments() +{ + set -e + out_dir="logs" + skip=0 + + while [[ $# > 0 ]] + do + key="$1" + case $key in + -d|--dir) + out_dir="$2" + shift # past argument + ;; + -s|--skip) + skip=1 + ;; + -h|--help) + print_help + ;; + *) + print_help + ;; + esac + shift # past argument or value + done +} + +print_help() +{ + echo "Usage: $0 -d OUTPUT_DIR [--skip]" + echo "The logs file will be generated inside OUTPUT_DIR" + echo "Options:" + echo -e "\t\t-s|--skip: Only posprocess and show results, skip running tests." + exit 0 +} + +run_tests() +{ + set -e + mkdir -p $out_dir + pushd $out_dir > /dev/null + + i=0 + for folder in "${TEST_FOLDERS[@]}" + do + echo -e "\e[34mRunning performance test with the following configuration:\e[39m" + echo -e "\e[34m\t\t${COMMAND_ARGUMENTS[i]}\e[39m" + mkdir -p $folder + ros2 run rclcpp_performance communication_performance -d $folder ${COMMAND_ARGUMENTS[i]} + i=$i+1 + echo + done + + popd +} + +show_results() +{ + set -e + pushd $out_dir > /dev/null + + echo -e "\e[34mThe generated data will be posprocessed an showed.\e[39m" + echo + + i=0 + for folder in "${TEST_FOLDERS[@]}" + do + echo "Next configuration to be posprocessed:" + echo -e "\t\t${COMMAND_ARGUMENTS[i]}" + read -p "Press enter to posprocess and plot the results." + echo + ros2 run rclcpp_performance posprocess_logging -d $folder + i=$i+1 + done + + popd +} + +main "$@" diff --git a/rclcpp_performance/src/communication_performance.cpp b/rclcpp_performance/src/communication_performance.cpp index 5494546d5a..22277ce1db 100644 --- a/rclcpp_performance/src/communication_performance.cpp +++ b/rclcpp_performance/src/communication_performance.cpp @@ -36,6 +36,7 @@ class PublisherConstantRate uint64_t publisher_id, std::string base_dir, uint64_t number_of_messages_to_send, + uint64_t message_length, PeriodT period, bool use_unique_message, rmw_qos_profile_t qos_profile = rmw_qos_profile_default) : @@ -44,6 +45,7 @@ class PublisherConstantRate // Note(ivanpauno): msg type could be changed, to try the different publish methods. shared_msg_ = std::make_shared(); shared_msg_->publisher_id = publisher_id; + shared_msg_->data.resize(message_length); shared_msg_->message_id = 0; std::stringstream ss; @@ -76,7 +78,7 @@ class PublisherConstantRate }; timer_ = node->create_wall_timer(period, callback); } else { - auto callback = [this]() -> void + auto callback = [this, message_length]() -> void { if (this->number_of_messages_to_send_) { // First create a shared message and copy the data. @@ -85,6 +87,7 @@ class PublisherConstantRate std::make_unique(); unique_msg->publisher_id = this->shared_msg_->publisher_id; unique_msg->message_id = this->shared_msg_->message_id; + unique_msg->data.resize(message_length); this->logging_file_ << unique_msg->message_id << ", " << std::chrono::duration_cast( std::chrono::system_clock::now().time_since_epoch()).count() @@ -194,6 +197,7 @@ class PerformanceTestNode : public rclcpp::Node std::string base_dir, uint64_t number_of_pub_sub, uint64_t number_of_messages, + uint64_t message_length, PeriodT publish_period, bool use_unique_message) : Node(node_name, node_options) @@ -216,6 +220,7 @@ class PerformanceTestNode : public rclcpp::Node i, base_dir, number_of_messages, + message_length, publish_period, use_unique_message); publishers_.push_back(pub); @@ -234,6 +239,7 @@ int main(int argc, char ** argv) PeriodT period = PeriodT(100); uint64_t number_of_messages = 1000; uint64_t number_of_publishers = 100; + uint64_t message_length = 100; rclcpp::NodeOptions node_options; bool use_unique_message = false; @@ -265,6 +271,12 @@ int main(int argc, char ** argv) iss >> number_of_publishers; } + cli_option = rcutils_cli_get_option(argv, argv + argc, "-l"); + if (nullptr != cli_option) { + std::istringstream iss(cli_option); + iss >> message_length; + } + bool option = rcutils_cli_option_exist(argv, argv + argc, "-intra"); if (option) { node_options.use_intra_process_comms(true); @@ -283,6 +295,7 @@ int main(int argc, char ** argv) base_dir, number_of_publishers, //number of publishers/subscriptions number_of_messages, // number of messages to be send + message_length, // message length in bytes period, // Publish period use_unique_message); //use unique message or shared