Skip to content

Improve PayloadBuilderService polling service #4403

Closed
@tcoratger

Description

Describe the feature

At the moment, a new_job boolean flag is used and modified inside a while condition that drains all requests:

// TODO(mattsse): this could be optmized so we only poll new jobs
let mut new_job = false;
// drain all requests
while let Poll::Ready(Some(cmd)) = this.command_rx.poll_next_unpin(cx) {
match cmd {
PayloadServiceCommand::BuildNewPayload(attr, tx) => {
let id = attr.payload_id();
let mut res = Ok(id);
if this.contains_payload(id) {
warn!(%id, parent = ?attr.parent, "Payload job already in progress, ignoring.");
} else {
// no job for this payload yet, create one
match this.generator.new_payload_job(attr) {
Ok(job) => {
this.metrics.inc_initiated_jobs();
new_job = true;
this.payload_jobs.push((job, id));
}
Err(err) => {
this.metrics.inc_failed_jobs();
warn!(?err, %id, "Failed to create payload builder job");
res = Err(err);
}
}
}
// return the id of the payload
let _ = tx.send(res);
}
PayloadServiceCommand::BestPayload(id, tx) => {
let _ = tx.send(this.best_payload(id));
}
PayloadServiceCommand::Resolve(id, tx) => {
let _ = tx.send(this.resolve(id));
}
}
}
if !new_job {
return Poll::Pending
}

At the end, if new_job is false, Poll::Pending is returned. We could improve the efficiency here by polling only new jobs.

Additional context

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

Type

No type

Projects

  • Status

    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions