这是来自谷歌官方博客: 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有独立渲染进程,站点隔离