Skip to content
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

[Spot] Make spot_state use safe_cursor(). #2102

Merged
merged 2 commits into from
Jun 19, 2023

Conversation

concretevitamin
Copy link
Member

@concretevitamin concretevitamin commented Jun 19, 2023

When developing a basic Flask app that eventually calls into spot_state.get_spot_jobs(), SQLite complained about threading errors. With safe_cursor() this error was fixed. This PR changes the entire spot_state module to use it.

Tested (run the relevant ones):

  • Code formatting: bash format.sh
  • Any manual or new tests for this PR (please specify below)
  • All smoke tests: pytest tests/test_smoke.py --managed-spot
    • running
  • Relevant individual smoke tests: pytest tests/test_smoke.py::test_fill_in_the_name
  • Backward compatibility tests: bash tests/backward_comaptibility_tests.sh

Copy link
Collaborator

@Michaelvll Michaelvll left a comment

Choose a reason for hiding this comment

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

Thanks for identifying this issue @concretevitamin! Left a question about the consistency across the modules. : )

Comment on lines 28 to 29
@contextlib.contextmanager
def _safe_cursor():
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems we have this in the sky.skylet.configs as well. Do we want to refactor it as a common utility function in sky.utils.db_utils?

Also, we have a db_utils.SQLiteConn which creates a thread-level connection for the database and serves for the same purpose in job_lib and global_user_state. Can we have choose one of them for all the modules using sqlite?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point - moved it into db_utils.safe_cursor(). SQLiteConn doesn't come with auto-commit as a context manager so I didn't use it.

Copy link
Collaborator

@Michaelvll Michaelvll left a comment

Choose a reason for hiding this comment

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

Thanks @concretevitamin! LGTM.

One general question: will adding the commit after read-only queries degrade the performance, as we have quite many SELECT queries that do no modify the database?

@concretevitamin
Copy link
Member Author

Thanks @concretevitamin! LGTM.

One general question: will adding the commit after read-only queries degrade the performance, as we have quite many SELECT queries that do no modify the database?

On a controller,

%timeit spot_state.get_spot_jobs()
513 µs ± 5.94 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)

which is fast enough.

@concretevitamin concretevitamin merged commit 3b3037c into master Jun 19, 2023
@concretevitamin concretevitamin deleted the spot-state-for-spot-ui branch June 19, 2023 21:44
Michaelvll pushed a commit that referenced this pull request Jun 22, 2023
* [Spot] Make spot_state use safe_cursor().

* db_utils.safe_cursor()
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