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

Some refactor to fast workers #655

Merged
merged 1 commit into from
Jan 10, 2025
Merged
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
88 changes: 32 additions & 56 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1924,8 +1924,8 @@ pub mod fast {
});
let token = tokio_util::sync::CancellationToken::new();

if client.is_work_http2() {
let handles = connections
let handles = if client.is_work_http2() {
connections
.map(|num_connections| {
let report_tx = report_tx.clone();
let counter = counter.clone();
Expand Down Expand Up @@ -2036,19 +2036,9 @@ pub mod fast {
rt.block_on(local);
})
})
.collect::<Vec<_>>();
tokio::spawn(async move {
tokio::signal::ctrl_c().await.unwrap();
token.cancel();
});

tokio::task::block_in_place(|| {
for handle in handles {
let _ = handle.join();
}
});
.collect::<Vec<_>>()
} else {
let handles = connections
connections
.map(|num_connection| {
let report_tx = report_tx.clone();
let counter = counter.clone();
Expand Down Expand Up @@ -2090,19 +2080,19 @@ pub mod fast {
rt.block_on(local);
})
})
.collect::<Vec<_>>();
.collect::<Vec<_>>()
};

tokio::spawn(async move {
tokio::signal::ctrl_c().await.unwrap();
token.cancel();
});
tokio::spawn(async move {
tokio::signal::ctrl_c().await.unwrap();
token.cancel();
});

tokio::task::block_in_place(|| {
for handle in handles {
let _ = handle.join();
}
});
};
tokio::task::block_in_place(|| {
for handle in handles {
let _ = handle.join();
}
});
}

/// Run until dead_line by n workers
Expand Down Expand Up @@ -2132,8 +2122,8 @@ pub mod fast {
}
});
let token = tokio_util::sync::CancellationToken::new();
if client.is_work_http2() {
let handles = connections
let handles = if client.is_work_http2() {
connections
.map(|num_connections| {
let report_tx = report_tx.clone();
let client = client.clone();
Expand Down Expand Up @@ -2238,24 +2228,9 @@ pub mod fast {
rt.block_on(local);
})
})
.collect::<Vec<_>>();
tokio::select! {
_ = tokio::time::sleep_until(dead_line.into()) => {
}
_ = tokio::signal::ctrl_c() => {
}
}

is_end.store(true, Ordering::Relaxed);

if !wait_ongoing_requests_after_deadline {
token.cancel();
}
for handle in handles {
let _ = handle.join();
}
.collect::<Vec<_>>()
} else {
let handles = (0..num_threads)
(0..num_threads)
.filter_map(|i| {
let num_connection = n_connections / num_threads
+ (if (n_connections % num_threads) > i {
Expand Down Expand Up @@ -2315,23 +2290,24 @@ pub mod fast {
rt.block_on(local);
})
})
.collect::<Vec<_>>();

tokio::select! {
_ = tokio::time::sleep_until(dead_line.into()) => {
}
_ = tokio::signal::ctrl_c() => {
}
.collect::<Vec<_>>()
};
tokio::select! {
_ = tokio::time::sleep_until(dead_line.into()) => {
}
_ = tokio::signal::ctrl_c() => {
}
}

is_end.store(true, Ordering::Relaxed);
is_end.store(true, Ordering::Relaxed);

if !wait_ongoing_requests_after_deadline {
token.cancel();
}
if !wait_ongoing_requests_after_deadline {
token.cancel();
}
tokio::task::block_in_place(|| {
for handle in handles {
let _ = handle.join();
}
};
});
}
}
Loading