Skip to content

Commit 9f5d4c1

Browse files
Update architecture.zh-cn.md
1 parent 845ea50 commit 9f5d4c1

File tree

1 file changed

+85
-139
lines changed

1 file changed

+85
-139
lines changed

website_and_docs/content/documentation/grid/architecture.zh-cn.md

Lines changed: 85 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -16,107 +16,68 @@ aliases: [
1616
</p>
1717
{{% /pageinfo %}}
1818

19-
The Grid is designed as a set of components that all fulfill a role in
20-
maintaining the Grid. It can seem quite complicated, but hopefully
21-
this document can help clear up any confusion.
19+
Grid 被设计为一组组件,这些组件共同维护 Grid。它可能看起来相当复杂,但希望本文档能帮助澄清任何疑问。
2220

2321
## The Key Components
2422

25-
The main components of the Grid are:
23+
Grid的主要组件是:
2624

2725
<dl>
28-
<dt>Event Bus
29-
<dd>Used for sending messages which may be received asynchronously
30-
between the other components.
31-
32-
<dt>New Session Queue
33-
<dd>Maintains a list of incoming sessions which have yet to be
34-
assigned to a Node by the Distributor.
35-
36-
<dt>Distributor
37-
<dd>Responsible for maintaining a model of the available locations in
38-
the Grid where a session may run (known as "slots") and taking any
39-
incoming <a
40-
href="https://w3c.github.io/webdriver/#new-session">new
41-
session</a> requests and assigning them to a slot.
42-
43-
<dt>Node
44-
<dd>Runs a <a
26+
<dt>事件总线
27+
<dd>用于在其他组件之间异步发送和接收消息。
28+
29+
<dt>新会话队列
30+
<dd>维护一个尚未分配给节点的传入会话列表。
31+
32+
<dt>分配器
33+
<dd>负责维护 Grid 中可用位置的模型(称为“槽”),并接收任何传入的新会话请求,将其分配给一个槽。
34+
35+
<dt>节点
36+
<dd>运行一个<a
4537
href="https://w3c.github.io/webdriver/#dfn-sessions">WebDriver
46-
session</a>. Each session is assigned to a slot, and each node has
47-
one or more slots.
38+
session</a> 会话。每个会话分配给一个槽,每个节点有一个或多个槽。
4839

49-
<dt>Session Map
50-
<dd>Maintains a mapping between the <a
40+
<dt>会话映射
41+
<dd>维护会话ID <a
5142
href="https://w3c.github.io/webdriver/#dfn-session-id">session
52-
ID</a> and the address of the Node the session is running on.
43+
ID</a> 和运行会话的节点地址之间的映射。
5344

54-
<dt>Router
55-
<dd>Acts as the front-end of the Grid. This is the only part of the
56-
Grid which <i>may</i> be exposed to the wider Web (though we strongly
57-
caution against it). This routes incoming requests to either the
58-
New Session Queue or the Node on which the session is running.
45+
<dt>路由器
46+
<dd>作为 Grid 的前端。这是唯一可能暴露给外部 Web 的组件(尽管我们强烈建议不要这样做)。它将传入请求路由到新会话队列或运行会话的节点。
5947
</dl>
6048

61-
While discussing the Grid, there are some other useful concepts to
62-
keep in mind:
63-
64-
* A **slot** is the place where a session can run.
65-
* Each slot has a **stereotype**. This is the minimal set of
66-
capabilities that a [new session][] session request must match
67-
before the Distributor will send that request to the Node owning
68-
the slot.
69-
* The **Grid Model** is how the Distributor tracks the state of the
70-
Grid. As the name suggests, this may sometimes fall out of sync
71-
with reality (perhaps because the Distributor has only just
72-
started). It is used in preference to querying each Node so that
73-
the Distributor can quickly assign a slot to a New Session request.
74-
75-
## Synchronous and Asynchronous Calls
76-
77-
There are two main communication mechanisms used within the Grid:
78-
79-
1. Synchronous "REST-ish" JSON over HTTP requests.
80-
2. Asynchronous events sent to the Event Bus.
81-
82-
How do we pick which communication mechanism to use? After all, we
83-
could model the entire Grid in an event-based way, and it would work
84-
out just fine.
85-
86-
The answer is that if the action being performed is synchronous
87-
(eg. most WebDriver calls), or if missing the response would be
88-
problematic, the Grid uses a synchronous call. If, instead, we want to
89-
broadcast information to anyone who's interested, or if missing the
90-
response doesn't matter, then we prefer to use the event bus.
91-
92-
One interesting thing to note is that the async calls are more
93-
decoupled from their listeners than the synchronous calls are.
94-
95-
## Start Up Sequence and Dependencies Between Components
96-
97-
Although the Grid is designed to allow components to start up in any
98-
order, conceptually the order in which components starts is:
99-
100-
1. The Event Bus and Session Map start first. These have no other
101-
dependencies, not even on each other, and so are safe to start in
102-
parallel.
103-
2. The Session Queue starts next.
104-
3. It is now possible to start the Distributor. This will periodically
105-
connect to the Session Queue and poll for jobs, though this polling
106-
might be initiated either by an event (that a New Session has been
107-
added to the queue) or at regular intervals.
108-
4. The Router(s) can be started. New Session requests will be directed
109-
to the Session Queue, and the Distributor will attempt to find a
110-
slot to run the session on.
111-
5. We are now able to start a Node. See below for details about how
112-
the Node is registered with the Grid. Once registration is
113-
complete, the Grid is ready to serve traffic.
114-
115-
You can picture the dependencies between components this way, where a
116-
"✅" indicates that there is a synchronous dependency between the
117-
components.
118-
119-
| | Event Bus | Distributor | Node | Router | Session Map | Session Queue |
49+
在讨论 Grid 时,还需要记住一些其他有用的概念:
50+
51+
* 槽(slot)是会话可以运行的地方。
52+
* 每个槽有一个能力集(stereotype)。这是一个最小能力集,传入的会话请求必须匹配,然后分配器才会将请求发送到拥有该槽的节点。
53+
* 分配器跟踪 Grid 的状态。顾名思义,有时可能会因为现实(也许分配器刚刚启动)而出现同步问题。如果优先查询每个节点,以便分配器可以快速为新会话请求分配槽。
54+
55+
## 同步和异步调用
56+
57+
Grid 中使用了两种主要的通信机制:
58+
59+
1. 通过 HTTP 请求的同步“REST-ish” JSON。
60+
2. 发送到事件总线的异步事件。
61+
62+
我们如何选择同步机制(例如,大多数 WebDriver 调用)或异步机制?之后,我们可以将整个 Grid 建模为事件驱动的,它将正常工作。
63+
64+
答案是,如果响应丢失将是问题,我们希望将信息广播给任何感兴趣的人,或者我们不在乎响应,我们更喜欢使用事件总线。
65+
66+
一个有趣的现象是,同步调用比异步调用更解耦。
67+
68+
## 组件间的启动顺序和依赖关系
69+
70+
尽管 Grid 设计为允许组件以任何顺序启动,但组件启动的顺序如下:
71+
72+
1. 事件总线和会话映射首先启动。这些没有其他依赖项,甚至彼此之间也没有,因此可以安全地并行启动。
73+
2. 接下来启动新会话队列。
74+
3. 现在可以启动分配器。这将定期连接到新会话队列并轮询作业,尽管这种轮询可以是初始化的(即查询)或定期的。
75+
4. 路由器可以启动。新会话请求将被定向到新会话队列,分配器将尝试找到一个槽来运行会话。
76+
5. 我们现在可以启动节点。请参阅下面的详细信息,了解节点如何与 Grid 注册。注册完成后,Grid 准备提供服务。
77+
78+
您可以这样想象组件之间的依赖关系,其中 √ 表示组件之间存在同步依赖关系。
79+
80+
| | 事件总线| 分配器 | 节点 | 路由器 | 会话映射 | 会话队列 |
12081
|---------------|-----------|-------------|------|--------|-------------|---------------|
12182
| Event Bus | X | | | | | |
12283
| Distributor || X || | ||
@@ -125,66 +86,51 @@ components.
12586
| Session Map | | | | | X | |
12687
| Session Queue || | | | | X |
12788

128-
## Node Registration
89+
## 节点注册
12990

130-
The process of registering a new Node to the Grid is lightweight.
91+
向 Grid 注册新节点的过程是轻量级的。
92+
1. 当节点启动时,它应该定期发送“心跳”事件。这个心跳包含节点状态。
93+
2. 分配器监听心跳事件。当它看到时,它尝试获取节点的 /status 端点。这是 Grid 设置的信息。
94+
分配器将使用相同的 /status 端点定期检查节点,但节点应该在启动后继续发送心跳事件,以便在没有持久存储 Grid 状态的情况下,分配器可以重启并(最终)更新和正确。
13195

132-
1. When the Node starts, it should emit a "heart beat" event on a
133-
regular basis. This heartbeat contains the [node status].
134-
2. The Distributor listens for the heart beat events. When it sees
135-
one, it attempts to `GET` the `/status` endpoint of the Node. It
136-
is from this information that the Grid is set up.
96+
### 节点状态对象
13797

138-
The Distributor will use the same `/status` endpoint to check the Node
139-
on a regular basis, but the Node should continue sending heart beat
140-
events even after started so that a Distributor without a persistent
141-
store of the Grid state can be restarted and will (eventually) be up
142-
to date and correct.
98+
节点状态是一个 JSON blob,具有以下字段:
14399

144-
### The Node Status Object
100+
| 名称 | 类型 | 描述 |
101+
|------|------|-------------|
102+
| availability | string | 一个字符串,可以是 up、draining 或 down。重要的是 draining,它表示不应再向节点发送新会话,一旦最后一个会话关闭,节点将退出或重启。|
103+
| externalUrl | string | 网格的其他组件应该连接的 URL。 |
104+
| lastSessionCreated | integer | 最后一次会话创建的纪元时间戳。分配器将尝试将新会话发送到具有最长空闲时间的节点(如果所有其他条件都相等)。 |
105+
| maxSessionCount | integer | 尽管可以通过计算可用槽的数量来推断会话计数,但这个整数值用于确定在节点上同时运行的最大会话数,然后才被认为是“满”。 |
106+
| nodeId | string | 用于标识此节点实例的 UUID。 |
107+
| osInfo | object | 具有 arch、name 和 version 字段的对象。这用于 Grid UI 和 GraphQL 查询。 |
108+
| slots | array | 槽对象数组(下面描述)。|
109+
| version | string | 节点的版本(对于 Selenium,这将与 Selenium 版本号匹配) |
145110

146-
The Node Status is a JSON blob with the following fields:
111+
建议在所有字段中填写值。
147112

148-
| Name | Type | Description |
149-
|------|------|-------------|
150-
| availability | string | A string which is one of `up`, `draining`, or `down`. The important one is `draining`, which indicates that no new sessions should be sent to the Node, and once the last session on it closes, the Node will exit or restart. |
151-
| externalUrl | string | The URI that the other components in the Grid should connect to. |
152-
| lastSessionCreated | integer | The epoch timestamp of when the last session was created on this Node. The Distributor will attempt to send new sessions to the Node that has been idle longest if all other things are equal. |
153-
| maxSessionCount | integer | Although a session count can be inferred by counting the number of available slots, this integer value is used to determine the maximum number of sessions that should be running simultaneously on the Node before it is considered "full". |
154-
| nodeId | string | A UUID used to identify this instance of the Node. |
155-
| osInfo | object | An object with `arch`, `name`, and `version` fields. This is used by the Grid UI and the GraphQL queries. |
156-
| slots | array | An array of Slot objects (described below) |
157-
| version | string | The version of the Node (for Selenium, this will match the Selenium version number) |
158-
159-
It is recommended to put values in all fields.
160-
161-
### The Slot Object
162-
163-
The Slot object represents a single slot within a Node. A "slot" is
164-
where a single session may be run. It is possible that a Node will
165-
have more slots than it can run concurrently. For example, a node may
166-
be able to run up 10 sessions, but they could be any combination of
167-
Chrome, Edge, or Firefox; in this case, the Node would indicate a "max
168-
session count" of 10, and then also say it has 10 slots for Chrome, 10
169-
for Edge, and 10 for Firefox.
170-
171-
| Name | Type | Description |
113+
### 槽对象
114+
115+
槽对象表示节点内的单个槽。“槽”是可以在节点上运行的单个会话的地方。一个节点可能有比它可以同时运行的更多槽。例如,一个节点可能能够运行多达 10 个会话,但它们可能是 Chrome、Edge 或 Firefox 的任何组合。在这种情况下,节点将指示“最大会话数为 10”,然后还说它有 10 个 Chrome 槽,10 个 Edge 槽和 10 个 Firefox 槽。
116+
117+
| 名称 | 类型 | 描述 |
172118
|------|------|-------------|
173-
| id | string | UUID to refer to the slot |
174-
| lastStarted | string | When the slot last had a session started, in ISO-8601 format |
175-
| stereotype | object | The minimal set of [capabilities][capabilities] this slot will match against. A minimal example is `{"browserName": "firefox"}` |
176-
| session | object | The Session object (see below) |
119+
| id | string | UUID 和槽进行匹配 |
120+
| lastStarted | string | 当槽上次启动会话时,在 ISO-8601 格式。 |
121+
| stereotype | object | 此槽将匹配的最小能力集。一个最小示例是 {"browserName": "firefox"}|
122+
| session | object | 会话对象(见下文) |
177123

178-
### The Session Object
124+
### 会话对象
179125

180-
This represents a running session within a slot
126+
这表示槽中的运行会话。
181127

182-
| Name | Type | Description |
128+
| 名称 | 类型 | 描述 |
183129
|------|------|-------------|
184-
| capabilities | object | The actual capabilities provided by the session. Will match the return value from the [new session][new session] command |
185-
| startTime | string | The start time of the session in ISO-8601 format |
186-
| stereotype | object | The minimal set of [capabilities][capabilities] this slot will match against. A minimal example is `{"browserName": "firefox"}` |
187-
| uri | string | The URI used by the Node to communicate with the session |
130+
| capabilities | object | 会话提供的实际功能。将与 new session 命令的返回值匹配。 |
131+
| startTime | string |会话的开始时间,ISO-8601 格式。 |
132+
| stereotype | object | 此槽将匹配的最小能力集。一个最小示例是 {"browserName": "firefox"} |
133+
| uri | string | 节点用于与会话通信的 URI |
188134

189135
[capabilities]: https://w3c.github.io/webdriver/#dfn-merging-capabilities
190136
[new session]: https://w3c.github.io/webdriver/#new-session

0 commit comments

Comments
 (0)