-
Notifications
You must be signed in to change notification settings - Fork 369
telemetry: extract bounded staging queue #1945
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
Open
e-eygin
wants to merge
4
commits into
ai-dynamo:main
Choose a base branch
from
e-eygin:nix-1542-extract-telemetry-staging-queue
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
eea0fba
telemetry: extract bounded staging queue
e-eygin a9db285
telemetry: address CodeRabbit review on staging queue
e-eygin b923ec4
telemetry: address review on staging queue
e-eygin f3cd5f9
telemetry: refine staging queue API per review
e-eygin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| #include "telemetry_staging_queue.h" | ||
|
|
||
| nixlTelemetryStagingQueue::nixlTelemetryStagingQueue(size_t capacity) : capacity_(capacity) { | ||
| events_.reserve(capacity_); | ||
| } | ||
|
|
||
| bool | ||
| nixlTelemetryStagingQueue::tryPush(const nixlTelemetryEvent &event) { | ||
| const std::lock_guard<std::mutex> lock(mutex_); | ||
| if (events_.size() >= capacity_) { | ||
| numDroppedEvents_.fetch_add(1, std::memory_order_relaxed); | ||
| return false; | ||
| } | ||
| events_.push_back(event); | ||
| return true; | ||
| } | ||
|
|
||
| bool | ||
| nixlTelemetryStagingQueue::tryPushBatch(std::span<const nixlTelemetryEvent> events) { | ||
| if (events.empty()) { | ||
| return true; | ||
| } | ||
| const std::lock_guard<std::mutex> lock(mutex_); | ||
| if (events.size() > capacity_ - events_.size()) { | ||
| numDroppedEvents_.fetch_add(events.size(), std::memory_order_relaxed); | ||
| return false; | ||
| } | ||
| events_.insert(events_.end(), events.begin(), events.end()); | ||
| return true; | ||
| } | ||
|
|
||
| std::vector<nixlTelemetryEvent> | ||
| nixlTelemetryStagingQueue::takePending() { | ||
| std::vector<nixlTelemetryEvent> pending; | ||
| pending.reserve(capacity_); | ||
| { | ||
| const std::lock_guard<std::mutex> lock(mutex_); | ||
| events_.swap(pending); | ||
| } | ||
| return pending; | ||
| } | ||
|
|
||
| uint64_t | ||
| nixlTelemetryStagingQueue::takeNumDropped() noexcept { | ||
| return numDroppedEvents_.exchange(0, std::memory_order_relaxed); | ||
| } | ||
|
|
||
| size_t | ||
| nixlTelemetryStagingQueue::capacity() const noexcept { | ||
| return capacity_; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| /* | ||
| * SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| #ifndef NIXL_SRC_CORE_TELEMETRY_TELEMETRY_STAGING_QUEUE_H | ||
| #define NIXL_SRC_CORE_TELEMETRY_TELEMETRY_STAGING_QUEUE_H | ||
|
|
||
| #include <atomic> | ||
| #include <cstddef> | ||
| #include <cstdint> | ||
| #include <mutex> | ||
| #include <span> | ||
| #include <vector> | ||
|
|
||
| #include "telemetry_event.h" | ||
|
|
||
| /** | ||
| * @brief Bounded multi-producer/single-consumer staging queue for telemetry | ||
| * events. | ||
| * | ||
| * Owns the queue mechanics that used to live inline in nixlTelemetry: the event | ||
| * storage and its capacity reserve, the producer/consumer mutex, capacity | ||
| * enforcement, all-or-none single and batch insertion, the swap-drain, and the | ||
| * staging-drop counter. Metric semantics (activation, event selection, exporter | ||
| * dispatch, synthetic dropped-event construction) stay in nixlTelemetry. | ||
| * | ||
| * Drop policy is drop-newest: once the queue is full an incoming event or batch | ||
| * is rejected and counted as dropped; already-queued events are never | ||
| * overwritten. | ||
| */ | ||
| class nixlTelemetryStagingQueue { | ||
| public: | ||
| /** | ||
| * @brief Construct a queue that retains at most @p capacity events. | ||
| * | ||
| * Reserves storage for @p capacity events up front so the producer path | ||
| * never reallocates. Any @p capacity is accepted (a zero capacity yields a | ||
| * queue that drops every push); rejecting a zero telemetry buffer size is | ||
| * the caller's responsibility (see nixlTelemetry construction). | ||
| * @param capacity Maximum number of events retained before pushes are dropped. | ||
| */ | ||
| explicit nixlTelemetryStagingQueue(size_t capacity); | ||
|
|
||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| /** | ||
| * @brief Append a single event if there is room. | ||
| * | ||
| * The capacity check and insertion happen under one mutex acquisition. On a | ||
| * full queue the event is rejected and the staging-drop count is incremented | ||
| * by one. | ||
| * @return true if the event was queued, false if rejected (dropped). | ||
| */ | ||
| [[nodiscard]] bool | ||
| tryPush(const nixlTelemetryEvent &event); | ||
|
|
||
| /** | ||
| * @brief Append a batch of events all-or-none if the whole batch fits. | ||
| * | ||
| * The capacity check and insertion happen under one mutex acquisition. The | ||
| * batch is accepted completely or rejected completely; on rejection the | ||
| * staging-drop count is incremented by the batch size. An empty batch | ||
| * succeeds without locking or changing drop accounting. | ||
| * @param events Contiguous events to append. | ||
| * @return true if the batch was queued (or empty), false if rejected. | ||
| */ | ||
| [[nodiscard]] bool | ||
| tryPushBatch(std::span<const nixlTelemetryEvent> events); | ||
|
|
||
| /** | ||
| * @brief Swap the live queue with an empty capacity-reserved vector and | ||
| * return the drained events in insertion order. | ||
| * | ||
| * The swap happens under the mutex; producers can write to the fresh live | ||
| * vector while the consumer processes the returned one. | ||
| */ | ||
| [[nodiscard]] std::vector<nixlTelemetryEvent> | ||
| takePending(); | ||
|
|
||
| /** | ||
| * @brief Atomically take and reset the number of staging drops accumulated | ||
| * since the previous call. | ||
| */ | ||
| [[nodiscard]] uint64_t | ||
| takeNumDropped() noexcept; | ||
|
|
||
| [[nodiscard]] size_t | ||
| capacity() const noexcept; | ||
|
|
||
| private: | ||
| const size_t capacity_; | ||
| std::vector<nixlTelemetryEvent> events_; | ||
| std::mutex mutex_; | ||
| std::atomic<uint64_t> numDroppedEvents_{0}; | ||
| }; | ||
|
|
||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| telemetry_unit_test_dep = declare_dependency( | ||
| sources: [ | ||
| 'telemetry_staging_queue_test.cpp', | ||
| ], | ||
| include_directories: [nixl_inc_dirs, gtest_inc_dirs], | ||
| dependencies: [gmock_dep, nixl_common_dep], | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.