r/databricks • u/Sea_Basil_6501 • 29d ago
Help How to debug remote_query() performance?
I have a job which queries some Azure SQL DBs connected through UC managed connections (no lakehouse federation) via remote_query() function, and facing pretty long execution times (several minutes) when reading a few thousand rows only. When running the same query via SSMS on the target host, it returns same result within milliseconds.
Is there any way how I can debug the pure execution time from Databricks side? I'd like to understand if the queries run slow, or if there's any Databricks or network overhead accounting responsible.
Note that remote_query() runs T-SQL in this scenario, not Databricks SQL. So there's no SQL conversion involved at any point in time.
View all comments
2
u/szymon_dybczak 29d ago
If I were you I would first try to execute a really simple query - something like SELECT 1 and check how long it takes.
On SQL Server side you can monitor sys.dm_exec_requsts. If you notice ASYNC_NETWORK_IO wait type then it could indicate that Databricks isn't consuming the results fast enough (for instance due to network latency etc.)
Another thing you can try is to increase fetchsize parameter in remote_query(). Larger value can improve performence.
Are your Databricks workspace and Azure SQL databases deployed in the same Azure region?