Skip to content

Conversation

@mzyfree
Copy link

@mzyfree mzyfree commented Dec 23, 2025

Summary

This PR adds a new configuration option use_permanent to the Docker deployment mode.

Problem: Currently, a permanent browser instance is always initialized at startup, which consumes roughly 200MB-300MB of memory regardless of actual usage. In resource-constrained environments or high-concurrency stress tests, this persistent instance contributes to memory accumulation and potential OOM (Out Of Memory) issues.

Solution: By introducing the use_permanent toggle, users can now choose to disable the persistent browser. When disabled, browser instances are created strictly on-demand and are fully managed by the janitor cleanup logic, ensuring better memory reclamation.

List of files changed and why

  • deploy/docker/server.py: Modified the lifespan startup sequence to conditionally initialize the browser pool based on the use_permanent config. Added a fallback default of True to ensure zero breaking changes for existing users.
  • deploy/docker/config.yml: Added the use_permanent flag under the crawler.pool section to make the feature discoverable and configurable.

How Has This Been Tested?

  1. Default Behavior: Verified that the permanent browser still starts as usual when the config is missing or set to true.
  2. On-Demand Mode: Set use_permanent: false and verified the following:
    • Log confirmation: 🚫 Permanent browser instance is disabled by default to save memory.
    • Baseline memory usage decreased significantly at container startup.
    • Successfully performed crawls; the system correctly fell back to creating on-demand instances in the COLD_POOL.
  3. Resource Reclamation: Confirmed that on-demand browsers are correctly terminated by the janitor task after the idle_ttl_sec threshold is reached.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (Config updated in config.yml)
  • I have added/updated unit tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@mzyfree
Copy link
Author

mzyfree commented Dec 24, 2025

@unclecode please review the code.

@mzyfree mzyfree force-pushed the feat/configurable-permanent-browser branch from 30d92a9 to e24f838 Compare December 25, 2025 02:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant