-
Notifications
You must be signed in to change notification settings - Fork 2
/
upone.slide
288 lines (167 loc) · 6.46 KB
/
upone.slide
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
基于 mesos 的容器调度框架
Gopher 杭州 meetup
05 Aug 2017
黄励博(huangnauh)
又拍云
ihuangnauh@gmail.com
https://github.com/huangnauh
* What's Upone
.image upone/upone.png _ 1000
* Mesos 介绍
.image upone/mesos-logo.png _ 800
.caption Image credit: [[http://mesos.apache.org/][mesos.apache.org]]
官方称之为分布式系统内核, 它把数据中心的 CPU、内存、磁盘等抽象成一个资源池
* Mesos 调度
.image upone/scheduler.png _ 800
各个 Agent 启动后, 向 Master 注册,携带统计资源, 由 Master 决定给每个框架多少资源, 默认采用分级主导资源公平算法
每个框架收到资源后, 根据自身任务需求, 调度任务的资源分配
* upone
.image upone/marathon_chronos.png _ 800
为云处理服务定制的容器调度框架,支持长期服务和定时任务
* 处理流程
.image upone/mesos-seq-diagram.png _ 800
.caption Image credit: [[https://dcos.io/docs/1.7/overview/architecture/][dcos architecture]]
* 消息交互
upone 通过 [[/api/v1/scheduler][/api/v1/scheduler]] 和 mesos master 完成交互
.image upone/interface.png _ 600
* 订阅
通过 SUBSCRIBE 消息, 开启一个长链接来订阅事件 (Event), 常用事件类型:
.image upone/event.png _ 800
* OFFERS 事件处理
.image upone/offer.png _ 600
- ACCEPT 消息: 接受此 offer, 包括启动任务,预留资源等调度操作
- DECLINE 消息: 明确拒绝此 offer
- Filter : 可以设定资源的拒绝时间, 默认是 5s
- REVIVE 消息 : 取消之前设定 filter
* UPDATE 事件处理
.image upone/state.png _ 800
.caption Image generated by Mesos web interface
状态更新与 upone 的联动, 例如:
- Running 状态, upone 更新负载均衡
- Lost 状态, 任务迁移
* 其他消息
.image upone/message.png _ 800
* More Features
基于以上的 mesos http api, upone 可以实现一个具备基本功能的调度框架
那么除此之外, upone 还可以到哪些
* 特性
.image upone/feature.png _ 400
* 负载均衡
基于 *ngx_lua* 的动态负载均衡方案: *Slardar*
.image upone/slardar.png _ 1000
* 负载均衡
.image upone/balance.png _ 600
update slardar:
curl 127.0.0.1:1995/upstream/node-dev.example.com -d \
{"servers":[{"host":"10.0.5.108", "port": 1234}]}
* 零停机更新
通过允许两个不同版本的 *App* 同时运行来实现蓝绿更新
.image upone/update.png _ 600
* 健康检查
{
-- checkups heartbeat timer is alive.
"checkup_timer_alive": true,
-- last heartbeat time
"last_check_time": "2016-08-12 13:09:40",
-- status for node-dev cluster
"cls:node-dev": [
[
{
"server": "node-dev:10.0.5.108:1234",
"weight": 1,
"fail_timeout": 30,
"status": "ok",
"max_fails": 6
}
]
]
}
* 预处理
以频率限制为例, 可以在访问 app 前载入 limit 相关脚本完成处理
"modules": [
{
"time": "2017-08-04 13:09:40",
"version": "aed4a968ef14f8db732e3602c34dc37a",
"name": "modules.limit"
},
{
"time": "2017-08-04 13:09:40",
"version": "302f9bf40fcd3734cab120b97f18edf3",
"name": "script.limit"
}
]
* 命令行工具
.image upone/upone-cli.png _ 600
同时, 我们还提供命令行工具, 以便 App 所有者通过 upone 手动操作上述负载均衡和更新部署的相关功能
* 自定义策略
收到 mesos offer 后, 可以自定义策略来决定任务调度方案
- 随机调度
每次调度尽可能让同一应用的各个任务分布到不同机器
.image upone/random.png _ 450
* 自定义策略
- 根据机器和任务的属性进行调度
.image upone/attr.png _ 600
* 自定义策略
- 根据机器 weight/load 动态调度
.image upone/load.png _ 600
* 配置与服务发现
.image upone/consul.png _ 600
- upone 动态加载属性
- 注册服务
- 应用配置统一管理
* 高可用
通过 *Raft* 分布式一致性协议实现高可用
[[https://github.com/hashicorp/raft][hashicorp/raft]]
- 领导选举: 心跳机制来触发选举, term 充当逻辑时钟的作用
- 日志复制: 领导者把一条指令(能被复制状态机执行)附加到日志中,发起附加条目 RPC 请求给其他角色
- 强领导者:日志条目只从 leader 发送给其他的服务器
* raft 领导选举
.image upone/raft-leader.png
.caption Image credit: [[https://raft.github.io/raft.pdf][the Raft paper]]
* raft 日志复制
.image upone/raft-log.png _ 650
.caption Image credit: [[https://raft.github.io/raft.pdf][the Raft paper]]
* raft 可视化
.image upone/raft.gif
.caption Image generated by [[https://raft.github.io/raftscope/index.html][RaftScope]]
* upone 定时任务
[[https://github.com/mesos/chronos][mesos/chronos]] 很多遗留问题没有解决
不再维护:
- is:issue is:open 188
- Latest commit on 1 Mar
遇到的问题:
- cpu 利用率达到 100%
- 共享数据缺乏锁保护
* 定时任务特性
- 支持 upone 的上述特性(自定义调度等)
- 支持 linux 定时任务 crontab 的配置格式
.image upone/crontab.jpg _ 600
* 组件化
- store 组件, 已支持 [[https://github.com/hashicorp/raft-boltdb][hashicorp/raft-boltdb]], 数据库
- drive 组件, upone 可以选择 master-agent 模式, 不依赖于 mesos 独立使用
* 告警
各个应用可以在创建任务的时候指定自己的 slack channel
当任务出现异常时, 发送实时通知
.image upone/slack.png _ 700
* 告警
.image upone/alarm.png _ 700
* 遇到的问题
- 孤儿任务
mesos 上未注册的 framework 没有办法 teardown
只能等 failover_timeout, 或者再次注册同一 id, 主动删除
最近发现 failover_timeout 之后, mesos 上的孤儿任务依然保留着
- tcp_tw_recycle
在请求不能保证时间戳单调递增的情况下(比如 NAT) 会出现丢包
* References
- docs
[1] [[http://mesos.apache.org/documentation/latest/scheduler-http-api/][scheduler-http-api]]
[2] [[http://mesos.berkeley.edu/mesos_tech_report.pdf][mesos tech report]]
[3] [[https://raft.github.io/raft.pdf][the Raft paper]]
[4] [[https://raft.github.io/raftscope/index.html][RaftScope]]
- projects
[1] [[https://github.com/apache/mesos][apache/mesos]]
[2] [[https://github.com/upyun/slardar][upyun/slardar]]
[3] [[https://github.com/hashicorp/consul][hashicorp/consul]]
[4] [[https://github.com/hashicorp/raft][hashicorp/raft]]
[5] [[https://github.com/mesos/chronos][mesos/chronos]]
[6] [[https://github.com/mesosphere/marathon][mesosphere/marathon]]