perf(douyu): 消除任务锁竞争并增加创建背压
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user