On Feb 19, 2014, at 9:27 PM, Shahaf Abileah <[email protected]> wrote:

> Hello,
> 
> I'd like to measure how much time my code spends waiting to check out a 
> connection from the pool.  Why?  Because I suspect that I have too many 
> workers and not enough connections in the pool, and I'd like to gather some 
> hard numbers to prove my theory one way or the other.
> 
> I see that there are events I can register for: 
> http://docs.sqlalchemy.org/en/rel_0_9/core/events.html#connection-pool-events.
>   However, off hand I don't see a documented way to get the time spent 
> waiting in checkout.
> 
> I took a peek at pool.py (I'm using sqlalchemy version 0.9.1) .  I see 
> _ConnectionRecord doing the following:
> 
>     def __connect(self):
>         try:
>             self.starttime = time.time()
>             connection = self.__pool._creator()
>             self.__pool.logger.debug("Created new connection %r", connection)
>             return connection
>         except Exception as e:
>             self.__pool.logger.debug("Error on connect(): %s", e)
>             raise
> 
> Is it safe to use this starttime?  Does it measure the time-to-checkout?  Or 
> time-to-establish-new-connection-in-pool?  Or something else?
> 
> Is there a better way to get the info I'm looking for?

for profiling code you should use the Python profiler module.  See 
http://stackoverflow.com/questions/1171166/how-can-i-profile-a-sqlalchemy-powered-application/1175677#1175677
 for an introduction to using Python profiling with specifics regarding 
SQLAlchemy.

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to