blob: ffdf8bd6818615f4dcbe09afc352baf6ecb8f5e0 [file] [log] [blame] [view]
Sigurdur Asgeirsson51d9d242019-10-07 20:38:341# Performance Manager Overview
2
Sigurdur Asgeirssoncdd10d62020-02-14 19:50:143[TOC]
Olivier Li0e6cff52020-02-04 17:51:214
Sigurdur Asgeirssoncdd10d62020-02-14 19:50:145# Overview
Olivier Li0e6cff52020-02-04 17:51:216
Sigurdur Asgeirssoncdd10d62020-02-14 19:50:147The Performance Manager supports data-driven, centralized resource management,
8prioritization and planning for the Chrome browser. Over time, data-driven,
9centralized resource management will supplant and/or supplement the heuristics
10that can be found all over Chrome at present.
11
12Heres an overview picture of the intended architecture:
13
14![Overview Image](doc/overview.png)
15
16- The *Embedder* is responsible for notifying the
17 [Performance Manager Registry](embedder/performance_manager_registry.h) when
18 content entities are created or their relationships change. The Performance Manager
19 Registry maintains the structure of the Graph, which is a coarsely abstracted view of the state
20 of the browser.
21- Decorators populate the graph nodes with interesting properties and data, such as e.g. the results
22 of CPU, memory and battery measurements and so on.
23- Aggregators aggregate data in the graph, possibly across nodes.
24 As an example, the memory usage of all frame nodes could be summed up to their associated page
25 node, to establish the total memory usage of the page.
26- Resource Management Policies are observers of the graph, and use the graph structure as well as
27 the properties of graph nodes to make policy decisions.
28- Resource Management Mechanisms are invoked by Resource Management Policy to implement policy
29 decisions.
30 Note that while the mechanisms are depicted in the main thread, they can be hosted anywhere
31 necessary or convenient, such as in a renderer process at the far end of a mojo::Remote<>.
32- Content Proxies are a convenience feature to allow easy and safe access from nodes in the graph
33 to the corresponding content entity for any task that needs to run on the main thread.
34
35The graph lives on the Performance Manager Sequence, as do all graph observers and mutators.
36The graph structure can be viewed in the graph tab of the `chrome://discards WebUI.`
37
38In addition to the above, the Performance Manager also provides support for
39users that need to occasionally query the graph to e.g. collect metrics.
40
41# Details
42
43## Graph
44
45The performance manager exposes a simplified, coarse model of the browsers
46state as a [Graph](public/graph/graph.h) of [Nodes](public/graph/node.h),
47where the nodes represent such things as:
481. [Page](public/graph/page_node.h): corresponds to a content::WebContents.
491. [Frame](public/graph/frame_node.h): corresponds to a frame in a
50 content::WebContents frame tree.
511. [Process](public/graph/process_node.h): corresponds to a content::RenderProcessHost or
52 other type of process, such as e.g. the Browser or GPU process.
531. [Worker](public/graph/worker_node.h): corresponds to a web worker.
54
55Nodes in the graph are connected with edges, such that e.g. each frame or worker
56connects to its hosting process.
57Frames are connected in a tree, and all frames in a tree connect to their
58corresponding page.
59Other edge types may denote dependencies between nodes, such as e.g. a
60MessagePort connection or the like. Different node types in the graph are
61adorned with different sets of properties, each of which represents necessary
62information about the particular node type.
63The graph provides node lookup and retrieval, as well as an observer interface
64for notification of addition and removal of nodes, as well as node property
65changes.
66The graph also provides a way for users to adorn nodes with private data by means of
67[Node Attached Data](public/graph/node_attached_data.h).
68Its preferable to store data thats used for intermediate results or for
69private purposes in Node Attached Data rather than in Node properties.
70
71## Public & Private APIs.
72
73The graph exposes both a public and a private API. The private API is only
74available to code in the components directory, whereas the public API can be
75used by anyone in the browser process. The private API provides read-write
76access to nodes and allows for node-intimate storage of node attached
77properties. The public API provides read-only access to nodes, but otherwise the
78two APIs are fairly similar. Where possible, using the public API is preferable,
79as the public API is more stable, and doesnt require the user to live in the
80component.
81
82Good examples where the public API is appropriate, is e.g. for periodically
83collecting metrics by iteration over the graph, or where iterating over the
84graph can yield a set of content entities for some operation. As an example,
85finding the set of frames in a page that belong to the same browsing instance
86would be easy to do by iterating over the graph.
87
88## Decorators
89
90Decorators set properties on the graph that are derived from data external to
91the graph itself, such as e.g. performance measurement data.
92
93A simple example Decorator might periodically measure the cumulative CPU usage
94for each process Node in the Graph and adorn each node with the measured
95cumulative CPU usage of the corresponding process.
96
97## Aggregators
98
99Aggregators, like Decorators, set properties on the graph nodes. The difference is that
100Aggregators work solely on data in the graph, to e.g. aggregate or distribute data from
101one node to another.
102
103A simple example Aggregator working with the simple example Decorator above might
104compute the difference in cumulative CPU usage from the most recent measurement,
105then distribute the difference across the Frame (and/or Worker) nodes associated
106with each Process.
107This would in turn allow summing up the cumulative CPU usage of each Frame and
108Worker node to their associated Page node. This would yield the CPU usage of
109the entire Page (content::WebContents).
110
111## Policies & Mechanisms
112
113The intent is for all Resource Management Policies to use the graph and the data
114therein to make policy decisions. The decisions are then implemented by invoking
115some kind of Resource Management Mechanism. Making this a clean distinction
116makes the implementation easier, more readable and more testable.
117
118A simple example of a policy and a mechanism might be a policy for flushing some
119kind of a cache after all frames in a process have been backgrounded or idle for
120a set amount of time. This policy would register for the appropriate
121notifications and likely maintain private state on a process node. When the
122criteria for flushing is met, the policy invokes the mechanism by rendezvousing
123to a process-associated mojo interface and invoking on it.
124
125If the mojo interface is accessible through a content entity (e.g.
126content::WebContents), the mechanism invocation is posted to the main thread
127where the relevant content proxy (e.g. performance_manager::WebContentsProxy)
128makes it easy and safe to retrieve the content entity on the main thread.
129Should the corresponding content entity have been deleted after the task was
130posted, the content proxy will simply return nullptr.