Reputation: 19
I have a very strange problem with sqlalchemy and the connect() function of it.
I have discovered the problem when i was running my unittests, which took forever - like up to 30 minutes per test.
After that i wrote a simple test to figure out which line of code could take so long: The url is someting like 'postgresql+psycopg2://usr:pwd@localhost:8888/postgres?application_name=Flask-App-1'
engine = sqlalchemy.create_engine(url, poolclass=sqlalchemy.pool.NullPool,)
import time
def test():
start = time.time()
with engine.connect() as connection:
end = time.time()
duration = end - start
print("--------------------" + str(duration))
It turned out that it was the engine.connect() which already takes like around 40 seconds. My VS-Code which i am using is running on a local server (Centos). I discovered that connecting to the desired database via console and telnet is working immediately. Running the code above within the console via pyenv is taking also very long (when using my user).
What i also discovered was that when changing to root or any other user, the code will executed fast. Also the unittests executed via pytest in the console and as root are finishing fast. Only with my user it will take ages.
With htop i could see that following process will take ~100% cpu utilization of a single core during the whole time of running a test.
That is all i did discovered so far. I have this problem for 4 days now and it seems it is getting even slower from day to day. Of course i tried simple things like restarting the server, recreating the docker container of database, restarting vscode...
Also mentionable is maybe that 4 days ago i had a short disconnect (like 5 secs.) from the internet, which disconnected the vpn connection, while running a lot of unittests in vscode. After that incident i could not connect to my server again. It said something like "login aborted" (not very sure what the exact message was). I contatced my Lead and he restarted my server. After that i could connect to my server again. I am not sure if there is a connection of the problem with the incident but in terms of the timing it could be possible.
For my limited knowledge with linux and networking I'm at my wit's end here.
Thanks for every help in advance. Feel free to ask questions for further details.
Upvotes: 0
Views: 70