Comments (10)
It means that you're using the same connection in multiple threads. This is not supported even by the database driver.
Is something wrong in your connection pool setup?
from pq.
Thanks for replying. I am using a web application deployed with uwsgi. There are 4 worker threads.
The queue is created with the following code:
from playhouse.pool import PooledPostgresqlExtDatabase as PostgresqlDatabase
from psycopg2 import connect, errors
from pq import PQ
....
db = PostgresqlDatabase(CONFIG.postgres_db,
user=CONFIG.postgres_user,
password=CONFIG.postgres_password,
host=CONFIG.postgres_host, port=5432,
max_connections=32,
stale_timeout=300 # 5 minutes.
)
def get_queue(connection, name):
"""
a PQ connection wrapper
connection = connect(dbname=CONFIG.postgres_db,
user=CONFIG.postgres_user,
password=CONFIG.postgres_password,
host=CONFIG.postgres_host)
using peewee we simply get the connection from the database instance.
"""
pq = PQ(connection)
# recreating the queue is, because peewee evolve does not take care
# of this model
try:
pq.create()
except errors.DuplicateTable:
pass
queue = pq[name]
return queue
my_queue = get_queue(db.connection(), "default")
I am guessing, every time I call queue.put
I need to pass a new connection. Thus avoiding
a global shared connection.
This will take some rethinking of how I combine pq with peewee. I would be happy to hear a suggestion.
from pq.
If you have a module-global my_queue
that you're using from multiple threads, then you have a problem because you're using just a single connection.
Instead, what you can do is to use a connection pool (passing it to the PQ
constructor using keyword-argument pool
). This will play nicely with your setup.
from pq.
Actually, I am using a connection pool. I just didn't pass it. Although I'm not sure peewee's connection pool does the job.
I still need to check this.
from pq.
It does not but you should be able to write a simple wrapper for it.
from pq.
Sigh... More yack shaving 😃
from pq.
Yep. Alternatively, use psycopg2
directly. You might not need to run everything through Peewee.
from pq.
Using psycopg2 directly seems tricky with uwsgi. I am reluctant to do this.
It seems the solution is simply using lazy-apps
when running multiple workers with uWSGI
..
Also, eventually, the application will be deployed to k8s. This means I can at the cost of more RAM have each replica member have one worker, thus avoiding the connection sharing.
from pq.
Yeah that's not a bad idea. And to be honest, the memory overhead probably isn't all that big.
from pq.
Thanks for replying. I made some changes to my code and docker images, seems that the issue is gone.
from pq.
Related Issues (20)
- connection pool exhausted HOT 3
- Prepared statement name not properly escaped HOT 1
- Question: why am I seeing "NOTICE: function pq_notify does not exist" in the logs? HOT 3
- Delete executed tasks?! HOT 1
- Wait on a job? HOT 3
- get() timeout not honoured HOT 1
- Any interest in porting to cockroach HOT 3
- Pipenv using old create.sql HOT 5
- Get id of current task HOT 2
- Performance with a very large queue HOT 9
- lost trigger when setting up multiple queue-tables within the same schema
- Adding recurring tasks? HOT 4
- queue.put() inside a transaction sets enqueued_at to the transaction start time, not the current time HOT 4
- Adding name of the job producer HOT 2
- Dashboard for PQ HOT 3
- Any plans to migrate to Psycopg 3? HOT 1
- get items sometimes doesn't work
- 2.x roadmap
- Logging message not explicit
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pq.