-
Notifications
You must be signed in to change notification settings - Fork 10
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
fix: run publisher in its own task #188
Conversation
WS1-1339 DHT flaky tests
We believe the DHT publish logic is starving the swarm task. We should run it on its own task. DOD:
|
Locally this works well, however I'd like to test in dev/QA with better load to determine how well it works. We can revert if its not sufficient. |
let mut stream = PublisherStream::new(results_rx, interval, block_store, metrics.clone()); | ||
let task_metrics = metrics.clone(); | ||
tokio::spawn(async move { | ||
while let Some(batch) = stream.next().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.
So:
- The
Publisher
drivesPublisherStream
in a separate task. PublisherStream
builds and returns batches into a channel that gets polled by the swarm task.- The swarm publishes a batch and returns results via another channel that gets consumed first before a new batch is returned.
Does this sound like an accurate description?
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.
And it's the SQL lookups/batching logic that's been moved out from the swarm task to its own task, via PublisherStream
.
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.
PublisherStream builds and returns batches into a channel that gets polled by the swarm task.
This part is technically incorrect. Both the Publisher and PublisherStream types implement the Stream trait. The swarm is unware that PublisherStream exists or that the channel exists. So the swarm task polls the Publisher for the next batch. The only work the Publisher does is to read a channel if something is available.
The swarm publishes a batch and returns results via another channel that gets consumed first before a new batch is returned.
Yes except the swarm is unware of the results channel as well. It simply calls the handle method on the Publisher which puts the result on a channel that the PublisherStream reads.
So generally correct except that the Publisher abstraction means that the swarm doesn't care that channels and a separate task are being used under the hood.
Perhaps I should rename PublisherStream to PublisherWorker? That way its not misleading that they both implement Stream?
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.
Ah gotcha, makes sense, ty! I got confused by the two layers of streams.
Yeah, I think calling it PublisherWorker would help.
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.
Or perhaps even PublisherStream and PublisherWorkerStream but not a strong preference.
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.
I changed the names to Publisher
and PublisherWorker
. Keep it simple. I have added comments about the fact they implement the Stream trait and why.
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 change makes the Publisher logic run in its own task. This is to relieve CPU pressure from the swarm task.
12f93cb
to
92fce7b
Compare
This change makes the Publisher logic run in its own task. This is to relieve CPU pressure from the swarm task.