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

request counters #75

Closed
wants to merge 13 commits into from
Closed

request counters #75

wants to merge 13 commits into from

Conversation

pwalski
Copy link
Contributor

@pwalski pwalski commented Mar 15, 2024

Resolves: #56
Resolves: #57

@pwalski pwalski force-pushed the pwalski/request_time_counter branch 2 times, most recently from 87f6f51 to d02050d Compare March 17, 2024 20:59
@pwalski pwalski force-pushed the pwalski/request_time_counter branch 2 times, most recently from b5fc2cc to 20024a6 Compare March 18, 2024 18:57
@pwalski pwalski force-pushed the pwalski/request_time_counter branch from 20024a6 to 244b539 Compare March 18, 2024 19:19
@pwalski pwalski force-pushed the pwalski/request_time_counter branch from 0599d44 to 35fd3ea Compare March 19, 2024 10:00
@pwalski pwalski marked this pull request as ready for review March 19, 2024 10:06
@pwalski pwalski force-pushed the pwalski/request_time_counter branch from 0ac6add to 2ad3bac Compare March 19, 2024 10:58
let mut proxy = GsbToHttpProxy {
// base_url: "http://10.30.13.8:7861/".to_string(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accidentally removed it. Sorry.

current_usage[idx] = duration.to_std()?.as_secs_f64();
}
let current_usage = counters.current_usage().await;
let timestamp = Utc::now().timestamp();
Copy link
Contributor Author

@pwalski pwalski Mar 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe counters.current_usage() should return tuple of usage vector and timestamp 🤷‍♂️

@pwalski pwalski changed the title request time counter request counters Mar 19, 2024
Copy link
Contributor

@nieznanysprawiciel nieznanysprawiciel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate efforts to make abstractions for Counters and Requests monitoring.I think that they could be better.

First of all some part of counters implementations should be in yagna. Requests counters are something that every user of the library would like to use. On the other side duration counter is something more general and should probably stay in ya-runtime-ai.
Abstractions that you build should reflect this split of responsibility.

The second thing: some parts of abstractions are over-complicated. I don't thing you need as many traits. I posted details in comments.

}
}

// Failsafe for not calling `on_response`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

Comment on lines +58 to +77
#[derive(Debug)]
enum SupportedCounter {
Duration(DurationCounter),
RequestsDuration(RequestsDurationCounter),
RequestsCount(RequestsCounter),
}

impl FromStr for SupportedCounter {
type Err = anyhow::Error;

fn from_str(counter: &str) -> anyhow::Result<Self, Self::Err> {
let counter = match counter {
"golem.usage.duration_sec" => SupportedCounter::Duration(Default::default()),
"golem.usage.gpu-sec" => SupportedCounter::RequestsDuration(Default::default()),
"ai-runtime.requests" => SupportedCounter::RequestsCount(Default::default()),
_ => bail!("Unsupported counter: {}", counter),
};
Ok(counter)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not the best abstraction for counters we can have.
It serves well on creation, because number of possibilities is limited, but later you must implement every trait for this object. Imagine how much work would it cost to add new type of counter in comparison to just storing vector of boxed dyn traits.

It would be better to replace this with something like factory for counters.

Comment on lines +104 to +107
trait RequestMonitoringCounter: Counter {
fn on_request(&mut self, request_time: DateTime<Utc>);
fn on_response(&mut self, response_time: DateTime<Utc>);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need another trait here if you have ResponseMonitor and RequestMonitor already?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ResponseMonitor and RequestMonitor are splitted only to handle automatic on_response on drop of ResponseMonitor. Besides these traits do not accept time as a parameter. I pass time parameter because I want to use same time for every counter.

Comment on lines +196 to +202
// odd step number
// println!("Short request on step: {i}");
let response_monitor = requests_monitor.on_request().await;
// println!("Short request on step: {i}. Done.");
tokio::time::sleep(delay).await;
response_monitor.on_response();
// println!("Short request response on step: {i}");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove unused prints here and in the rest of tests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left them because test verifies time measurement which makes stoping with debugger difficult. Printing to console every single time is unnecessary. Of course I can remove these commented prints.

Comment on lines +8 to +11
pub(super) struct RequestsMonitoringCounters {
counters: SharedCounters,
response_time_tx: UnboundedSender<DateTime<Utc>>,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need another object for handling counters?
Can't you just implement traits for Counters struct?

Copy link
Contributor Author

@pwalski pwalski Mar 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I could have rename it similar to name of the module.
I wanted to have a counter implementation combining all counters which would also implement RequestMonitor trait.
At the same time I did not wanted to have top level struct Counters to implement it (and implementation of pub trait on pub struct cannot be private).

@pwalski
Copy link
Contributor Author

pwalski commented Mar 20, 2024

First of all some part of counters implementations should be in yagna. Requests counters are something that every user of the library would like to use. On the other side duration counter is something more general and should probably stay in ya-runtime-ai.
Abstractions that you build should reflect this split of responsibility.

I made gsb-http-proxy to provide only a Response/RequestMonitor traits and their functions usage implementation, because I considered counters to be a part of Agreement domain and gsb-http-proxy knows nothing about it. Library knows what is a response and what is a request, and it is all it does regarding counters. The way Requests counter and Request (GPU) duration counter internally work is inseparable to its id/name, and this is a part of Agreement and I assumed it should not be inside gsb-http-proxy.
Additionally I wanted to implement counters as a tool converting golem/com/usage/vector from Agreement into corresponding currentUsage property of Activity, and hide this implementation. This conversion of a list of some names into a list of f64 values according to some opaque rules is confusing (can the list be empty? what to do on unsupported counter? can it have duplicates? (accidentally it can)).
@nieznanysprawiciel

@pwalski
Copy link
Contributor Author

pwalski commented Apr 2, 2024

Work continued in PR #84

@pwalski pwalski closed this Apr 2, 2024
@pwalski pwalski deleted the pwalski/request_time_counter branch April 2, 2024 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Usage counters - number of requests Usage counters - GPU
2 participants