Skip to content

Commit b04fd9f

Browse files
committed
main: Use crossbeam channel for tokio contention check
I observed a panic due to a bug in std rust-lang/rust#39364, switching to crossbeam fixes that and improves performance, which reduces the effect of the channel in the timing.
1 parent 4f2abd5 commit b04fd9f

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ futures = "0.1.21"
1010
git-testament = "0.1"
1111
graphql-parser = "0.2.1"
1212
http = "0.1"
13+
1314
# We're using the latest ipfs-api for the HTTPS support that was merged in
1415
# https://github.com/ferristseng/rust-ipfs-api/commit/55902e98d868dcce047863859caf596a629d10ec
1516
# but has not been released yet.
@@ -18,6 +19,7 @@ itertools = "0.7"
1819
lazy_static = "1.2.0"
1920
sentry = "0.15.1"
2021
url = "1.7.1"
22+
crossbeam-channel = "0.3.8"
2123
graph = { path = "../graph" }
2224
graph-core = { path = "../core" }
2325
graph-datasource-ethereum = { path = "../datasource/ethereum" }

node/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,15 +575,15 @@ fn async_main() -> impl Future<Item = (), Error = ()> + Send + 'static {
575575
// Periodically check for contention in the tokio threadpool. First spawn a
576576
// task that simply responds to "ping" requests. Then spawn a separate
577577
// thread to periodically ping it and check responsiveness.
578-
let (ping_send, ping_receive) = mpsc::channel::<std::sync::mpsc::Sender<()>>(1);
578+
let (ping_send, ping_receive) = mpsc::channel::<crossbeam_channel::Sender<()>>(1);
579579
tokio::spawn(
580580
ping_receive
581581
.for_each(move |pong_send| pong_send.clone().send(()).map(|_| ()).map_err(|_| ())),
582582
);
583583
let contention_logger = logger.clone();
584584
std::thread::spawn(move || loop {
585585
std::thread::sleep(Duration::from_millis(100));
586-
let (pong_send, pong_receive) = std::sync::mpsc::channel();
586+
let (pong_send, pong_receive) = crossbeam_channel::bounded(1);
587587
ping_send.clone().send(pong_send).wait().unwrap();
588588
let mut timeout = Duration::from_millis(1);
589589
while pong_receive.recv_timeout(timeout).is_err() {

0 commit comments

Comments
 (0)