How to ensure that the same connection is always used from a given thread #2041
HoneyryderChuck
started this conversation in
General
Replies: 1 comment 6 replies
-
That sounds like the best way to me, calling |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
For a given "stats collection" functionality I have, where a thread is spawned from a process which runs in all servers where an application is deployed, I'm building a leader election process, to ensure that only one of them does work. For that, I'm using the pg advisory lock functionality. The process is very simple: on each 30s thread loop, I try acquiring the lock, and if successful, I collect the stats and send them to statsd, otherwise I sleep again.
For this to work the way I intended, I have to ensure that the worker thread always uses the same connection. However, by default, sequel distributes connections to all threads doing database work and using the same database object. Is there a way to "pin" connections to a given thread? Or do I have to acquire a connection for that thread for the duration of the process?
Beta Was this translation helpful? Give feedback.
All reactions