這是來自谷歌官方博客: inside modern browser 的四篇系列文章,也有人作了全文翻譯,參見承香墨影。本文可看做一個abstract,對全文進行了重點摘要,以期讀完後對chrome瀏覽器的體系結構,處理機制有整體的瞭解。有個經典的前端面試問題:在導航欄輸入url敲下回車後發生了什麼?本文可以看做一個比較全面、深入一點的回答。
瀏覽器體系結構
- CPU 一個接一個地處理多項任務
- GPU 同時、跨內核處理多個簡單任務
開啓application時,機器的物理硬件在最底層,中間是操作系統,最上層纔是應用本身。
瀏覽器沒有一定之規。有的是單進程多線程,有的是多進程,一個進程有少量的多個線程IPC。
進程 | 功能 |
---|---|
Browser | controls ‘chrome’ part of the app and privileged parts such as network requests and file access |
Renderer | anything inside of the tab where a website is displayed |
Plugin | any plugins used by the web like flash |
GPU | Handles GPU tasks in isolation from other processes. It is separated into different process because GPUs handles requests from multiple apps and draw them in the same surface. |
- 出於安全和沙箱考慮,每個tab有獨立的renderer process
- 因爲每個進程由獨立的內存空間,這會造成一定的資源浪費(can’t share common infrasructure like v8), chrome限制了它可以啓動的進程數量。如果達到了限制,則會把多個tab上那些同源的網頁合併到一個進程中。
- chrome 正在做的事情是,把瀏https://www.cnblogs.com/peida/archive/2013/03/05/2943698.html覽器程序的每個部分作爲一項可拆分的服務。當 Chrome 在強大的硬件上運行時,它可能會將每個服務拆分爲不同的進程,從而提供更高的穩定性,但如果它位於資源約束的設備上,Chrome 會將服務整合到一個進程中,從而節省內存佔用。
- 整合進程以節省資源的策略已經被用於其他平臺,如andriod上。
每個frame有獨立渲染進程,站點隔離