Skip to content

Feat; mark benchmark requests as complete #2214

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 8 commits into from
Aug 5, 2025

Conversation

Jamesbarford
Copy link
Contributor

Related to; #2200 which I've closed as it was becoming fiddly to update.

  • Mark benchmark_request's as complete based on;
    • parent being complete if there is a parent
    • all jobs in the job_queue being in a terminal state.

.conn()
.query_opt(
"
UPDATE
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit of a monster but atomically achieves what we want it to.

The query uses indexes as can be seen here through running EXPLAIN ANALYSE below.

It's verbose however the points of interest are all operations use either index scans or bitmap index scans

Update on benchmark_request  (cost=4.71..28.37 rows=1 width=52) (actual time=0.047..0.049 rows=0 loops=1)
   ->  Nested Loop Anti Join  (cost=4.71..28.37 rows=1 width=52) (actual time=0.045..0.047 rows=0 loops=1)
         ->  Index Scan using benchmark_request_tag_key on benchmark_request  (cost=0.42..17.14 rows=1 width=15) (actual time=0.045..0.046 rows=0 loops=1)
               Index Cond: (tag = 'foo'::text)
               Filter: ((status <> 'completed'::text) AND ((parent_sha IS NULL) OR (NOT (SubPlan 1))))
               SubPlan 1
                 ->  Nested Loop  (cost=0.70..16.71 rows=2 width=0) (never executed)
                       ->  Index Scan using job_queue_request_tag_idx on job_queue job_queue_1  (cost=0.28..12.25 rows=2 width=8) (never executed)
                             Index Cond: (request_tag = benchmark_request.parent_sha)
                             Filter: (status <> ALL ('{success,failure}'::text[]))
                       ->  Materialize  (cost=0.42..4.44 rows=1 width=9) (never executed)
                             ->  Index Only Scan using benchmark_request_tag_key on benchmark_request parent_request  (cost=0.42..4.44 rows=1 width=9) (never execut
ed)
                                   Index Cond: (tag = benchmark_request.parent_sha)
                                   Heap Fetches: 0
         ->  Bitmap Heap Scan on job_queue  (cost=4.30..11.21 rows=2 width=14) (never executed)
               Recheck Cond: (request_tag = 'foo'::text)
               Filter: (status <> ALL ('{success,failure}'::text[]))
               ->  Bitmap Index Scan on job_queue_request_tag_idx  (cost=0.00..4.29 rows=2 width=0) (never executed)
                     Index Cond: (request_tag = 'foo'::text)
 Planning Time: 2.288 ms
 Execution Time: 0.238 ms

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm open to suggestions on how to test this. The obstacles I see are;

  • Marking jobs as complete.
  • A way of getting a benchmark request (or Vec of them) to see if one was marked as complete.

@Jamesbarford Jamesbarford requested a review from Kobzol July 31, 2025 15:28
Copy link
Member

@Kobzol Kobzol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks. I think that for testing we will need to move forward with my part (mark jobs as completed etc.). I started working on it, but it's more work than I expected, and I'm a bit stuck on reviews now.

If you want to move forward in parallel, you can prepare the functions for marking a job as successful/failed, and use them in tests for this PR.

status = $1,
completed_at = NOW()
WHERE
request_tag = $2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not enough, because the jobs will be distinguished also by profile and codegen backend. Since the collector will always dequeue a specific job and know it's ID, we should just mark the jobs as finished based on their unique ID.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, yes. Exposing the database id in the struct would seem to make sense in this instance

request_tag: &str,
benchmark_set: u32,
target: &Target,
status: &BenchmarkJobStatus,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe create an enum BenchmarkJobConclusion { Success, Failure } to avoid the invalid states?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's more a developer error I think. Much like the panic!(...) I put in update_benchmark_request_status(...) to prevent the wrong functions being used in the wrong context. And provided we have good test coverage, or good enough, we shouldn't need anything else. It was easy enough for me to fix the tests I broke.

Copy link
Contributor Author

@Jamesbarford Jamesbarford Aug 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After moving some code around you suggestion makes sense if we have the function prototype as;

async fn mark_benchmark_job_as_completed(
    &self,
    id: u32,
    benchmark_job_conclusion: &BenchmarkJobConclusion
) -> anyhow::Result<()>;

Then it becomes intuitive and is different to my previous comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jamesbarford Jamesbarford force-pushed the feat/mark-request-as-complete branch from cd7ff3d to 3074e36 Compare August 4, 2025 15:23
Copy link
Member

@Kobzol Kobzol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I just got to the point where I need job completion 😆 So gonna merge and rebase on top of this.

@Kobzol Kobzol merged commit 563cc7d into rust-lang:master Aug 5, 2025
11 checks passed
@Jamesbarford Jamesbarford deleted the feat/mark-request-as-complete branch August 5, 2025 14:29
Comment on lines +326 to +327
* **id** (`bigint` / `serial`): Primary*key identifier for the job row;
auto*increments with each new job.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this intentional italics?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not :) We can fix it in some follow-up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants