优化浏览器池和并发配置

1. 浏览器池改为按需启动模式
   - 启动时不创建浏览器,有截图任务时才启动
   - 空闲5分钟后自动关闭浏览器释放资源

2. 修复截图并发数保存问题
   - 修复database.py中缺少保存max_screenshot_concurrent的代码

3. 去掉并发数上限限制
   - 管理员可自由设置并发数,不再限制1-20/1-5

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-10 20:31:49 +08:00
parent f46c662fe5
commit a8e8bbe8a2
4 changed files with 43 additions and 36 deletions

View File

@@ -579,26 +579,26 @@
<h3 style="margin-bottom: 15px; font-size: 16px;">系统并发配置</h3>
<div class="form-group">
<label>全局最大并发数 (1-20)</label>
<label>全局最大并发数</label>
<input type="number" id="maxConcurrent" min="1" value="2" style="max-width: 200px;">
<div style="font-size: 12px; color: #666; margin-top: 5px;">
说明同时最多运行的账号数量。浏览任务使用API方式资源占用极低截图任务会启动浏览器。建议设置2-5
说明同时最多运行的账号数量。浏览任务使用API方式资源占用极低。
</div>
</div>
<div class="form-group">
<label>单账号最大并发数 (1-5)</label>
<label>单账号最大并发数</label>
<input type="number" id="maxConcurrentPerAccount" min="1" value="1" style="max-width: 200px;">
<div style="font-size: 12px; color: #666; margin-top: 5px;">
说明:单个账号同时最多运行的任务数量。建议设置1-2。
说明:单个账号同时最多运行的任务数量。
</div>
</div>
<div class="form-group">
<label>截图最大并发数 (1-5)</label>
<label>截图最大并发数</label>
<input type="number" id="maxScreenshotConcurrent" min="1" value="3" style="max-width: 200px;">
<div style="font-size: 12px; color: #666; margin-top: 5px;">
说明:同时进行截图的最大数量。截图使用浏览器建议设置2-3
说明:同时进行截图的最大数量。每个浏览器约占用200MB内存
</div>
</div>
@@ -1509,22 +1509,22 @@
const maxConcurrentPerAccount = parseInt(document.getElementById('maxConcurrentPerAccount').value);
const maxScreenshotConcurrent = parseInt(document.getElementById('maxScreenshotConcurrent').value);
if (maxConcurrent < 1 || maxConcurrent > 20) {
showNotification('全局并发数必须在1-20之间', 'error');
if (maxConcurrent < 1) {
showNotification('全局并发数必须大于0', 'error');
return;
}
if (maxConcurrentPerAccount < 1 || maxConcurrentPerAccount > 5) {
showNotification('单账号并发数必须在1-5之间', 'error');
if (maxConcurrentPerAccount < 1) {
showNotification('单账号并发数必须大于0', 'error');
return;
}
if (maxScreenshotConcurrent < 1 || maxScreenshotConcurrent > 5) {
showNotification('截图并发数必须在1-5之间', 'error');
if (maxScreenshotConcurrent < 1) {
showNotification('截图并发数必须大于0', 'error');
return;
}
if (!confirm(`确定更新并发配置吗?\n\n全局并发数: ${maxConcurrent}\n单账号并发数: ${maxConcurrentPerAccount}\n\n建议并发数影响任务执行速度过高可能触发目标服务器限制。全局建议2-5单账号建议1-2`)) return;
if (!confirm(`确定更新并发配置吗?\n\n全局并发数: ${maxConcurrent}\n单账号并发数: ${maxConcurrentPerAccount}\n截图并发数: ${maxScreenshotConcurrent}`)) return;
try {
const response = await fetch('/yuyx/api/system/config', {