-
Notifications
You must be signed in to change notification settings - Fork 1
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
request counters #75
Conversation
87f6f51
to
d02050d
Compare
b5fc2cc
to
20024a6
Compare
…tors drop test. Yagna ver update.
20024a6
to
244b539
Compare
0599d44
to
35fd3ea
Compare
0ac6add
to
2ad3bac
Compare
let mut proxy = GsbToHttpProxy { | ||
// base_url: "http://10.30.13.8:7861/".to_string(), |
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.
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(); |
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.
Maybe counters.current_usage()
should return tuple of usage vector and timestamp 🤷♂️
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 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`. |
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.
👍🏻
#[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) | ||
} | ||
} |
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 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.
trait RequestMonitoringCounter: Counter { | ||
fn on_request(&mut self, request_time: DateTime<Utc>); | ||
fn on_response(&mut self, response_time: DateTime<Utc>); | ||
} |
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.
Why do you need another trait here if you have ResponseMonitor
and RequestMonitor
already?
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.
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.
// 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}"); |
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.
Please remove unused prints here and in the rest of tests
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 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.
pub(super) struct RequestsMonitoringCounters { | ||
counters: SharedCounters, | ||
response_time_tx: UnboundedSender<DateTime<Utc>>, | ||
} |
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.
Why do you need another object for handling counters?
Can't you just implement traits for Counters
struct?
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.
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).
I made |
Work continued in PR #84 |
Resolves: #56
Resolves: #57