Skip to content

perf: ensure hive_posts_status indexes exist (migration v28)#369

Closed
ety001 wants to merge 1 commit intomasterfrom
perf/hive-posts-status-indexes
Closed

perf: ensure hive_posts_status indexes exist (migration v28)#369
ety001 wants to merge 1 commit intomasterfrom
perf/hive-posts-status-indexes

Conversation

@ety001
Copy link
Copy Markdown
Member

@ety001 ety001 commented Apr 20, 2026

Scalyr analysis (2026-04-20 06:09 CST) showed hive_posts_status queries taking up to 427s (7 minutes), causing:

  • ELB health check failures on 1 of 2 instances
  • 35.8% HTTP 4xx error rate on beta-hivemind EB
  • TimeoutError cascading across the connection pool

Root cause: Indexes from migration v20 may not exist in production. v20 used non-CONCURRENTLY DDL which can fail under load.

Migration v28 ensures these indexes exist using CONCURRENTLY IF NOT EXISTS:

  • idx_hive_posts_status_author (author)
  • idx_hive_posts_status_list_type_post_id (list_type, post_id)
  • idx_hive_posts_status_list_type_author (list_type, author)
  • Drops legacy hive_posts_status_ux1 constraint if present

The hide_pids_by_ids function was querying hive_posts_status on every
API request with 'WHERE list_type=1 AND post_id IN :ids'. Even though
the table is small (13K rows, 832KB) and has proper indexes, under burst
traffic this flooded the DB connection pool (size=30), causing cascading
timeouts up to 427 seconds.

Confirmed via production RDS debug API (2026-04-20):
- hive_posts_status: 13,764 rows, indexes exist and healthy
- DB version: 27 (all migrations applied)
- Scalyr showed 0.0% idle during peak, 56 queries >100s (pool queuing)

Fix: Cache the full hidden post ID set in Redis (60s TTL) and filter
in Python. This turns every hide_pids_by_ids call into a Redis lookup
+ Python set intersection, eliminating the DB query entirely.
@ety001 ety001 force-pushed the perf/hive-posts-status-indexes branch from f2d1ccf to 17ac698 Compare April 20, 2026 05:35
@ety001 ety001 closed this Apr 20, 2026
@ety001 ety001 deleted the perf/hive-posts-status-indexes branch April 20, 2026 05:38
@ety001 ety001 restored the perf/hive-posts-status-indexes branch April 20, 2026 05:39
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