Spaces:
Running
Running
nacho commited on
Commit ·
da32f5f
1
Parent(s): b8df3fa
perf: 注入大量无头浏览器省内存参数,并将并发限制降低至3个,彻底杜绝内存爆炸问题
Browse files- account_manager.py +1 -1
- deepseek_browser.py +16 -1
account_manager.py
CHANGED
|
@@ -27,7 +27,7 @@ class Account:
|
|
| 27 |
|
| 28 |
|
| 29 |
class AccountManager:
|
| 30 |
-
def __init__(self, max_inflight: int = 1, max_active_browsers: int =
|
| 31 |
self.accounts: Dict[str, Account] = {}
|
| 32 |
self.queue: deque = deque()
|
| 33 |
self.max_inflight = max_inflight
|
|
|
|
| 27 |
|
| 28 |
|
| 29 |
class AccountManager:
|
| 30 |
+
def __init__(self, max_inflight: int = 1, max_active_browsers: int = 3):
|
| 31 |
self.accounts: Dict[str, Account] = {}
|
| 32 |
self.queue: deque = deque()
|
| 33 |
self.max_inflight = max_inflight
|
deepseek_browser.py
CHANGED
|
@@ -49,13 +49,28 @@ class DeepSeekBrowser:
|
|
| 49 |
async def start(self):
|
| 50 |
self.profile_dir.mkdir(parents=True, exist_ok=True)
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
self.context = await launch_persistent_context_async(
|
| 53 |
user_data_dir=str(self.profile_dir),
|
| 54 |
headless=self.headless,
|
| 55 |
humanize=self.humanize,
|
| 56 |
proxy=self.proxy,
|
| 57 |
-
viewport={"width":
|
| 58 |
locale="zh-CN",
|
|
|
|
| 59 |
)
|
| 60 |
|
| 61 |
self.page = await self.context.new_page()
|
|
|
|
| 49 |
async def start(self):
|
| 50 |
self.profile_dir.mkdir(parents=True, exist_ok=True)
|
| 51 |
|
| 52 |
+
# 极致的省内存参数
|
| 53 |
+
args = [
|
| 54 |
+
"--disable-gpu",
|
| 55 |
+
"--disable-dev-shm-usage",
|
| 56 |
+
"--disable-extensions",
|
| 57 |
+
"--disable-background-networking",
|
| 58 |
+
"--disable-default-apps",
|
| 59 |
+
"--disable-sync",
|
| 60 |
+
"--mute-audio",
|
| 61 |
+
"--no-sandbox",
|
| 62 |
+
"--js-flags=--max-old-space-size=128", # 限制 V8 引擎内存
|
| 63 |
+
"--renderer-process-limit=1", # 限制渲染进程
|
| 64 |
+
]
|
| 65 |
+
|
| 66 |
self.context = await launch_persistent_context_async(
|
| 67 |
user_data_dir=str(self.profile_dir),
|
| 68 |
headless=self.headless,
|
| 69 |
humanize=self.humanize,
|
| 70 |
proxy=self.proxy,
|
| 71 |
+
viewport={"width": 1280, "height": 720}, # 减小渲染面积,降低合成内存
|
| 72 |
locale="zh-CN",
|
| 73 |
+
args=args,
|
| 74 |
)
|
| 75 |
|
| 76 |
self.page = await self.context.new_page()
|