-
Notifications
You must be signed in to change notification settings - Fork 22
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
Usage reporting tweaks #536
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cda4ca3
parametrize the display of usage in the simple service
shadeofblue 871ed5e
black ...
shadeofblue 979628d
add type for `instance_name`
shadeofblue 110bfd0
better usage reporting
shadeofblue cfaa1be
actually, a dataclass instead of dict (for better typing support et al)
shadeofblue 0846129
human linter ;)
shadeofblue 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 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 |
---|---|---|
|
@@ -39,9 +39,10 @@ class SimpleService(Service): | |
SIMPLE_SERVICE = "/golem/run/simple_service.py" | ||
SIMPLE_SERVICE_CTL = "/golem/run/simulate_observations_ctl.py" | ||
|
||
def __init__(self, *args, instance_name, **kwargs): | ||
def __init__(self, *args, instance_name, show_usage: bool = False, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.name = instance_name | ||
self._show_usage = show_usage | ||
|
||
@staticmethod | ||
async def get_payload(): | ||
|
@@ -81,18 +82,20 @@ async def run(self): | |
steps = self._ctx.commit() | ||
yield steps | ||
|
||
print(f" --- {self._ctx.provider_name} USAGE: {await self._ctx.get_usage()}") | ||
print(f" --- {self._ctx.provider_name} STATE: {await self._ctx.get_state()}") | ||
print(f" --- {self._ctx.provider_name} COST: {await self._ctx.get_cost()}") | ||
if self._show_usage: | ||
print(f" --- {self.name} USAGE: {await self._ctx.get_usage()}") | ||
print(f" --- {self.name} STATE: {await self._ctx.get_state()}") | ||
print(f" --- {self.name} COST: {await self._ctx.get_cost()}") | ||
|
||
async def shutdown(self): | ||
# handler reponsible for executing operations on shutdown | ||
self._ctx.run(self.SIMPLE_SERVICE_CTL, "--stop") | ||
yield self._ctx.commit() | ||
print(f" --- {self._ctx.provider_name} COST: {await self._ctx.get_cost()}") | ||
if self._show_usage: | ||
print(f" --- {self.name} COST: {await self._ctx.get_cost()}") | ||
|
||
|
||
async def main(subnet_tag, running_time, driver=None, network=None, num_instances=1): | ||
async def main(subnet_tag, running_time, driver=None, network=None, num_instances=1, show_usage=False): | ||
async with Golem( | ||
budget=1.0, | ||
subnet_tag=subnet_tag, | ||
|
@@ -120,7 +123,7 @@ async def main(subnet_tag, running_time, driver=None, network=None, num_instance | |
cluster = await golem.run_service( | ||
SimpleService, | ||
instance_params=[ | ||
{"instance_name": f"simple-service-{i+1}"} for i in range(num_instances) | ||
{"instance_name": f"simple-service-{i+1}", "show_usage": show_usage} for i in range(num_instances) | ||
], | ||
expiration=datetime.now(timezone.utc) + timedelta(minutes=120), | ||
) | ||
|
@@ -184,7 +187,8 @@ def still_starting(): | |
"(in seconds, default: %(default)s)" | ||
), | ||
) | ||
parser.add_argument("--num-instances", type=int, default=1) | ||
parser.add_argument("--num-instances", type=int, default=1, help="The number of instances of the service to spawn") | ||
parser.add_argument("--show-usage", action="store_true", help="Show usage and cost of each instance while running.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done ;) |
||
now = datetime.now().strftime("%Y-%m-%d_%H.%M.%S") | ||
parser.set_defaults(log_file=f"simple-service-yapapi-{now}.log") | ||
args = parser.parse_args() | ||
|
@@ -207,6 +211,7 @@ def still_starting(): | |
driver=args.driver, | ||
network=args.network, | ||
num_instances=args.num_instances, | ||
show_usage=args.show_usage, | ||
) | ||
) | ||
|
||
|
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'd either specify types for both
instance_name
andshow_usage
, or for neither 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.
I mean, here, done ;)