-
Notifications
You must be signed in to change notification settings - Fork 183
ETCD: initial heartbeat thread #1010
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
tstamler
wants to merge
10
commits into
ai-dynamo:main
Choose a base branch
from
tstamler:etcd_heartbeat
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
10 commits
Select commit
Hold shift + click to select a range
dfbfa40
ETCD: initial heartbeat thread
tstamler 864d63a
refactor
tstamler 2d39fa6
bug fixes
tstamler c1cd6b7
API update
tstamler ea70af4
functional
tstamler 17c1fcd
precommit
tstamler 7985b71
clang format
tstamler c2065fd
Merge branch 'main' into etcd_heartbeat
aranadive b5065dc
heartbeat for whole agent
tstamler 4e8f87d
Merge branch 'main' into etcd_heartbeat
aranadive 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025 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. | ||
|
|
||
| import multiprocessing | ||
| import time | ||
|
|
||
| import torch | ||
|
|
||
| from nixl._api import nixl_agent, nixl_agent_config | ||
| from nixl.logging import get_logger | ||
|
|
||
| logger = get_logger(__name__) | ||
|
|
||
|
|
||
| def run_target(): | ||
| """ | ||
| Target mode function that runs in a subprocess. | ||
| This posts metadata to etcd and then is killed. | ||
| """ | ||
| logger.info("Target subprocess started") | ||
|
|
||
| config = nixl_agent_config(True, True, 5555) | ||
|
|
||
| # Allocate memory and register with NIXL | ||
| agent = nixl_agent( | ||
| "target", | ||
| config, | ||
| ) | ||
| tensors = [torch.ones(10, dtype=torch.float32) for _ in range(2)] | ||
|
|
||
| logger.info("Target running with tensors: %s", tensors) | ||
|
|
||
| reg_descs = agent.register_memory(tensors) | ||
| if not reg_descs: | ||
| logger.error("Target: Memory registration failed.") | ||
| return | ||
|
|
||
| agent.send_local_metadata() | ||
|
|
||
| logger.info("Waiting to die") | ||
|
|
||
| time.sleep(100) | ||
|
|
||
| agent.deregister_memory(reg_descs) | ||
|
|
||
| logger.info("Target subprocess complete successfully (should have died by now).") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| # Start the target process | ||
| target_process = multiprocessing.Process(target=run_target) | ||
| target_process.start() | ||
|
|
||
| logger.info("Subprocess started, pausing...") | ||
|
|
||
| time.sleep(5) | ||
|
|
||
| config = nixl_agent_config(True, True) | ||
|
|
||
| agent = nixl_agent("initiator", config) | ||
|
|
||
| # Fetch remote metadata when its ready | ||
| agent.fetch_remote_metadata("target") | ||
|
|
||
| # Ensure remote metadata has arrived from fetch | ||
| ready = False | ||
| while not ready: | ||
| ready = agent.check_remote_metadata("target") | ||
|
|
||
| logger.info("Ready to kill, pausing...") | ||
|
|
||
| time.sleep(5) | ||
| # SIGKILL the target process to test heartbeat failure | ||
| target_process.kill() | ||
|
|
||
| logger.info("Target process killed, waiting for metadata to be invalidated") | ||
|
|
||
| # Wait for metadata to be invalidated | ||
| ready = True | ||
| while ready: | ||
| ready = agent.check_remote_metadata("target") | ||
|
|
||
| agent.invalidate_local_metadata() | ||
|
|
||
| logger.info("Test Complete.") |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs to be a queue of lease ids. If an agent can store multiple metadata within etcd we will have multiple lease ids. We should add all those to a queue (like the commqueue) and the heartbeat thread should just loop over all of them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another way would be add some special known key to deem an agent active and create a lease_id only for that. The agent keeps this key alive, and the other agents watcher only checks this key. If this key is deleted that means the agent is gone, so delete all MD for it.