supabase-community / supabase-py

Python Client for Supabase. Query Postgres from Flask, Django, FastAPI. Python user authentication, security policies, edge functions, file storage, and realtime data streaming. Good first issue.
https://supabase.com/docs/reference/python
MIT License
1.55k stars 177 forks source link

Connection Keep Alive #783

Open StanGirard opened 2 months ago

StanGirard commented 2 months ago

Hey !

It seems that the TLS Handshake happens every query.

image

Implementing a Keep-alive and keeping the connection alive would save around 60ms per query.

juancarlospaco commented 2 months ago

is it really required? 🤔

Also, it should be ON by default whatsoever, because it is hardcoded:

It is interesting nevertheless, will keep investigating...

StanGirard commented 2 months ago

Hey @juancarlospaco,

I've been battling with it for almost a week.

Going with direct connection to the database with RAW SQL queries makes it way faster. I looked into Kong, it should be around 8ms of latency not 40ms.

There might be something funny happening.

image

Here you can see the time when I do queries directly to database and when using the python sdk.

Would love to help you investigate.

Both my backend and my supabase are in Ireland on AWS.

juancarlospaco commented 2 months ago

I can confirm it is not the "keep-alive" by itself IMHO, something funny is happening somehow, will keep investigating...

StanGirard commented 2 months ago

@juancarlospaco Thanks Juan! Let me know if i can help anyhow

StanGirard commented 1 month ago

Hello @juancarlospaco, any update of this issue ?