Skip to content

perf: optimize database pools, batch commits, and node health checks#615

Open
wahh3b-lgtm wants to merge 1 commit into
PasarGuard:devfrom
wahh3b-lgtm:pr-4-db-node-perf-v3
Open

perf: optimize database pools, batch commits, and node health checks#615
wahh3b-lgtm wants to merge 1 commit into
PasarGuard:devfrom
wahh3b-lgtm:pr-4-db-node-perf-v3

Conversation

@wahh3b-lgtm

Copy link
Copy Markdown

Changes

  • DB connection pool (config.py, app/db/base.py): Increased pool_recycle to 1800s, added configurable pool_timeout (default 15s) with ge=1 validation, enabled pool_use_lifo=True
  • Performance indexes (Alembic migration): Added composite indexes via proper Alembic migration generated from model definitions — (status, expire), (status, used_traffic), (nodes.status), (hosts.inbound_tag), (hosts.is_disabled), (notification_reminders.user_id)
  • Indexes defined in models: All new indexes are declared in __table_args__ so Alembic can detect and manage them automatically
  • Record usages (app/jobs/record_usages.py): Cached dialect lookup with double-checked locking to prevent race conditions. Per-node safe_execute for node stats
  • Node health checks (app/node/__init__.py): Concurrent asyncio.gather() with snapshot revalidation and exception logging for failed probes
  • XRayConfig (app/core/xray.py): Reverted TLS reads to synchronous (run_until_complete on a running loop always raised RuntimeError)
  • .env.example: Updated pool defaults to match new config

Files Changed

  • config.py
  • app/db/base.py
  • app/db/__init__.py
  • app/db/models.py
  • app/db/migrations/versions/118c2a5eaa7d_add_performance_indexes.py (new)
  • app/jobs/record_usages.py
  • app/node/__init__.py
  • app/core/xray.py
  • .env.example

Verification

  • Ruff lint + format pass
  • 13/13 tests pass
  • Indexes defined in SQLAlchemy models, migration generated by Alembic

- DB pool: increase pool_recycle to 1800s, add pool_timeout (default 15s), enable pool_use_lifo, add ge=1 validation
- Alembic migration: add performance indexes (status/expire, status/used_traffic, nodes/status, hosts/inbound_tag, etc.)
- Indexes defined in models (__table_args__) so Alembic detects changes properly
- Record usages: cache dialect lookup with double-checked locking, per-node safe_execute
- Node health checks: concurrent asyncio.gather with snapshot revalidation and exception logging
- XRayConfig: revert TLS reads to synchronous (run_until_complete fails on running loop)
- Update .env.example with new pool defaults
@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 735e12fb-7a8b-45c1-bb1f-36176eeb8959

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

1 participant