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

DM-47594: Set up trace telemetry for Butler server #1117

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

dhirving
Copy link
Contributor

Set up trace telemetry for Butler server using Sentry, to allow debugging of performance issues in the deployed server.

Checklist

  • ran Jenkins
  • added a release note for user-visible changes to doc/changes
  • (if changing dimensions.yaml) make a copy of dimensions.yaml in configs/old_dimensions

Copy link

codecov bot commented Nov 15, 2024

❌ 2 Tests Failed:

Tests completed Failed Passed Skipped
1858 2 1856 14
View the top 2 failed tests by shortest run time
tests/test_sqlite.py::SqliteMemoryDatabaseTestCase::testConnection
Stack Traces | 0.004s run time
self = <test_sqlite.SqliteMemoryDatabaseTestCase testMethod=testConnection>

    def testConnection(self):
        """Test that different ways of connecting to a SQLite database
        are equivalent.
        """
        # Create an in-memory database by passing filename=None.
        memFromFilename = SqliteDatabase.fromEngine(SqliteDatabase.makeEngine(filename=None), origin=0)
        self.assertIsNone(memFromFilename.filename)
        self.assertEqual(memFromFilename.origin, 0)
        self.assertTrue(memFromFilename.isWriteable())
>       self.assertTrue(isEmptyDatabaseActuallyWriteable(memFromFilename))
E       AssertionError: False is not true

tests/test_sqlite.py:166: AssertionError
tests/test_sqlite.py::SqliteFileDatabaseTestCase::testConnection
Stack Traces | 0.006s run time
self = <test_sqlite.SqliteFileDatabaseTestCase testMethod=testConnection>

    def testConnection(self):
        """Test that different ways of connecting to a SQLite database
        are equivalent.
        """
        _, filename = tempfile.mkstemp(dir=self.root, suffix=".sqlite3")
        # Create a read-write database by passing in the filename.
        rwFromFilename = SqliteDatabase.fromEngine(SqliteDatabase.makeEngine(filename=filename), origin=0)
        self.assertEqual(rwFromFilename.filename, filename)
        self.assertEqual(rwFromFilename.origin, 0)
        self.assertTrue(rwFromFilename.isWriteable())
>       self.assertTrue(isEmptyDatabaseActuallyWriteable(rwFromFilename))
E       AssertionError: False is not true

tests/test_sqlite.py:109: AssertionError

To view more test analytics, go to the Test Analytics Dashboard
📢 Thoughts on this report? Let us know!

@dhirving dhirving force-pushed the tickets/DM-47594 branch 6 times, most recently from 1a7921f to 09c1d38 Compare November 20, 2024 23:32
@dhirving dhirving force-pushed the tickets/DM-47594 branch 4 times, most recently from c6227a8 to 9cb8879 Compare December 6, 2024 20:13
DatasetTypeCache is only used in a single file with a specific set of types, so it no longer needs to be generic.

Upcoming changes to make it thread-safe and cloneable will be easier to reason about with concrete types.
In preparation for sharing DatasetTypeCache between threads, make its inner DynamicTables values immutable.  The mutable portion moved to a separate cache inside DatasetTypeCache.

As a side effect, this reduces the number of times we go to the DB to check for the existence of tag and calib tables.
This cache is used only by a single manager, and has never participated in the caching enable/disable logic associated with CachingContext.

Getting it out of CachingContext encapsulates its creation and use within a single manager class, simplifying upcoming changes. This also removes some unused branches from the code.
Pre-fetch dataset types the first time a repository is accessed in Butler server, to avoid the need to re-fetch them in most later operations.
Trigger dataset type preload the first time a connection is made to the Butler server in each unit test, to better match the conditions that will exist in the actual server.
Fix a bug where loading a dataset type registered externally after the Butler had loaded a "full" dataset type cache would cause an assertion failure "Dataset type cache population is incomplete" due to only filling in one of the two caches.
Copy some notes from the comments on DM-42317, and update them for the changes to dataset type caching.
Set up trace telemetry for Butler server using Sentry, to allow debugging of performance issues in the deployed server.
Avoid cluttering trace logs by not tracking the health check endpoint.
Add manual spans to clarify where time is being used during streaming queries
This would create an excessive number of spans for larger queries.  The FastAPI telemetry is already tracking the time spent in sending the results to the client, so we can see it without adding an additional span.
With the cache enabled, every query on the server is pulling and processing 17k rows of dataset summaries because filtering is disabled when the cache is on.  (Which is all queries).

This is more like 1 or 60 rows if we use the filter.

The processing of these rows seems to be taking excessive synchronous CPU time (300ms+ on the server).
The FastAPI thread pool size can now be configured by setting the environment variable DAF_BUTLER_SERVER_THREAD_POOL_SIZE.

It turns out the default value was 10, which is way too low for an I/O-bound service like Butler server.
Wrap all accesses to sqlalchemy.MetaData with a lock to avoid concurrency issues.

sqlalchemy.MetaData is documented to be threadsafe for reads, but not with concurrent modifications.  We add tables dynamically at runtime, and the MetaData object is shared by all Database instances sharing the same connection pool.

Prior to adding the lock, Butler server database calls that added table definitions dynamically were sometimes failing with InvalidRequestError exceptions complaining about inconsistency of table definitions.
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.

1 participant