Skip to content

Performance Issue: Global ReentrantLock in bubus Limits Concurrency #21

@eltomon

Description

@eltomon

I’ve noticed that when running browser-use within a FastAPI application or using the provided parallel_browser.py example, tasks do not scale concurrently as expected.

When initiating multiple agent instances simultaneously, the execution time increases significantly rather than staying relatively constant.
Single task: ~10 seconds.
3 concurrent tasks: ~25 seconds.
10 concurrent tasks: Performance degrades further.

After investigating the bubus library, I found that the event processing logic uses a global reentrant lock (_global_eventbus_lock). This lock ensures that only one event across all EventBus contexts can be processed at any given time.

# Always acquire the global lock (it's re-entrant across tasks)
async with _get_global_lock():
    # Process the event
    await self.process_event(event, timeout=timeout)

    # Mark task as done only if we got it from the queue
    if from_queue:
        self.event_queue.task_done()

Was this global lock intended to prevent a specific race condition in shared resources, or could it be moved to a per-instance lock?
If the goal is to allow multiple agents to run in true parallel, we should consider:
Removing the global lock if it's not protecting shared state.
Scoping the lock to the instance so that different contexts don't block each other.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions