[TOC]
目的
实在受不鸟这些复杂的又充满bug的参数服务器,我就想要一个用jvm语言写的参数分布式缓存而已
调研Glint
简单,能看明白
PS就两个操作
1
2
3
4(1) Asynchronously ‘Pull’ data from the servers.
this will query parts of the matrix or vector.
(2) Asynchronously ‘Push’ data to the servers.
this will update parts of the matrix or vector.
简化到就两个操作,pull和push
PS的目的
ps的目的就是存放一个大型的分布式matrix,想那么多没用。
并且可以让用户快速query和update这个matrix
把参数想成个表,这里用redis也可以替代
这需要去切分matrix, 每个节点只存放matrix中的几行
算法只需要通过pull和push 来和这个matrix进行交互,不需要知道data的物理位置
Pull Action
Whenever an algorithm wants to retrieve entries from the matrix it will call the pull method. is method triggers an asynchronous pull request with a specific set of row and column indices that should be retrieved.
The request is split up into smaller requests based on the partitioning of the matrix such that there will be at most one request per parameter server.
这句话没看明白,怎么算是一个ps至多一个请求
源码解读
几个点
- 数据是用dense来表示的
先看组成
exceptions
iterators
messages
models
partitioning
serialization
utils
yarn
client
main
master
server
exceptions
三个exceptions model创建,pull push exceptions
iterators迭代器
先看基类
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
30PipelineIterator
abstract class PipelineIterator[T](duration: Duration = Duration.Inf)(implicit ec: ExecutionContext) extends Iterator[T] {
// 获取下一个,返回是一个Future
protected def fetchNextFuture(): Future[T]
protected var index: Int = 0
protected var total: Int = 0
private var nextFuture: Future[T] = fetchNextFuture()
// 当前index没有到total 就继续
override def hasNext: Boolean = index < total
// 下一个
override def next(): T = {
//Await and return the result
// duration 超时
val result = Await.result(nextFuture, duration)
index += 1
if (hasNext) {
nextFuture = fetchNextFuture()
}
result
}
}
三个集成
ColumnIterator
RowBlockIterator
RowIterator
消息messages
master
ClientList
RegisterClient
RegisterServer
ServerList
这些消息也很简答, 就是注册client server以及拿到list
servers
包含了logic, request ,response 主要是和ps交互的信息
Models模型在client和server端的操作
client
首先客户端这边包含两个trait, BigMatrix, BigVector
BigMatrix
-
rows: Long
-
Cols:Int
-
pull
-
push
-
destroy
-
save
BigVector
- size
- pull
- push
- destroy
- save
Client还有三个基于上述两个trait的实现
先看async
async
重点是async的matrix
partitioning
这个模块是重点中的重点,详细来看,参数如何分区的
主要包含了两个cyclic 和 range
cyclic的是 轮询, number of partitions就是ps的node数量
range是自定义划分
##serialization
使用了unsafe和bytebuffer来解析
core classes
下面来说四个核心类,Client, Main, Master, Server