-
Notifications
You must be signed in to change notification settings - Fork 3
Feature/metric proxy bindings #16
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
Tim-Dieringer
wants to merge
7
commits into
development
Choose a base branch
from
feature/metric_proxy_bindings
base: development
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
7 commits
Select commit
Hold shift + click to select a range
87fb827
Initial zmq communication for metric proxy
Tim-Dieringer 604ea4a
Changed proxy communication to msgpack from JSON
Tim-Dieringer 2e623c9
Added wave names to ftio task output
Tim-Dieringer 6ed20b3
Added dynamic initial port and ability to change port at runtime
Tim-Dieringer 3d4eb00
Optimized metric processing for high core counts
Tim-Dieringer 7a0ac99
Simplified code and added information to contributing.md
Tim-Dieringer c19e484
Merge remote-tracking branch 'origin/development' into feature/metric…
Tim-Dieringer 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| import math | ||
| import time | ||
| import numpy as np | ||
| import zmq | ||
| import msgpack | ||
| from rich.console import Console | ||
|
|
||
| from multiprocessing import Pool, cpu_count | ||
| from ftio.api.metric_proxy.parallel_proxy import execute, execute_parallel | ||
| from ftio.prediction.tasks import ftio_metric_task, ftio_metric_task_save | ||
|
|
||
| from ftio.api.metric_proxy.parse_proxy import filter_metrics | ||
| from ftio.freq.helper import MyConsole | ||
| import signal | ||
|
|
||
| CONSOLE = MyConsole() | ||
| CONSOLE.set(True) | ||
|
|
||
| CURRENT_ADDRESS = None | ||
| IDLE_TIMEOUT = 100 | ||
| last_request = time.time() | ||
|
|
||
| def sanitize(obj): | ||
| if isinstance(obj, np.ndarray): | ||
| return obj.tolist() | ||
| elif isinstance(obj, dict): | ||
| return {k: sanitize(v) for k, v in obj.items()} | ||
| elif isinstance(obj, list): | ||
| return [sanitize(v) for v in obj] | ||
| return obj | ||
|
|
||
|
|
||
| def handle_request(msg: bytes) -> bytes: | ||
| """Handle one FTIO request via ZMQ.""" | ||
| global CURRENT_ADDRESS | ||
|
|
||
| if msg == b"ping": | ||
| return b"pong" | ||
|
|
||
| if msg.startswith(b"New Address: "): | ||
| new_address = msg[len(b"New Address: "):].decode() | ||
| CURRENT_ADDRESS = new_address | ||
| return b"Address updated" | ||
|
|
||
| try: | ||
| req = msgpack.unpackb(msg, raw=False) | ||
| argv = req.get("argv", []) | ||
| raw_metrics = req.get("metrics", []) | ||
|
|
||
| metrics = filter_metrics(raw_metrics, filter_deriv=False) | ||
| print(f"Processing {len(metrics)} metrics") | ||
|
|
||
| print(f"With Arguments: {argv}") | ||
| argv.extend(["-e", "no"]) | ||
|
|
||
| disable_parallel = req.get("disable_parallel", False) | ||
|
|
||
| ranks = 32 | ||
|
|
||
|
|
||
| except Exception as e: | ||
| return msgpack.packb({"error": f"Invalid request: {e}"}, use_bin_type=True) | ||
|
|
||
| try: | ||
| t = time.process_time() | ||
| if disable_parallel: | ||
| data = execute(metrics, argv, ranks, False) | ||
| else: | ||
| data = execute_parallel(metrics, argv, ranks) | ||
| elapsed_time = time.process_time() - t | ||
| CONSOLE.info(f"[blue]Calculation time: {elapsed_time} s[/]") | ||
|
|
||
| native_data = sanitize(list(data)) | ||
|
|
||
| return msgpack.packb(native_data, use_bin_type=True) | ||
|
|
||
| except Exception as e: | ||
| print(f"Error during processing: {e}") | ||
| return msgpack.packb({"error": str(e)}, use_bin_type=True) | ||
|
|
||
|
|
||
| def main(address: str = "tcp://*:0"): | ||
| """FTIO ZMQ Server entrypoint for Metric Proxy.""" | ||
| global CURRENT_ADDRESS, last_request, POOL | ||
| context = zmq.Context() | ||
| socket = context.socket(zmq.REP) | ||
| socket.bind(address) | ||
| CURRENT_ADDRESS = address | ||
|
|
||
| signal.signal(signal.SIGTERM, shutdown_handler) | ||
| signal.signal(signal.SIGINT, shutdown_handler) | ||
|
|
||
| endpoint = socket.getsockopt(zmq.LAST_ENDPOINT).decode() | ||
| print(endpoint, flush=True) | ||
|
|
||
| console = Console() | ||
| console.print(f"[green]FTIO ZMQ Server listening on {endpoint}[/]") | ||
|
|
||
| try: | ||
| while True: | ||
| if socket.poll(timeout=1000): | ||
| msg = socket.recv() | ||
| console.print(f"[cyan]Received request ({len(msg)} bytes)[/]") | ||
| last_request = time.time() | ||
| reply = handle_request(msg) | ||
| socket.send(reply) | ||
|
|
||
| if reply == b"Address updated": | ||
| console.print(f"[yellow]Updated address to {CURRENT_ADDRESS}[/]") | ||
| socket.close() | ||
| socket = context.socket(zmq.REP) | ||
| socket.bind(CURRENT_ADDRESS) | ||
| else: | ||
| if time.time() - last_request > IDLE_TIMEOUT: | ||
| console.print("Idle timeout reached, shutting down server") | ||
| break | ||
| finally: | ||
| socket.close(linger=0) | ||
| context.term() | ||
|
|
||
|
|
||
| def shutdown_handler(signum, frame): | ||
| raise SystemExit | ||
|
|
||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
A-Tarraf marked this conversation as resolved.
Show resolved
Hide resolved
|
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.
Is this actually used, or do you use the prediction server already implemented in FTIO?
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.
ftio/api/metric_proxy/proxy_zmq.py is a zmq server to specifically support what metric proxy needs, so it is used. It's probably possible to change proxy_zmq.py to rely on some of the already implemented functions instead of using a complete custom method but that would require refactoring.
Uh oh!
There was an error while loading. Please reload this page.
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.
No, this is fine. I was just wondering because we introduced a new class (prediction) and wanted to avoid dictionaries. But if there is no way to use the class, we can keep it this way. I would just suggest that you document these points alongside some instructions (e.g., call tree?) in a separate file for FTIO as described here: https://github.com/tuda-parallel/FTIO/blob/feature/pattern_change_detection/docs/students_contribute.md#-module-documentation-and-licensing. Also, maybe you can add some test cases so that we do not break these functionalities in the future with newer commits (https://github.com/tuda-parallel/FTIO/blob/feature/pattern_change_detection/docs/students_contribute.md#-module-documentation-and-licensing)