Skip to content

Move the subgraph task to the blocking thread pool #956

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

Merged
merged 1 commit into from
May 22, 2019
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ serde = "1.0"
serde_json = "1.0"
serde_yaml = "0.7"
uuid = { version = "0.7.2", features = ["v4"] }
tokio-threadpool = "0.1.14"

[dev-dependencies]
# We're using the latest ipfs-api for the HTTPS support that was merged in
Expand Down
12 changes: 11 additions & 1 deletion core/src/subgraph/instance_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,17 @@ impl SubgraphInstanceManager {
// creates dynamic data sources. This allows us to recreate the
// block stream and include events for the new data sources going
// forward; this is easier than updating the existing block stream.
tokio::spawn(loop_fn(ctx, move |ctx| run_subgraph(ctx)));
let mut subgraph_task = loop_fn(ctx, |ctx| run_subgraph(ctx));

// This task has many calls to the store, so mark it as `blocking`.
tokio::spawn(future::poll_fn(move || {
match tokio_threadpool::blocking(|| subgraph_task.poll()) {
Ok(Async::NotReady) | Ok(Async::Ready(Ok(Async::NotReady))) => Ok(Async::NotReady),
Ok(Async::Ready(Ok(Async::Ready(())))) => Ok(Async::Ready(())),
Ok(Async::Ready(Err(()))) => Err(()),
Err(_) => panic!("not inside a tokio thread pool"),
}
}));

Ok(())
}
Expand Down