Skip to content

Add PgBouncer service and update Django DB connection settings#2407

Open
AyoubHmadouch wants to merge 2 commits into
codalab:developfrom
AyoubHmadouch:develop
Open

Add PgBouncer service and update Django DB connection settings#2407
AyoubHmadouch wants to merge 2 commits into
codalab:developfrom
AyoubHmadouch:develop

Conversation

@AyoubHmadouch

@AyoubHmadouch AyoubHmadouch commented Jun 9, 2026

Copy link
Copy Markdown

Description

This PR improves backend connection stability under load by introducing and tuning PgBouncer in front of PostgreSQL, and aligning app/database settings for high concurrency.

Main goals:

  • Reduce request latency during traffic spikes
  • Avoid database connection saturation
  • Improve overall stability for load tests and competition traffic

Issues this PR resolves

  • Database connection pressure under concurrent traffic
  • Risk of degraded performance when many users are active simultaneously

A checklist for hand testing

  • Start full stack with PgBouncer enabled
  • Confirm Django uses PgBouncer as database endpoint
  • Validate app startup

Any relevant files for testing

link to any relevant files (or drag and drop into github)

Checklist

  • Code review by me
  • Hand tested by me
  • I'm proud of my work
  • Code review by reviewer
  • Hand tested by reviewer
  • CircleCi tests are passing
  • Ready to merge

@AyoubHmadouch AyoubHmadouch marked this pull request as draft June 9, 2026 11:06
@AyoubHmadouch AyoubHmadouch marked this pull request as ready for review June 9, 2026 11:09
Comment thread src/settings/base.py
}

# With ASGI workers and PgBouncer, keep Django DB connections short-lived.
DATABASES['default']['CONN_MAX_AGE'] = int(os.environ.get('DB_CONN_MAX_AGE', '0'))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like we also need to test cases in which a long term connection to the database is necessary, like mass downloading submissions as an organizer ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants