On Fri, Jan 18, 2019 at 4:54 PM Mike Bayer <[email protected]> wrote:
>
> On Fri, Jan 18, 2019 at 4:49 PM Zsolt Ero <[email protected]> wrote:
> >
> > I know I'm far away from a remote server, as the server is a Google
> > Cloud SQL instance, and I'm in a residential cable connection. But
> > ping times are only 145 ms, nothing extreme I'd say. If you'd like I
> > can quickly setup a sandbox instance on GCP for trying this out.
> >
> > Still, I don't even understand the theory, shouldn't connection pools
> > be the same speed as keeping one connection?
>
> the problem you are illustrating has nothing to do with the connection pool.

oh, you're asking why if you connect each time, its slower.     the
code you are illustrating is still using only one connection at a
time, however when you return a connection to the pool, it has to emit
a ROLLBACK on the connection by default which might be adding extra
latency.

I can replicate that the ROLLBACK causes it to take .77 seconds:

>>> from sqlalchemy import create_engine
>>> e = create_engine("postgresql://scott:tiger@pg10/test")
>>> import time
>>> def go():
...     now = time.time()
...     for i in range(100):
...         with e.connect() as conn:
...             conn.execute("select 1").fetchall()
...     total = time.time() - now
...     print("completed in %f sec" % (total, ))
...
>>> go()
completed in 0.779910 sec

turning that off (this is also instructional in how to do that), takes
.30 seconds again:

>>> from sqlalchemy import create_engine
>>> e = create_engine("postgresql://scott:tiger@pg10/test", 
>>> pool_reset_on_return=None)
>>> import time
>>> def go():
...     now = time.time()
...     for i in range(100):
...         with e.connect() as conn:
...             conn.execute("select 1").fetchall()
...     total = time.time() - now
...     print("completed in %f sec" % (total, ))
...
>>> go()
completed in 0.301798 sec




>
> >
> > --
> > SQLAlchemy -
> > The Python SQL Toolkit and Object Relational Mapper
> >
> > http://www.sqlalchemy.org/
> >
> > To post example code, please provide an MCVE: Minimal, Complete, and 
> > Verifiable Example.  See  http://stackoverflow.com/help/mcve for a full 
> > description.
> > ---
> > You received this message because you are subscribed to the Google Groups 
> > "sqlalchemy" group.
> > To unsubscribe from this group and stop receiving emails from it, send an 
> > email to [email protected].
> > To post to this group, send email to [email protected].
> > Visit this group at https://groups.google.com/group/sqlalchemy.
> > For more options, visit https://groups.google.com/d/optout.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to