Collecting Renders from Multiple Browser Sessions
This tutorial builds on Collecting Renders from a Virtual Camera and shows you how to scale up render collection using a job queue with multiple browser sessions.
In the previous tutorial, we used grab_render() to capture frames from a single browser session. When you need to render many frames (e.g., for dataset generation), you can parallelize the work across multiple browser sessions connecting to the same Vuer server.
This tutorial will teach you how to:
- Create a simple job queue to manage rendering tasks
- Handle multiple browser sessions concurrently
- Implement error handling with job recovery
Step 1: Set Up Imports and Scene
First, we set up the basic imports and create a scene with an on-demand virtual camera.
Step 2: Implement the Job Queue
We define a simple job queue where each job is a dictionary of parameters. The queue tracks job status and supports recovery of failed jobs.
Each job has three possible states:
None: Available, waiting to be taken"in_progress": Currently being processed by a browser session- Removed from queue: Completed successfully
Step 3: Create and Populate the Job Queue
Now we create a job queue and populate it with rendering jobs. In a real application, these jobs might contain camera poses, scene parameters, or other rendering settings.
Step 4: Track Connected Sessions
We use a simple counter to track how many browser sessions are currently connected. This helps monitor the parallelism of your rendering pipeline.
Step 5: Process Jobs from the Queue
Each browser session that connects will take jobs from the queue and process them. The @app.spawn decorator creates a handler that runs for each connected session.
Key points:
- Each session takes one job at a time from the queue
- On success,
mark_done()removes the job from the queue - On failure,
put_back()resets the job so another session can retry - The session counter tracks active connections
Step 6: Running the Tutorial
Paste the code into render_queue.py and run:
Open the URL printed in the terminal (usually https://vuer.ai) in multiple browser tabs. Each tab will connect as a separate session and start processing jobs from the queue.
How It Works
Each browser session:
- Takes an available job from the queue
- Processes the job (updates scene, captures renders)
- Marks the job as done or puts it back on failure
- Repeats until the queue is empty
This pattern allows you to scale rendering by simply opening more browser tabs or connecting from multiple machines.