Skip to content

Improving codabench performances - #2707

Merged
Didayolo merged 15 commits into
developfrom
app/performances
Nov 17, 2026
Merged

Didayolo merged 15 commits into
developfrom
app/performances

Conversation

@IdirLISN

@IdirLISN IdirLISN commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Description

This PR is an attempt to improve codabench performances by adding a db index for submission and leaderboard.

Also we add in this PR some django ORM code optimizations for better performances.

We focus on improving API performance while keeping existing logic and behavior.
The main optimizations include using select_related() to reduce database queries from django ORM features.
We also address N+1 query problems in serializers.

A checklist for hand testing

  • Check if the competition page is more responsive.

Performance Comparison — develop vs perf

Benchmark Configuration

Parameter Value
Virtual users 20
CPU cores 8
Test duration 180 seconds
Target throughput 40 journeys/s
Tested endpoints API Competition Detail and API Leaderboard
User journey Retrieve competition details, then retrieve its leaderboard

Overall Throughput and Latency

Metric Description develop perf Change
Target throughput Desired number of user journeys per second 40.00/s 40.00/s —
Achieved throughput Actual number of complete user journeys processed per second 20.98/s 34.56/s +64.7%
Completed journeys Total number of complete user journeys executed during the test 3,777 6,220 +64.7%
Average latency Average time required to complete a full user journey 618 ms 322 ms −47.9%
P50 Median: 50% of journeys completed within this time 519 ms 278 ms −46.4%
P95 95% of journeys completed within this time 1,335 ms 642 ms −51.9%
P99 99% of journeys completed within this time 2,016 ms 850 ms −57.8%
Maximum Longest observed journey duration 3,074 ms 1,269 ms −58.7%
HTTP errors Number of failed requests 0 0 No change

API Competition Detail Performance

Metric Description develop perf Change
Requests Total number of requests executed 3,777 6,220 +64.7%
RPS Number of requests processed per second 20.98 34.56 +64.7%
Avg Average response time 467 ms 259 ms −44.5%
P50 Median response time 370 ms 221 ms −40.3%
P95 95% of responses are faster than this value 1,129 ms 529 ms −53.1%
P99 99% of responses are faster than this value 1,786 ms 720 ms −59.7%
Max Maximum observed response time 2,853 ms 1,209 ms −57.6%
Errors Number of failed requests 0 0 No change

API Leaderboard Performance

Metric Description develop perf Change
Requests Total number of requests executed 3,777 6,220 +64.7%
RPS Number of requests processed per second 20.98 34.56 +64.7%
Avg Average response time 151 ms 63 ms −58.3%
P50 Median response time 129 ms 51 ms −60.5%
P95 95% of responses are faster than this value 313 ms 134 ms −57.2%
P99 99% of responses are faster than this value 474 ms 205 ms −56.8%
Max Maximum observed response time 1,580 ms 768 ms −51.4%
Errors Number of failed requests 0 0 No change

SQL Query Count

Metric Description develop perf Change
SQL Competition Detail — Total Total number of SQL executions for this endpoint 333,874 329,922 −1.2%
SQL Competition Detail — Avg Average number of SQL executions per HTTP request 88.40 53.04 −40.0%
SQL Competition Detail — Max Maximum number of SQL executions for a single HTTP request 108 68 −37.0%
SQL Leaderboard — Total Total number of SQL executions for this endpoint 168,006 56,470 −66.4%
SQL Leaderboard — Avg Average number of SQL executions per HTTP request 44.48 9.08 −79.6%
SQL Leaderboard — Max Maximum number of SQL executions for a single HTTP request 54 17 −68.5%
Journey SQL — Total Total number of SQL executions across both endpoints 501,880 386,392 −23.0%
Journey SQL — Avg Average number of SQL executions per complete user journey 132.88 62.12 −53.2%

Interpretation: The perf branch significantly reduces the number of SQL queries required, particularly for the leaderboard. The average number of SQL queries per complete user journey is reduced by more than half.

SQL Execution Time

Metric Description develop perf Change
SQL Detail — Total Cumulative time spent executing SQL queries for this endpoint 683,032 ms 758,598 ms +11.1%
SQL Detail — Avg Average SQL execution time per HTTP request 180.84 ms 121.96 ms −32.5%
SQL Leaderboard — Total Cumulative time spent executing SQL queries for this endpoint 257,579 ms 169,773 ms −34.1%
SQL Leaderboard — Avg Average SQL execution time per HTTP request 68.20 ms 27.29 ms −60.0%
Journey SQL — Total Cumulative SQL execution time across all journeys 940,611 ms 928,371 ms −1.3%
Journey SQL — Avg Average SQL time consumed per complete user journey 249.04 ms 149.26 ms −40.1%

Total SQL execution time is accumulated across all workers. It can exceed the actual benchmark duration because multiple SQL queries are executed in parallel.

HTTP Response Payload Size

Metric Description develop perf Change
Detail — Average size Average amount of data returned per request 10.02 KB 9.98 KB −0.4%
Detail — Total size Total amount of data transferred by this endpoint 37,833.4 KB 62,084.3 KB +64.1%
Leaderboard — Average size Average amount of data returned per request 0.93 KB 0.93 KB No change
Leaderboard — Total size Total amount of data transferred by this endpoint 3,522.1 KB 5,813.4 KB +65.1%
HTTP 200 Number of successful responses for each endpoint 3,777 6,220 No errors

Checklist

  • Code review by me
  • Hand tested by me
  • I'm proud of my work
  • Code review by reviewer
  • Hand tested by reviewer
  • CircleCi tests are passing
  • Ready to merge

@IdirLISN
IdirLISN requested a review from ObadaS November 5, 2026 15:48
@IdirLISN IdirLISN self-assigned this Nov 5, 2026
@IdirLISN
IdirLISN marked this pull request as draft November 5, 2026 15:49
@IdirLISN
IdirLISN marked this pull request as ready for review November 9, 2026 15:08
@IdirLISN
IdirLISN requested a review from Didayolo November 9, 2026 15:08
@Didayolo

Didayolo commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Some blocking points:

1. Leaderboard shows submissions that aren't on the leaderboard

In LeaderboardPhaseSerializer.get_submissions, the last commit removed the leaderboard=instance.leaderboard and has_children=False filters.

Without the leaderboard filter, every submission of the phase ends up on the public leaderboard, including ones the participant never pushed to it or that the organizer removed. I think we should restore them.

submissions_qs = Submission.objects.filter(
    phase=instance,
    leaderboard=instance.leaderboard,
    is_soft_deleted=False,
    has_children=False,
    is_specific_task_re_run=False,
)

If a test was failing with these filters, it's probably the test (or its fixtures) that needs adjusting.

2. Search no longer works for anonymous users

The title / description filter was moved inside the authenticated block. Before, it was applied at the end for everyone. Now, a logged-out user searching gets all published competitions, unfiltered. We should keep the search filter applied in both cases.

3. The submission refresh fix in detail.tag doesn't take effect

The new new_submission_created handler (with select_phase: false) was added, but the old one right below it is still there. So each new submission triggers two requests, and the old handler still resets the selected phase. Removing the old handler should fix it.

EDIT: this behavior was already on develop

@IdirLISN

Copy link
Copy Markdown
Collaborator Author

branch production ready

@Didayolo
Didayolo merged commit 7941d2c into develop Nov 17, 2026
3 checks passed
@Didayolo
Didayolo deleted the app/performances branch November 17, 2026 13:52
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