mirror of
https://github.com/xfgryujk/blivechat.git
synced 2024-12-26 21:00:15 +08:00
优化一些参数
This commit is contained in:
parent
8e7d9b266b
commit
8fa63f1d75
@ -2,8 +2,8 @@
|
|||||||
# If you want to modify the configuration, copy this file and rename it to "config.ini" and edit
|
# If you want to modify the configuration, copy this file and rename it to "config.ini" and edit
|
||||||
|
|
||||||
[app]
|
[app]
|
||||||
# 数据库配置,见https://docs.sqlalchemy.org/en/13/core/engines.html#database-urls
|
# 数据库配置,见 https://docs.sqlalchemy.org/en/20/core/engines.html#database-urls
|
||||||
# See https://docs.sqlalchemy.org/en/13/core/engines.html#database-urls
|
# See https://docs.sqlalchemy.org/en/20/core/engines.html#database-urls
|
||||||
database_url = sqlite:///data/database.db
|
database_url = sqlite:///data/database.db
|
||||||
|
|
||||||
# 如果使用了nginx之类的反向代理服务器,设置为true
|
# 如果使用了nginx之类的反向代理服务器,设置为true
|
||||||
@ -24,17 +24,17 @@ open_browser_at_startup = true
|
|||||||
enable_upload_file = true
|
enable_upload_file = true
|
||||||
|
|
||||||
|
|
||||||
# 获取头像间隔时间(秒)。如果小于3秒有很大概率被服务器拉黑
|
# 获取头像间隔时间(秒)。如果小于5秒有很大概率被服务器拉黑
|
||||||
# Interval between fetching avatars (seconds). At least 3 seconds is recommended
|
# Interval between fetching avatars (seconds). At least 3 seconds is recommended
|
||||||
fetch_avatar_interval = 3.5
|
fetch_avatar_interval = 5.5
|
||||||
|
|
||||||
# 获取头像最大队列长度,注意最长等待时间等于 最大队列长度 * 请求间隔时间
|
# 获取头像最大队列长度,注意最长等待时间等于 最大队列长度 * 请求间隔时间
|
||||||
# Maximum queue length for fetching avatar
|
# Maximum queue length for fetching avatar
|
||||||
fetch_avatar_max_queue_size = 2
|
fetch_avatar_max_queue_size = 1
|
||||||
|
|
||||||
# 头像缓存数量
|
# 内存中头像缓存数量
|
||||||
# Number of avatar caches
|
# Number of avatar caches in memory
|
||||||
avatar_cache_size = 50000
|
avatar_cache_size = 10000
|
||||||
|
|
||||||
|
|
||||||
# 允许自动翻译到日语
|
# 允许自动翻译到日语
|
||||||
|
1
main.py
1
main.py
@ -67,7 +67,6 @@ def init_logging(debug):
|
|||||||
)
|
)
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
format='{asctime} {levelname} [{name}]: {message}',
|
format='{asctime} {levelname} [{name}]: {message}',
|
||||||
datefmt='%Y-%m-%d %H:%M:%S',
|
|
||||||
style='{',
|
style='{',
|
||||||
level=logging.INFO if not debug else logging.DEBUG,
|
level=logging.INFO if not debug else logging.DEBUG,
|
||||||
handlers=[stream_handler, file_handler]
|
handlers=[stream_handler, file_handler]
|
||||||
|
@ -15,8 +15,15 @@ class OrmBase(sqlalchemy.orm.DeclarativeBase):
|
|||||||
def init(_debug):
|
def init(_debug):
|
||||||
cfg = config.get_config()
|
cfg = config.get_config()
|
||||||
global _engine
|
global _engine
|
||||||
# engine = sqlalchemy.create_engine(cfg.database_url, echo=debug)
|
_engine = sqlalchemy.create_engine(
|
||||||
_engine = sqlalchemy.create_engine(cfg.database_url)
|
cfg.database_url,
|
||||||
|
pool_size=5, # 保持的连接数
|
||||||
|
max_overflow=5, # 临时的额外连接数
|
||||||
|
pool_timeout=3, # 连接数达到最大时获取新连接的超时时间
|
||||||
|
# pool_pre_ping=True, # 获取连接时先检测是否可用
|
||||||
|
pool_recycle=60 * 60, # 回收超过1小时的连接,防止数据库服务器主动断开不活跃的连接
|
||||||
|
# echo=debug, # 输出SQL语句
|
||||||
|
)
|
||||||
|
|
||||||
OrmBase.metadata.create_all(_engine)
|
OrmBase.metadata.create_all(_engine)
|
||||||
|
|
||||||
|
@ -191,7 +191,7 @@ async def _get_avatar_url_from_web_consumer():
|
|||||||
if _last_fetch_banned_time is not None:
|
if _last_fetch_banned_time is not None:
|
||||||
cur_time = datetime.datetime.now()
|
cur_time = datetime.datetime.now()
|
||||||
if (cur_time - _last_fetch_banned_time).total_seconds() < 3 * 60 + 3:
|
if (cur_time - _last_fetch_banned_time).total_seconds() < 3 * 60 + 3:
|
||||||
# 3分钟以内被ban,解封大约要15分钟
|
# 3分钟以内被ban
|
||||||
future.set_result(None)
|
future.set_result(None)
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
@ -216,7 +216,7 @@ async def _get_avatar_url_from_web_wrapper(user_id, future):
|
|||||||
|
|
||||||
|
|
||||||
async def _do_get_avatar_url_from_web(user_id) -> Optional[str]:
|
async def _do_get_avatar_url_from_web(user_id) -> Optional[str]:
|
||||||
global _wbi_key, _refresh_wbi_key_future
|
global _wbi_key, _refresh_wbi_key_future, _last_fetch_banned_time
|
||||||
if _wbi_key == '':
|
if _wbi_key == '':
|
||||||
if _refresh_wbi_key_future is None:
|
if _refresh_wbi_key_future is None:
|
||||||
_refresh_wbi_key_future = asyncio.create_task(_refresh_wbi_key())
|
_refresh_wbi_key_future = asyncio.create_task(_refresh_wbi_key())
|
||||||
@ -236,17 +236,20 @@ async def _do_get_avatar_url_from_web(user_id) -> Optional[str]:
|
|||||||
logger.warning('Failed to fetch avatar: status=%d %s uid=%d', r.status, r.reason, user_id)
|
logger.warning('Failed to fetch avatar: status=%d %s uid=%d', r.status, r.reason, user_id)
|
||||||
if r.status == 412:
|
if r.status == 412:
|
||||||
# 被B站ban了
|
# 被B站ban了
|
||||||
global _last_fetch_banned_time
|
|
||||||
_last_fetch_banned_time = datetime.datetime.now()
|
_last_fetch_banned_time = datetime.datetime.now()
|
||||||
return None
|
return None
|
||||||
data = await r.json()
|
data = await r.json()
|
||||||
except (aiohttp.ClientConnectionError, asyncio.TimeoutError):
|
except (aiohttp.ClientConnectionError, asyncio.TimeoutError):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if data['code'] != 0:
|
code = data['code']
|
||||||
# 这里虽然失败但不会被ban一段时间
|
if code != 0:
|
||||||
logger.info('Failed to fetch avatar: code=%d %s uid=%d', data['code'], data['message'], user_id)
|
logger.info('Failed to fetch avatar: code=%d %s uid=%d', code, data['message'], user_id)
|
||||||
if data['code'] == -403:
|
if code == -401:
|
||||||
|
# 被B站ban了
|
||||||
|
_last_fetch_banned_time = datetime.datetime.now()
|
||||||
|
elif code == -403:
|
||||||
|
# 签名错误
|
||||||
_wbi_key = ''
|
_wbi_key = ''
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -403,8 +403,8 @@ class TencentTranslateFree(FlowControlTranslateProvider):
|
|||||||
|
|
||||||
def _on_fail(self):
|
def _on_fail(self):
|
||||||
self._fail_count += 1
|
self._fail_count += 1
|
||||||
# 为了可靠性,连续失败10次时冷却直到下次重新init
|
# 为了可靠性,连续失败5次时冷却直到下次重新init
|
||||||
if self._fail_count >= 10:
|
if self._fail_count >= 5:
|
||||||
self._cool_down()
|
self._cool_down()
|
||||||
|
|
||||||
def _cool_down(self):
|
def _cool_down(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user