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

test(MultiThreadedAgnocastExecutor): verify that starvation does not occur #435

Merged
merged 5 commits into from
Feb 27, 2025

Conversation

atsushi421
Copy link
Contributor

@atsushi421 atsushi421 commented Feb 27, 2025

Description

MultiThreadedAgnocastExecutorにてスタベーションが発生しないことを検証するテストを追加しました。基本はSingleThreadedAgnocastExecutorへのテストと同じです。

MultiThreadedAgnocastExecutorの場合はcallback groupもスタベーションに関わってきますが、本テストでは全てのcallbackを別々のcallback groupに所属させたケースにスコープを絞っています。callback groupを設定した時のスタベーションの検証は別のテストで行います。

Related links

How was this PR tested?

bash scripts/test_and_create_report

Notes for reviewers

このテストには以下10個のパラメータがあります。

  1. publishの周期 (PUB_PERIOD)
  2. ros2_spin() を実行するスレッド数 (NUMBER_OF_ROS2_THREADS)
  3. agnocast_spin() を実行するスレッド数 (NUMBER_OF_AGNOCAST_THREADS)
  4. ROS 2 subscritption callbackの数 (NUM_ROS2_SUB_CBS)
  5. Agnocast subscription callbackの数 (NUM_AGNOCAST_SUB_CBS)
  6. spin() 後にregisterされるAgnocast subscription callbackの数 (NUM_AGNOCAST_CBS_TO_BE_ADDED)
  7. yield_before_execute
  8. ros2_next_exec_timeout
  9. agnocast_next_exec_timeout_ms
  10. spin() を回す時間 (spin_duration)

AGNOCAST_CALLBACK_GROUP_WAIT_TIME はこのテストでは意味を持たないので、デフォルト値にしています。

このうち、1--3は決め打ちの固定値を使用し、4--6はそれらの値を使用して以下のように設定しています。

const uint64_t NUM_ROS2_SUB_CBS = NUMBER_OF_ROS2_THREADS * 3;
const uint64_t NUM_AGNOCAST_SUB_CBS = NUMBER_OF_AGNOCAST_THREADS * 3;
const uint64_t NUM_AGNOCAST_CBS_TO_BE_ADDED = NUMBER_OF_AGNOCAST_THREADS * 2;

7--9は色々変動させるべきだと思ったので、パラメータ化しました。8,9を別々のパラメータにすると組み合わせ数が増えすぎるかなという判断で、1つのパラメータに統合しています(同じ値に設定する)。

そして、10は以下のようにざっくり理論値計算して、それを使用しています。

void set_spin_duration_based_on_params(const int agnocast_next_exec_timeout_ms)
  {
    std::chrono::seconds buffer = std::chrono::seconds(1);  // Rough value
    spin_duration_ =
      std::max(
        std::chrono::seconds(
          agnocast_next_exec_timeout_ms * (NUM_AGNOCAST_SUB_CBS + NUM_AGNOCAST_CBS_TO_BE_ADDED) /
          1000 / NUMBER_OF_AGNOCAST_THREADS),
        std::chrono::duration_cast<std::chrono::seconds>(
          PUB_PERIOD * NUM_AGNOCAST_CBS_TO_BE_ADDED)) +
      buffer;
  }

…occur

Signed-off-by: atsushi421 <atsushi.yano.2@tier4.jp>
Signed-off-by: atsushi421 <atsushi.yano.2@tier4.jp>
Signed-off-by: atsushi421 <atsushi.yano.2@tier4.jp>
@atsushi421 atsushi421 marked this pull request as ready for review February 27, 2025 02:24
Signed-off-by: atsushi421 <atsushi.yano.2@tier4.jp>
@atsushi421 atsushi421 added the run-build-test Run build-test in CI label Feb 27, 2025
@atsushi421 atsushi421 merged commit c1b00bb into main Feb 27, 2025
4 checks passed
@atsushi421 atsushi421 deleted the test_for_multi_threaded_executor branch February 27, 2025 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
run-build-test Run build-test in CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants