Spaces:
Runtime error
Runtime error
Commit ·
e86dee7
1
Parent(s): b2ff257
feat(worker-manager): implement Redis connection pooling for sync workers
Browse files- Add Redis ConnectionPool with max_connections=15 for improved resource management
- Enable socket keepalive to maintain persistent connections
- Set socket_connect_timeout to 5 seconds for faster failure detection
- Enable retry_on_timeout for automatic reconnection on timeout events
- Add health_check_interval=30 for periodic connection validation
- Update logging to reflect connection pool configuration
- Improves connection stability and resource efficiency for sync worker operations
- app/sync/worker_manager.py +10 -4
app/sync/worker_manager.py
CHANGED
|
@@ -42,17 +42,23 @@ class WorkerManager:
|
|
| 42 |
await conn.execute(text("SELECT 1"))
|
| 43 |
logger.info("✅ Connected to PostgreSQL")
|
| 44 |
|
| 45 |
-
# Redis
|
| 46 |
logger.info(f"Connecting to Redis: {settings.REDIS_HOST}:{settings.REDIS_PORT}")
|
| 47 |
-
|
| 48 |
host=settings.REDIS_HOST,
|
| 49 |
port=settings.REDIS_PORT,
|
| 50 |
password=settings.REDIS_PASSWORD,
|
| 51 |
db=settings.REDIS_DB,
|
| 52 |
-
decode_responses=True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
)
|
|
|
|
| 54 |
await self.redis_client.ping()
|
| 55 |
-
logger.info("✅ Connected to Redis")
|
| 56 |
|
| 57 |
# Initialize sync services
|
| 58 |
await self._initialize_sync_services()
|
|
|
|
| 42 |
await conn.execute(text("SELECT 1"))
|
| 43 |
logger.info("✅ Connected to PostgreSQL")
|
| 44 |
|
| 45 |
+
# Redis with connection pooling
|
| 46 |
logger.info(f"Connecting to Redis: {settings.REDIS_HOST}:{settings.REDIS_PORT}")
|
| 47 |
+
pool = redis.ConnectionPool(
|
| 48 |
host=settings.REDIS_HOST,
|
| 49 |
port=settings.REDIS_PORT,
|
| 50 |
password=settings.REDIS_PASSWORD,
|
| 51 |
db=settings.REDIS_DB,
|
| 52 |
+
decode_responses=True,
|
| 53 |
+
max_connections=15, # Slightly higher for sync workers
|
| 54 |
+
socket_keepalive=True,
|
| 55 |
+
socket_connect_timeout=5,
|
| 56 |
+
retry_on_timeout=True,
|
| 57 |
+
health_check_interval=30
|
| 58 |
)
|
| 59 |
+
self.redis_client = redis.Redis(connection_pool=pool)
|
| 60 |
await self.redis_client.ping()
|
| 61 |
+
logger.info("✅ Connected to Redis with connection pool (max_connections=15)")
|
| 62 |
|
| 63 |
# Initialize sync services
|
| 64 |
await self._initialize_sync_services()
|