-
Notifications
You must be signed in to change notification settings - Fork 62
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
Improve database check performance: replace introspection.table_names() by a simple cursor query #171
Improve database check performance: replace introspection.table_names() by a simple cursor query #171
Conversation
@cristianemoyano Thanks for opening this PR! Interesting, I hadn't realized this could be an issue. Is it something you've run into yourself? Just curious what sort of performance you were seeing on the |
Hey @mwarkentin, You're welcome. Yes, we realized that running this health check many times in production results in database degradation. Clearly running "select 1" is much cheaper. Unfortunately, I can't show you metrics. I also did a "python timeit" comparing both approaches and my approach turned out to be 6x faster. Another reason is that the purpose of this health check is to establish a connection with the database and instead the method is also returning the name of the tables which is unnecessary. |
@cristianemoyano I'm doing some work to modernize the testing and release processes for django-watchman at the moment - hope to get this in and released when that stabilizes. |
@mwarkentin that sounds Great! let me know if you need anything from my side. |
@cristianemoyano looks like the added test is failing - can you take a look? Was it working for you locally? https://github.com/mwarkentin/django-watchman/runs/4619579103?check_suite_focus=true |
That's weird. I will try again rebasing my code later this week.
|
…() by just a SELECT 1
217a80d
to
f5bac54
Compare
Hey @mwarkentin, can you try again, please? Thanks! |
All checks are green! 🎉 |
@cristianemoyano thanks! I'll take a look next week. 😊 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - thanks again! I'll update on this PR when I've released to pypi.
Summary
The
introspection.table_names()
method in Django could produce a poor performance in large databases.Take a look at the different backends implementations:
That's why I suggest executing a cheap query:
SELECT 1
to test the database connection.Testing
python runtests.py tests/test_decorators.py:TestDBConnection