-
Notifications
You must be signed in to change notification settings - Fork 487
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
feat: add fluvio producer callback #4340
base: master
Are you sure you want to change the base?
Conversation
21775b3
to
a283846
Compare
a283846
to
530de55
Compare
530de55
to
c182387
Compare
self.stat.start(); | ||
let time = std::time::Instant::now(); | ||
let send_out = self | ||
self.stat.start().await; |
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.
should remove this
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.
Start is setting the first instant to calculate the final bandwidth at the end.
.fluvio_producer | ||
.send(record.key, record.data.clone()) | ||
.await?; | ||
|
||
self.stat.send_out((send_out, time)); | ||
self.stat.add_record(record.data.len() as u64).await; |
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 longer need this
} | ||
// send end | ||
let hist = hist.lock().await; | ||
let start_time = start_time.lock().await.expect("start time"); |
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.
start time should be tracked by callback?
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.
This is the first start time, I can rename it
// send end | ||
let hist = hist.lock().await; | ||
let start_time = start_time.lock().await.expect("start time"); | ||
let elapsed = start_time.elapsed(); |
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.
this should be come from callback
@@ -118,6 +120,9 @@ pub struct TopicProducerConfig { | |||
|
|||
#[builder(default)] | |||
pub(crate) smartmodules: Vec<SmartModuleInvocation>, | |||
|
|||
#[builder(setter(into, strip_option), default)] | |||
pub(crate) callback: Option<SharedProducerCallback<ProduceCompletionEvent>>, |
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 make generic? don't think there is need to make generic
created_at: batch_metadata.created_at, | ||
metadata: batch_metadata.clone(), | ||
}; | ||
callback.finished(event).await.unwrap(); |
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.
remove unwrap
} | ||
|
||
pub(crate) fn set_current_time(&mut self) { | ||
self.start_time = Instant::now(); | ||
pub(crate) fn add_record(&mut self, bytes: u64) { |
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.
this should be invoked by callback
This PR adds a callback option for the producer.
Also prints total bytes and total records per sec at the end: