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

Benchmark should not panic on server close #970

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions async-nats/benches/core_nats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ pub fn publish(c: &mut Criterion) {

pub fn subscribe(c: &mut Criterion) {
let server = nats_server::run_basic_server();

let mut subscribe_amount_group = c.benchmark_group("subscribe amount");
subscribe_amount_group.sample_size(30);
subscribe_amount_group.warm_up_time(std::time::Duration::from_secs(1));
Expand All @@ -82,9 +81,12 @@ pub fn subscribe(c: &mut Criterion) {
let msg = &bmsg[0..*size].to_vec();

loop {
nc.publish("bench".to_string(), msg.clone().into())
.await
.unwrap();
let result =
Copy link
Member

Choose a reason for hiding this comment

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

Maybe better directly check for disconnect event on the client and the break the loop, log publish errors (but not panic)?

The benchmark results and report would be cleaner about what happened.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So about printing the error, I don't want to give the impression that the benchmark failed when its expected (albeit racy behavior).

Could instead just loop from 0 to N and still unwrap.

Copy link
Member

Choose a reason for hiding this comment

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

I get your point and agree with it.
I'm talking about maybe having more graceful and controlled shutdown of server/clients in benchmarks.

nc.publish("bench".to_string(), msg.clone().into()).await;

if result.is_err() {
break;
}
}
}
});
Expand Down