Comments (6)
How many parallel connections do you have and at what rate are you generating IDs? The technique used by django-sequences on PostgreSQL < 9.5 likely doesn't scale to hundreds of connections creating tens of IDs per second.
Also, do you generate several IDs within the same database transaction? In that case you need to create them in a consistent order to avoid deadlocks.
from django-sequences.
@aaugustin, I'm trying up to 30 parallel connections, requesting about 10 request per second.
And no - only one ID per request.
It happens also with much lower number of parallel connections and rps- 5 users and about 2 rps.
from django-sequences.
That could be pushing the limits of the implementation on PostgreSQL < 9.5, depending on the hardware you're using to run PostgreSQL.
You should check the health of your database when running this workload, with the help of your DBA if you have one.
You should also get better results on PostgreSQL 9.5 which has a more optimized implementation.
from django-sequences.
@aaugustin , thanks for your answer.
When not using django-sequences seems like it works fine on those loads.
some more technical data that may help with diagnose the problem -
We're using gunicorn 19.6.0 configured to 5 threads, 3 servers, postgreSql with max_connections of 856, Django's CONN_MAX_AGE is currently set to 600.
Does it sound reasonable?
from django-sequences.
django-sequences is really designed to generate gapless sequences. This is a regulatory requirement in some contexts (e.g. accounting). These tend not to be write-heavy contexts, or at least not concurrent-write-heavy contexts.
This causes PostgreSQL to do a lot of work to synchronize between connections attempting to increment the counter. This is where the overhead comes from.
If you don't need gapless sequences, you can probably find a less expensive solution (in terms of database load), perhaps involving PostgreSQL counters.
If you do need gapless sequences, then you need either a database that's fast enough to handle the transactional workload or another solution for generating IDs.
from django-sequences.
I just noticed this limitation is discussed in the README:
Database transactions that call get_next_value for a given sequence are serialized. In other words, when you call get_next_value in a database transaction, other callers which attempt to get a value from the same sequence will block until the transaction completes, either with a commit or a rollback. You should keep such transactions short to minimize the impact on performance.
from django-sequences.
Related Issues (20)
- Atomic block behaviour HOT 2
- Python 2.x support HOT 1
- Feature request: Get current value HOT 5
- django-sequences version 2.4 is not supporting HOT 10
- Syntax Error sequences/__init__.py, line 29 on Python 3.5.9 HOT 2
- Help elaborate the background of the problem? HOT 5
- reset value does not work with PostgresDB HOT 1
- Document usage with different isolation levels HOT 3
- Deprecation warning: django.utils.translation.ugettext_lazy() is deprecated HOT 2
- New release HOT 1
- Detecting duplicate sequence name HOT 4
- Extend contributing instructions
- Calling get_next_value() in multiple paralel requests can cause huge database lags HOT 4
- Rename master branch to main HOT 1
- About daily sequence HOT 7
- PositiveBigIntegerField HOT 6
- Initial Django Migration Issue HOT 1
- Separate sequence property specifiers HOT 2
- dropping old sequences HOT 4
- Expand get_next_value for multiple sequences HOT 6
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 django-sequences.