perf(douyu): 消除任务锁竞争并增加创建背压

This commit is contained in:
yml
2026-11-19 22:01:21 +08:00
parent 62cb0a41ec
commit 09cdf3f2eb
11 changed files with 555 additions and 95 deletions
+13
View File
@@ -82,6 +82,19 @@ if DATABASE_URL.startswith("sqlite"):
cursor.execute("PRAGMA busy_timeout=30000")
cursor.execute("PRAGMA foreign_keys=ON")
cursor.close()
else:
@event.listens_for(engine, "connect")
def _set_mysql_session_guards(dbapi_connection, connection_record):
"""让行锁等待快速失败,避免单个事务把连接池堵住几十秒。"""
cursor = dbapi_connection.cursor()
try:
cursor.execute(
"SET SESSION innodb_lock_wait_timeout = "
f"{_env_int('DB_LOCK_WAIT_TIMEOUT', 10)}"
)
finally:
cursor.close()
SessionLocal = sessionmaker(bind=engine, autocommit=False, autoflush=False)