Slow engine creation - only when using FastAPI
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 25/100
Piste de recherche
Commencez par la reproduction FastAPI dans main.py et test_route.py, puis comparez son chemin create_engine avec l’exemple de connexion autonome databricks.sql. Profilez l’importation et l’exécution de databricks/sql/thrift_api/TCLIService/ttypes.py avec les versions épinglées dans requirements.txt. La tâche sera considérée comme terminée lorsque la cause du délai propre à FastAPI aura été établie et qu’un remède pris en charge aura été démontré sans modifier manuellement le fichier généré.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Hello,
I am currently working on a FastAPI application which calls Databricks using databricks-sql-connector, however the code appears to slow down massively on the engine creation stage.
I've narrowed the issue down to .venv\Lib\site-packages\databricks\sql\thrift_api\TCLIService\ttypes.py, where when running in debug mode the script is loaded incredibly slowly (around 5-10 minutes). However when the exact same code is run outside of a FastAPI function (ie, in a standalone script, notebook, etc) it runs almost instantly and the engine is created in under 1 second.
The details of my test application are:
main.py:
from fastapi import FastAPI
from fastapi.responses import RedirectResponse
import uvicorn
from routes import test_route
app = FastAPI(
title="TestAPI",
version="1.0",
description="Test API",
)
@app.get("/", include_in_schema=False)
async def docs_redirect():
return RedirectResponse(url='/docs')
app.include_router(test_route.router)
if __name__ == '__main__':
uvicorn.run('main:app', host='0.0.0.0', port=8000)
test_route.py:
import fastapi
from fastapi import APIRouter
from sqlalchemy import create_engine
from sqlalchemy import text
router = APIRouter(tags=["Test"])
@router.post("/test_route", description="Test")
async def test():
import time
print("Connecting to engine....")
startT = time.time()
engine = create_engine(
url = f"databricks://token:<<TOKEN>>@<<HOST>>?http_path=/sql/1.0/warehouses/<<WAREHOUSE>>&catalog=<<CATALOG>>&schema=<<SCHEMA>>"
)
print("Engine Connected!")
print(f"Time taken: {time.time() - startT} seconds.")
with engine.connect() as connection:
result = connection.execute(text("SELECT * from range(10)"))
for row in result:
print(row)
print(f"Execution time: {time.time() - startT} seconds.")
pass
return "Ok."
requirements.txt:
fastapi==0.111.1
uvicorn==0.30.3
databricks-sql-connector[SQLAlchemy]==3.3.0
The same issue occurs when using:
from databricks import sql
connection = sql.connect(
server_hostname = <HOST>,
http_path = <HTTP>
access_token = <TOKEN>)
cursor = connection.cursor()
cursor.execute("SELECT * from range(10)")
print(cursor.fetchall())
cursor.close()
connection.close()
but given it all goes to create_engine under the hood I was trying to simplify my test case.
As mentioned, the call stack points to .venv\Lib\site-packages\databricks\sql\thrift_api\TCLIService\ttypes.py taking all of this extra time. This can be fixed through editing ttypes.py directly and removing all rows which begin None, #. However this directly violates the warning given at the top of ttypes.py about not editing. Removing these rows reduces the file from ~100,000 lines to ~10,000, and completely solves the time delay issue when using FastAPI.
So my main questions are:
- Why does this delay in engine creation only occur in a FastAPI app (is it something to do with it being asynchronous?).
- How can this delay be remedied?
- Can
ttypes.pybe safely edited to remove all "None" rows or is this not a viable solution?
Thanks!
- Langage dominant
- Python
- Étoiles
- 236
- Forks
- 162
- Merge moyen
- 14 h 22 min
- PR mergées (30 j)
- 25
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de databricks/databricks-sql-python
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
databricks/databricks-sql-python#1012 ·
Les mainteneurs répondent en général sous 1 jour
-
Token federation: `_exchange_token` raises KeyError('access_token') on error responses, discarding the real failure reasonPeut-être pris @TangoEnSkai l’a pris il y a 82 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
databricks/databricks-sql-python#904 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
databricks/databricks-sql-python#865 ·
Les mainteneurs répondent en général sous 1 jour
-
engineer-bot
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
databricks/databricks-sql-python#860 · 3 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
Cursor.close() leaks server-side handle for async commands that were never fetchedPeut-être pris @nanookclaw l’a pris il y a 177 jours. Ouvertebug engineer-bot
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
databricks/databricks-sql-python#791 · 5 commentaires ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de databricks/databricks-sql-python
Issues similaires
-
Unknown stop ID in slow zone data crashes post formatting and skips the rest of that day's postsOuvertebackend bug tm-new-volunteer
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
transitmatters/mbta-slow-zone-bot#81 · 1 commentaire ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 64/100
spacetelescope/rdmt-spire#49 ·
Les mainteneurs répondent en général sous 1 jour
-
AI bug
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
AUTO-MAS-Project/AUTO-MAS#1960 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
btclib-org/btclib-wallet#872 ·
Les mainteneurs répondent en général sous 1 jour