Skip to content

Conversation

@SeungjinYang
Copy link
Collaborator

@SeungjinYang SeungjinYang commented Oct 13, 2025

The PR introduces a series of changes to make accesses to request DB more efficient.

General changes

  1. The database is given an index on created_at. This is because several queries in requests.py have ORDER BY created_at statements, which can be accelerated by an index.
  2. RequestTaskFilter now has a sort parameter that can toggle the inclusion of ORDER BY created_at statement. This allows callers that do not need the results to be sorted to benefit from not sorting the result.
  3. RequestTaskFilter had fields parameter introduced 2 days ago. This PR adds appropriate fields parameter to callers that do not need all of the parameters (especially request / response bodies) to perform their tasks.
  4. get_request_tasks_with_fields_async is merged with get_request_tasks_async, allowing the latter function to handle an optional fields parameter if provided. Similarly, get_request_tasks is modified to handle an optional fields parameter.
  5. exact_match fields are added to some queries that acts on a request given a request_id. Since the API server wants to handle clients submitting a request ID prefix, query functions use WHERE request_id LIKE <prefix>% statement to handle prefixes. However, in cases where we know an exact request ID is supplied, using WHERE request_id = <id> is more efficient.

Case studies of specific codepaths

sky api cancel -a:

  • Uses kill_requests. Since no request IDs are specified, the request IDs are retrieved from DB. This DB call now only returns request IDs (instead of whole requests) and does not sort. I expect this to be the bulk of the efficiency improvement.
  • Since the request IDs are retrieved from DB, we can set exact_match to True on update_request. This uses an exact match query (WHERE request_id = <id> instead of WHERE request_id LIKE <prefix>%) making the operation more efficient.

sky logs

  • uses _tail_log_file. We now establish an exact_request_id at the start of _tail_log_file, and use exact match query making the operation more efficient.

Tested (run the relevant ones):

  • Code formatting: install pre-commit (auto-check on commit) or bash format.sh
  • Any manual or new tests for this PR (please specify below)
  • All smoke tests: /smoke-test (CI) or pytest tests/test_smoke.py (local)
  • Relevant individual tests: /smoke-test -k test_name (CI) or pytest tests/test_smoke.py::test_name (local)
  • Backward compatibility: /quicktest-core (CI) or pytest tests/smoke_tests/test_backward_compat.py (local)

@SeungjinYang SeungjinYang force-pushed the request-db-optimizatons branch 2 times, most recently from 491bd65 to fe85ad9 Compare October 13, 2025 23:02
@SeungjinYang
Copy link
Collaborator Author

/quicktest-core --base-branch v0.10.1
/smoke-test --kubernetes --no-resource-heavy

@SeungjinYang SeungjinYang marked this pull request as ready for review October 13, 2025 23:21
@SeungjinYang
Copy link
Collaborator Author

/smoke-test --aws --no-resource-heavy

@SeungjinYang SeungjinYang requested a review from kyuds October 14, 2025 00:52
@SeungjinYang SeungjinYang force-pushed the request-db-optimizatons branch from fe85ad9 to 2df7191 Compare October 14, 2025 15:24
@SeungjinYang
Copy link
Collaborator Author

/quicktest-core --base-branch v0.10.1
/smoke-test --kubernetes --no-resource-heavy
/smoke-test --aws --no-resource-heavy

@SeungjinYang
Copy link
Collaborator Author

There's a lot of stuff going on in this PR, so I'll separate the changes out and submit incremental PRs as recommended by @rohansonecha

@SeungjinYang SeungjinYang marked this pull request as draft October 16, 2025 19:02
@SeungjinYang SeungjinYang force-pushed the request-db-optimizatons branch 5 times, most recently from bc520c8 to baf7335 Compare October 19, 2025 02:10
optimization2

consolidate funcs

more consolidation

more optimizations

add index

fix unit tests

address TODO

cancel optimizations 1

revert count

testfix
@SeungjinYang SeungjinYang force-pushed the request-db-optimizatons branch from baf7335 to e26f57e Compare October 19, 2025 19:26
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.

2 participants