How browser process manages the number of renderer process?
As you may know, chromium has multi process architecture. In this architecture many renderer processes are running. You can see many renderer processes running by ps command(in linux) or task manager(in Windows) When we use chromium browser, many renderer processes are created and destroyed. It lives long or very short depends on the situation.
In this document, I’ll cover two topics. First one is when new renderer process is created. Second is how the number of renderer processes are controlled.
Topic 1. When renderers are created and destroyed?
1. At start timeWhen user execute chromium, new renderer is created with new tab. If only one tab is opened, one renderer is created. If many tabs are opened, many renderers are created. The number of renderer process depends on installed system memory and --renderer-process-limit option. The number of renderer process will be covered second section.
2. Type new url to omnibox of opened tabWhen user types new url, whether new renderer process is created or not is depends on below two options.
*process-per-site-instanceThis is a current default process model. If user don’t add either process-per-site or process-per-tab, this mode is used. When you type new url to current tab, renderer is replaced.
I’m curious about separate visits to the same site on the same tab. Sometime, renderer process is replaced in this case.
In this mode, different tabs have different renderer regardless of its domain.
* process-per-siteIf you type url that have different domain to current tab, new renderer is created for current tab. And old renderer is destroyed. Otherwise(typed url that have same domain), existing renderer is used for rendering new url.
ex1) Current tab is in www.google.com and you type gmail.google.com, current renderer is
used because two url have same domain(google.com).
ex2) Current tab is in www.google.co.kr and you type gmail.google.com, current renderer is
destroyed and new renderer process is launched because two url has different domain.
In this mode, many tabs that have same domains are grouped in a renderer.
* process-per-tabWhen user add this switch value, one renderer process is used before the tab is closed. I found that this mode has some bug when I enabled low-memory-observer.
3. Add new tabWhen user clicks new tab button, NTP(New Tab Page) that show most visited pages or installed webapp is created. Opening many NTP sequentially don’t create renderer process. When user insert url on the NTP, new renderer is also created if renderer limit is not exceeded. If user types new url or click page snap, new renderer is created and existed renderer is destroyed. This behavior also depends --process-per-tab or --process-per-site.
4. OOM Handler (chromeos)When browser process receive oom event from kernel’s low-mem notifier, browser process choose least recently used tab’s renderer process. And that renderer is discarded.
Topic 2. How many renderers are created?
As I mentioned earlier, you can see many renderers. The number of tabs is not equals the number of renderer process. In this topic, I’ll explain what determines the number of renderer process
1. --renderer-process-limit=NBrowser process only creates renderer process up to N. When new tab is created, RenderProcessHost checks whether this switch is used.
2. --single-processBrowser process don’t create renderer process if this is on.
3. Installed system memoryIf above switches are not used, max number of renderer process is calculated based on installed system memory not available memory.
You can see the formula that calculates the max number of renderer process in the RenderProcessHost::GetMaxRendererProcessCount().
4. The number of Extension service processIf there is a room to create another renderer process, chromium considers running extension service. Browser process don’t create renderer if extension service process number is bigger than max number of render process * 0.3.
Refer to ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost().