Only run pg_advisory_unlock_all if necessary.#46
Only run pg_advisory_unlock_all if necessary.#46moser wants to merge 7 commits intolevel12:masterfrom
Conversation
|
Thanks for the PR. Can you give me more context about how you are using pals with respect to your other database connections? I've always setup a separate dedicated connection pool for the locks. It sounds like you are sharing the pals connection pool with code that is doing more than locking? |
|
I use But even if you exclusively use the connection pool for locking, it is still inefficient to run I understand that you are somewhat reluctant to accept changes to a safety measure. If you decline them, I will find another way to deal with it. For me it is important because the repeated calls take ~20-50ms each and waste hundreds of milliseconds on a critical path :-) |
|
That's a fine use case, thanks for sharing. It seems like a rather innocuous change and I'm a +1 on changing it. However, I might want to see this ran under a "feature flag" at first so we can get some real-world usage data before making it the default. Have you been able to run this modification in the real world yet (through a vendored version of this library or fork)? I'd also want to see tests added for the functionality. |
|
@rsyring I tried a solution for registering the checkin handler only once but failed. There are just too many sqlalchemy specifics (across versions) involved to make it reliable. Thus, I decided to continue on this solution. I added tests and put the tracking behavior behind a flag for now. WDYT? |
|
Simpler solution in #50 |
When using PALs on a shared SQLAlchemy engine, running
pg_advisory_unlock_allon every connection pool checkin event can cause performance problems.This PR adds tracking for used DB API connections and will limit the
pg_advisory_unlock_allto connections that were actually used by PALs.