perf(worker): 调高斗鱼任务与批次执行并发默认上限
This commit is contained in:
@@ -1888,7 +1888,7 @@ class DouyuTaskBatchRequest(BaseModel):
|
||||
account_ids: list[int]
|
||||
task_type: str
|
||||
handbook_scope: str = Field(..., pattern="^(elite|esports|peace)$")
|
||||
concurrency: int = Field(3, ge=1, le=10)
|
||||
concurrency: int = Field(5, ge=1, le=15)
|
||||
payload: dict[str, Any] = Field(default_factory=dict)
|
||||
platform_task_id: int | None = Field(None, gt=0)
|
||||
recharge_confirmation_token: str | None = Field(None, max_length=64)
|
||||
|
||||
@@ -226,7 +226,7 @@ def register_default_jobs() -> None:
|
||||
# relogin_next_at 的退避表决定);批次小、跑得慢,单轮 10 条。
|
||||
interval_seconds=6 * 3600,
|
||||
batch_size=10,
|
||||
concurrency=3,
|
||||
concurrency=5,
|
||||
run=run_ck_relogin,
|
||||
)
|
||||
)
|
||||
@@ -253,7 +253,7 @@ def register_default_jobs() -> None:
|
||||
# 反推,吞吐 40 条/分钟,够 6 小时内覆盖一遍(规划 §7.3)。
|
||||
interval_seconds=6 * 3600,
|
||||
batch_size=200,
|
||||
concurrency=5,
|
||||
concurrency=8,
|
||||
run=run_ck_health,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -74,7 +74,7 @@ _REGISTRY: dict[str, JobSpec] = {}
|
||||
|
||||
#: 同时最多几个作业在跑。作业之间互不依赖,并行是为了**慢作业不挡住快作业**
|
||||
#: (以前串行:一个作业跑 4 分钟,CK 巡检就得等 4 分钟)。
|
||||
_JOB_MAX_WORKERS = 2
|
||||
_JOB_MAX_WORKERS = 3
|
||||
|
||||
#: 运行间隔的下限:太短会变成忙轮询,没有意义
|
||||
MIN_RUN_INTERVAL_SECONDS = 30
|
||||
|
||||
@@ -25,9 +25,9 @@ def _env_positive_int(name: str, default: int) -> int:
|
||||
|
||||
DOUYU_BATCH_CREATE_CONCURRENCY = _env_positive_int(
|
||||
"DOUYU_BATCH_CREATE_CONCURRENCY",
|
||||
2,
|
||||
4,
|
||||
)
|
||||
DOUYU_MAX_ACTIVE_BATCHES = _env_positive_int("DOUYU_MAX_ACTIVE_BATCHES", 10)
|
||||
DOUYU_MAX_ACTIVE_BATCHES = _env_positive_int("DOUYU_MAX_ACTIVE_BATCHES", 25)
|
||||
|
||||
|
||||
def _run_batch(
|
||||
|
||||
@@ -19,11 +19,11 @@ def _env_positive_int(name: str, default: int) -> int:
|
||||
|
||||
DOUYU_BATCH_TASK_CONCURRENCY = _env_positive_int(
|
||||
"DOUYU_BATCH_TASK_CONCURRENCY",
|
||||
5,
|
||||
10,
|
||||
)
|
||||
DOUYU_PAYMENT_QR_CONCURRENCY = _env_positive_int(
|
||||
"DOUYU_PAYMENT_QR_CONCURRENCY",
|
||||
10,
|
||||
15,
|
||||
)
|
||||
|
||||
PAYMENT_QR_TASK_TYPES = frozenset(
|
||||
|
||||
@@ -167,7 +167,7 @@ def _env_positive_int(name: str, default: int) -> int:
|
||||
return value if value > 0 else default
|
||||
|
||||
|
||||
DOUYU_MAX_ACTIVE_TASKS = _env_positive_int("DOUYU_MAX_ACTIVE_TASKS", 250)
|
||||
DOUYU_MAX_ACTIVE_TASKS = _env_positive_int("DOUYU_MAX_ACTIVE_TASKS", 500)
|
||||
|
||||
|
||||
class DouyuActivePaymentError(ValueError):
|
||||
@@ -412,7 +412,7 @@ def create_douyu_planned_tasks(
|
||||
created_by: int,
|
||||
payload: dict | None = None,
|
||||
platform_task_id: int | None = None,
|
||||
concurrency: int = 3,
|
||||
concurrency: int = 5,
|
||||
enqueue_execution: bool = True,
|
||||
recharge_channel: str = "",
|
||||
recharge_amount: int | None = None,
|
||||
@@ -545,7 +545,7 @@ def create_douyu_planned_tasks(
|
||||
payload={
|
||||
"task_type": task_type,
|
||||
"payload": payload,
|
||||
"concurrency": max(1, min(int(concurrency), 10)),
|
||||
"concurrency": max(1, min(int(concurrency), 15)),
|
||||
},
|
||||
created_by=int(created_by),
|
||||
priority=40,
|
||||
|
||||
@@ -32,7 +32,7 @@ from .execution_jobs import (
|
||||
)
|
||||
from .login_service import LoginBatchRunner
|
||||
|
||||
DEFAULT_EXECUTION_WORKERS = 2
|
||||
DEFAULT_EXECUTION_WORKERS = 6
|
||||
DEFAULT_POLL_SECONDS = 1
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ def _lane_slot_limits() -> dict[str, int]:
|
||||
)
|
||||
auth_limit = _env_positive_int(
|
||||
"EXECUTION_WORKER_AUTH_JOBS",
|
||||
max(1, total - 1),
|
||||
max(1, total - 2),
|
||||
)
|
||||
fulfillment_limit = _env_positive_int(
|
||||
"EXECUTION_WORKER_FULFILLMENT_JOBS",
|
||||
@@ -87,9 +87,7 @@ def _lane_slot_limits() -> dict[str, int]:
|
||||
def _lane_claim_order() -> tuple[str, ...]:
|
||||
"""领取顺序:履约优先,登录用剩余槽位。"""
|
||||
lanes = _lane_scopes()
|
||||
return tuple(
|
||||
sorted(lanes, key=lambda lane: 0 if lane == LANE_FULFILLMENT else 1)
|
||||
)
|
||||
return tuple(sorted(lanes, key=lambda lane: 0 if lane == LANE_FULFILLMENT else 1))
|
||||
|
||||
|
||||
class ExecutionJobWorker:
|
||||
@@ -173,9 +171,7 @@ class ExecutionJobWorker:
|
||||
# 履约优先:先把 fulfillment 的槽填满,登录只用剩下的。
|
||||
# 登录批次等邮箱验证码时可能持槽 25 分钟,绝不能把履约饿死。
|
||||
for lane in _lane_claim_order():
|
||||
lane_free = lane_limits.get(lane, 0) - self._inflight.get(
|
||||
lane, 0
|
||||
)
|
||||
lane_free = lane_limits.get(lane, 0) - self._inflight.get(lane, 0)
|
||||
take = min(slots, lane_free)
|
||||
if take <= 0:
|
||||
continue
|
||||
@@ -272,8 +268,7 @@ class ExecutionJobWorker:
|
||||
runner = LoginBatchRunner(
|
||||
db=db,
|
||||
account_ids=[
|
||||
int(value)
|
||||
for value in payload.get("account_ids", [])
|
||||
int(value) for value in payload.get("account_ids", [])
|
||||
],
|
||||
created_by=int(job.created_by),
|
||||
creator_permissions=get_user_permissions(user),
|
||||
@@ -285,7 +280,9 @@ class ExecutionJobWorker:
|
||||
concurrency=int(payload.get("concurrency", 3) or 3),
|
||||
api_strategy=str(payload.get("api_strategy", "wgapi") or "wgapi"),
|
||||
mode=str(payload.get("mode", "login") or "login"),
|
||||
trigger_source=str(payload.get("trigger_source", "manual") or "manual"),
|
||||
trigger_source=str(
|
||||
payload.get("trigger_source", "manual") or "manual"
|
||||
),
|
||||
batch_id=job.batch_id,
|
||||
log_sink=log_sink,
|
||||
)
|
||||
|
||||
@@ -52,22 +52,22 @@ class LaneConfig:
|
||||
|
||||
|
||||
_DEFAULT_WORKERS: dict[TaskLane, int] = {
|
||||
TaskLane.INTERACTIVE_BINDING: 3,
|
||||
TaskLane.BATCH_COORDINATOR: 2,
|
||||
TaskLane.BINDING_POLL: 6,
|
||||
TaskLane.LOGIN: 4,
|
||||
TaskLane.ACCOUNT_CHECK: 4,
|
||||
TaskLane.ACCOUNT_SYNC: 3,
|
||||
TaskLane.AUTOMATION: 2,
|
||||
TaskLane.OVERVIEW_QUERY: _env_int("DOUYU_MAX_ACTIVE_OVERVIEW_TASKS", 5),
|
||||
TaskLane.QUERY_BATCH: 3,
|
||||
TaskLane.COLLAB_RECOMMEND: 2,
|
||||
TaskLane.PAYMENT_QR: 10,
|
||||
TaskLane.PAYMENT_POLL: 3,
|
||||
TaskLane.OPS_WRITE: 2,
|
||||
TaskLane.HUYA_BATCH: 2,
|
||||
TaskLane.HUYA_REGISTER: 2,
|
||||
TaskLane.INTEGRATION: 2,
|
||||
TaskLane.INTERACTIVE_BINDING: 6,
|
||||
TaskLane.BATCH_COORDINATOR: 6,
|
||||
TaskLane.BINDING_POLL: 12,
|
||||
TaskLane.LOGIN: 8,
|
||||
TaskLane.ACCOUNT_CHECK: 8,
|
||||
TaskLane.ACCOUNT_SYNC: 6,
|
||||
TaskLane.AUTOMATION: 3,
|
||||
TaskLane.OVERVIEW_QUERY: _env_int("DOUYU_MAX_ACTIVE_OVERVIEW_TASKS", 10),
|
||||
TaskLane.QUERY_BATCH: 10,
|
||||
TaskLane.COLLAB_RECOMMEND: 4,
|
||||
TaskLane.PAYMENT_QR: 12,
|
||||
TaskLane.PAYMENT_POLL: 6,
|
||||
TaskLane.OPS_WRITE: 6,
|
||||
TaskLane.HUYA_BATCH: 5,
|
||||
TaskLane.HUYA_REGISTER: 3,
|
||||
TaskLane.INTEGRATION: 4,
|
||||
TaskLane.MAINTENANCE: 1,
|
||||
}
|
||||
|
||||
|
||||
@@ -224,7 +224,7 @@ export default function DouyuTasksPage({
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [runningBatchIds, setRunningBatchIds] = useState<Set<string>>(new Set());
|
||||
const [configOpen, setConfigOpen] = useState(false);
|
||||
const [concurrency, setConcurrency] = useState(3);
|
||||
const [concurrency, setConcurrency] = useState(5);
|
||||
const [goldAmount, setGoldAmount] = useState(() => savedPositiveInteger(DOUYU_GOLD_AMOUNT_STORAGE_KEY));
|
||||
// 历史兑换截图默认不展示;只有本页面本次实际发起过兑换的账号才显示。
|
||||
const [exchangeImageAccountIds, setExchangeImageAccountIds] = useState<Set<number>>(() => new Set());
|
||||
@@ -1076,10 +1076,10 @@ export default function DouyuTasksPage({
|
||||
}
|
||||
// 支付码批次尽量一次全出码,队列只负责展示和等待到账,不让人工等前一个付完才生成下一个。
|
||||
const batchConcurrency = DOUYU_PAYMENT_TASK_TYPE_SET.has(taskType)
|
||||
? Math.min(10, Math.max(concurrency, ids.length))
|
||||
? Math.min(15, Math.max(concurrency, ids.length))
|
||||
: taskType === 'query_account_overview'
|
||||
? Math.min(5, Math.max(concurrency, ids.length))
|
||||
: Math.min(5, concurrency);
|
||||
? Math.min(10, Math.max(concurrency, ids.length))
|
||||
: Math.min(10, concurrency);
|
||||
try {
|
||||
const result = await douyuApi.createTasks({
|
||||
account_ids: ids,
|
||||
|
||||
Reference in New Issue
Block a user