README_CN.md 9.9 KB
Newer Older
K
KernelMaker 已提交
1
# Pika
S
SongZhao 已提交
2

S
SongZhao 已提交
3
## 简介 [English](https://github.com/Qihoo360/pika/blob/master/README.md)
F
fancyrabbit 已提交
4
Pika是一个可持久化的大容量redis存储服务,兼容string、hash、list、zset、set的绝大部分接口([兼容详情](https://github.com/Qihoo360/pika/wiki/pika-支持的redis接口及兼容情况)),解决redis由于存储数据量巨大而导致内存不够用的容量瓶颈,并且可以像redis一样,通过slaveof命令进行主从备份,支持全同步和部分同步,pika还可以用在twemproxy或者codis中来实现静态数据分片(pika已经可以支持codis的动态迁移slot功能,目前在合并到master分支,欢迎使用,感谢作者[left2right](https://github.com/left2right)同学提交pr)
L
Leviathan 已提交
5 6

## Pika用户
S
SongZhao 已提交
7

G
Gao Dunqiao 已提交
8 9 10
<table>
<tr>
<td height = "100" width = "150"><img src="http://i.imgur.com/dcHpCm4.png" alt="Qihoo"></td>
L
Leviathan 已提交
11
<td height = "100" width = "150"><img src="http://i.imgur.com/ktPV3JU.jpg?2" alt="360game"></td>
G
Gao Dunqiao 已提交
12 13 14 15
<td height = "100" width = "150"><img src="http://i.imgur.com/jjZczkN.png" alt="Weibo"></td>
<td height = "100" width = "150"><img src="http://i.imgur.com/zoel46r.gif" alt="Garena"></td>
</tr>
<tr>
L
Leviathan 已提交
16
<td height = "100" width = "150"><img src="http://i.imgur.com/kHqACbn.png" alt="Apus"></td>
G
Gao Dunqiao 已提交
17 18 19 20 21
<td height = "100" width = "150"><img src="http://i.imgur.com/2c57z8U.png" alt="Ffan"></td>
<td height = "100" width = "150"><img src="http://i.imgur.com/rUiO5VU.png" alt="Meituan"></td>
<td height = "100" width = "150"><img src="http://i.imgur.com/px5mEuW.png" alt="XES"></td>
</tr>
<tr>
L
Leviathan 已提交
22
<td height = "100" width = "150"><img src="http://imgur.com/yJe4FP8.png" alt="HX"></td>
G
Gao Dunqiao 已提交
23 24
<td height = "100" width = "150"><img src="http://i.imgur.com/o8ZDXCH.png" alt="XL"></td>
<td height = "100" width = "150"><img src="http://imgur.com/w3qNQ9T.png" alt="GWD"></td>
K
KernelMaker 已提交
25
<td height = "100" width = "150"><img src="https://imgur.com/KMVr3Z6.png" alt="DYD"></td>
G
Gao Dunqiao 已提交
26 27
</tr>
<tr>
L
Leviathan 已提交
28
<td height = "100" width = "150"><img src="http://i.imgur.com/vJbAfri.png" alt="YM"></td>
G
Gao Dunqiao 已提交
29 30
<td height = "100" width = "150"><img src="http://i.imgur.com/aNxzwsY.png" alt="XM"></td>
<td height = "100" width = "150"><img src="http://i.imgur.com/mrWxwkF.png" alt="XL"></td>
S
SongZhao 已提交
31 32
<td height = "100" width = "150"><img src="http://imgur.com/0oaVKlk.png" alt="YM"></td>
</tr>
K
KernelMaker 已提交
33 34
<tr>
<td height = "100" width = "150"><img src="https://imgur.com/qN6z25x.png" alt="MM"></td>
K
KernelMaker 已提交
35
<td height = "100" width = "150"><img src="https://i.imgur.com/G9MOvZe.jpg" alt="VIP"></td>
K
KernelMaker 已提交
36
<td height = "100" width = "150"><img src="https://imgur.com/vQW5qr3.png" alt="LK"></td>
K
KernelMaker 已提交
37
</tr>
G
Gao Dunqiao 已提交
38
</table>
S
SongZhao 已提交
39

S
SongZhao 已提交
40 41 42

[更多](https://github.com/Qihoo360/pika/blob/master/USERS.md)

K
KernelMaker 已提交
43 44 45 46
## 特点
* 容量大,支持百G数据量的存储
* 兼容redis,不用修改代码即可平滑从redis迁移到pika
* 支持主从(slaveof)
S
SongZhao 已提交
47
* 完善的[运维](https://github.com/Qihoo360/pika/wiki/pika的一些管理命令方式说明)命令
K
KernelMaker 已提交
48

B
baotiao 已提交
49

L
Leviathan 已提交
50 51 52 53 54 55 56
## 使用

### 二进制包使用

用户可以直接从[releases](https://github.com/Qihoo360/pika/releases)下载最新的二进制版本包直接使用.

### 编译使用
W
wuxiaofei-xy 已提交
57

K
v2.2.6  
KernelMaker 已提交
58
1.在编译机上安装snappy,glog,CentOS系统可以用yum安装,Ubuntu可以用apt-get安装。如是CentOS系统,执行如下命令:
W
wuxiaofei-xy 已提交
59 60

```
K
v2.2.6  
KernelMaker 已提交
61
    yum install snappy-devel glog-devel
W
wuxiaofei-xy 已提交
62 63 64 65
```

2.安装g++(若没有安装), 在CentOS上执行如下命令:

K
KernelMaker 已提交
66
```
W
wuxiaofei-xy 已提交
67
    yum install gcc-c++
K
KernelMaker 已提交
68 69
```

S
SongZhao 已提交
70
3.把gcc版本临时切换到4.8(若已是,则忽略), 在CentOs上执行如下命令:
W
wuxiaofei-xy 已提交
71 72

```
S
SongZhao 已提交
73 74 75
	a. sudo wget http://people.centos.org/tru/devtools-2/devtools-2.repo -O /etc/yum.repos.d/devtools-2.repo
	b. sudo yum install -y devtoolset-2-gcc devtoolset-2-binutils devtoolset-2-gcc-c++
	c. scl enable devtoolset-2 bash
W
wuxiaofei-xy 已提交
76 77 78 79
```
4.获取源代码

```
G
Gao Dunqiao 已提交
80
	git clone https://github.com/Qihoo360/pika.git && cd pika
W
wuxiaofei-xy 已提交
81
```
S
SongZhao 已提交
82
5.切换到最新release版本
W
wuxiaofei-xy 已提交
83

S
SongZhao 已提交
84
```
S
SongZhao 已提交
85 86
	a. 执行 git tag 查看最新的release tag,(如 v2.2.5)
	b. 执行 git checkout TAG切换到最新版本,(如 git checkout v2.2.5)
S
SongZhao 已提交
87 88 89
```

6.编译
W
wuxiaofei-xy 已提交
90 91

```
K
KernelMaker 已提交
92
	make
W
wuxiaofei-xy 已提交
93
```
K
KernelMaker 已提交
94

W
wuxiaofei-xy 已提交
95 96
若编译过程中,提示有依赖的库没有安装,则有提示安装后再重新编译

S
SongZhao 已提交
97 98
**注:我们推荐使用TCMalloc来进行内存管理**

K
KernelMaker 已提交
99 100
## 使用
```
J
JacketWoo 已提交
101
	./output/bin/pika -c ./conf/pika.conf
K
KernelMaker 已提交
102
```
K
KernelMaker 已提交
103

S
SongZhao 已提交
104
## 清空编译
W
wuxiaofei-xy 已提交
105 106

```
K
KernelMaker 已提交
107
  如果需要清空编译内容,视不同情况使用一下两种方法其一:
K
KernelMaker 已提交
108

K
KernelMaker 已提交
109 110 111
  1. 执行make clean来清空pika的编译内容
  2. 执行make distclean来清空pika及所有依赖的编译内容(一般用于彻底重新编译)
```
Z
zhaoanan 已提交
112

S
SongZhao 已提交
113
## 性能 (感谢[deep011](https://github.com/deep011)提供性能测试结果)
S
SongZhao 已提交
114 115 116 117
### 注!!!
本测试结果是在特定环境特定场景下得出的,不能够代表所有环境及场景下的表现,__仅供参考__。

__推荐大家在使用pika前在自己的环境根据自己的使用场景详细测试以评估pika是否满足要求__
S
SongZhao 已提交
118

119
### 测试环境
S
SongZhao 已提交
120

121
**CPU型号**:Intel(R) Xeon(R) CPU E5-2690 v4 @ 2.60GHz
S
SongZhao 已提交
122

123 124 125 126 127 128
**CPU线程数**:56

**MEMORY**:256G

**DISK**:3T flash

F
fancyrabbit 已提交
129
**NETWORK**:10GBase-T/Full * 2
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145

**OS**:centos 6.6

**Pika版本**:2.2.4

### 压测工具

[**vire-benchmark**](https://deep011.github.io/vire-benchmark)

### 测试一

#### 测试目的

测试在pika不同worker线程数量下,其QPS上限。

#### 测试条件
S
SongZhao 已提交
146

147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
pika数据容量:800G

value:128字节

CPU未绑定

#### 测试结果

说明:横轴Pika线程数,纵轴QPS,value为128字节。set3/get7代表30%的set和70%的get。

<img src="https://deep011.github.io/public/images/pika_benchmark/pika_threads_test.png" height = "60%" width = "60%" alt="1"/>

#### 结论

从以上测试图可以看出,pika的worker线程数设置为20-24比较划算。

### 测试二

#### 测试目的

F
fancyrabbit 已提交
167
测试在最佳worker线程数(20线程)下,pika的rtt表现。
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190

#### 测试条件

**pika数据容量**:800G

**value**:128字节

#### 测试结果

```c
====== GET ======
  10000000 requests completed in 23.10 seconds
  200 parallel clients
  3 bytes payload
  keep alive: 1
99.89% <= 1 milliseconds
100.00% <= 2 milliseconds
100.00% <= 3 milliseconds
100.00% <= 5 milliseconds
100.00% <= 6 milliseconds
100.00% <= 7 milliseconds
100.00% <= 7 milliseconds
432862.97 requests per second
S
SongZhao 已提交
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
```c
====== SET ======
  10000000 requests completed in 36.15 seconds
  200 parallel clients
  3 bytes payload
  keep alive: 1
91.97% <= 1 milliseconds
99.98% <= 2 milliseconds
99.98% <= 3 milliseconds
99.98% <= 4 milliseconds
99.98% <= 5 milliseconds
99.98% <= 6 milliseconds
99.98% <= 7 milliseconds
99.98% <= 9 milliseconds
99.98% <= 10 milliseconds
99.98% <= 11 milliseconds
99.98% <= 12 milliseconds
99.98% <= 13 milliseconds
99.98% <= 16 milliseconds
99.98% <= 18 milliseconds
99.99% <= 19 milliseconds
99.99% <= 23 milliseconds
99.99% <= 24 milliseconds
99.99% <= 25 milliseconds
99.99% <= 27 milliseconds
99.99% <= 28 milliseconds
99.99% <= 34 milliseconds
99.99% <= 37 milliseconds
99.99% <= 39 milliseconds
99.99% <= 40 milliseconds
99.99% <= 46 milliseconds
99.99% <= 48 milliseconds
99.99% <= 49 milliseconds
99.99% <= 50 milliseconds
99.99% <= 51 milliseconds
99.99% <= 52 milliseconds
99.99% <= 61 milliseconds
99.99% <= 63 milliseconds
99.99% <= 72 milliseconds
99.99% <= 73 milliseconds
99.99% <= 74 milliseconds
99.99% <= 76 milliseconds
99.99% <= 83 milliseconds
99.99% <= 84 milliseconds
99.99% <= 88 milliseconds
99.99% <= 89 milliseconds
99.99% <= 133 milliseconds
99.99% <= 134 milliseconds
99.99% <= 146 milliseconds
99.99% <= 147 milliseconds
100.00% <= 203 milliseconds
100.00% <= 204 milliseconds
100.00% <= 208 milliseconds
100.00% <= 217 milliseconds
100.00% <= 218 milliseconds
100.00% <= 219 milliseconds
100.00% <= 220 milliseconds
100.00% <= 229 milliseconds
100.00% <= 229 milliseconds
276617.50 requests per second
S
SongZhao 已提交
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 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
#### 结论

get/set 响应时间 99.9%都在2ms以内。

### 测试三

#### 测试目的

在pika最佳的worker线程数下,查看各命令的极限QPS。

#### 测试条件

**pika的worker线程数**:20

**key数量**:10000

**field数量**:100(list除外)

**value**:128字节

**命令执行次数**:1000万(lrange除外)

#### 测试结果

```c
PING_INLINE: 548606.50 requests per second
PING_BULK: 544573.31 requests per second
SET: 231830.31 requests per second
GET: 512163.91 requests per second
INCR: 230861.56 requests per second
MSET (10 keys): 94991.12 requests per second
LPUSH: 196093.81 requests per second
RPUSH: 195186.69 requests per second
LPOP: 131156.14 requests per second
RPOP: 152292.77 requests per second
LPUSH (needed to benchmark LRANGE): 196734.20 requests per second
LRANGE_10 (first 10 elements): 334448.16 requests per second
LRANGE_100 (first 100 elements): 50705.12 requests per second
LRANGE_300 (first 300 elements): 16745.16 requests per second
LRANGE_450 (first 450 elements): 6787.94 requests per second
LRANGE_600 (first 600 elements): 3170.38 requests per second
SADD: 160885.52 requests per second
SPOP: 128920.80 requests per second
HSET: 180209.41 requests per second
HINCRBY: 153364.81 requests per second
HINCRBYFLOAT: 141095.47 requests per second
HGET: 506791.00 requests per second
HMSET (10 fields): 27777.31 requests per second
HMGET (10 fields): 38998.52 requests per second
HGETALL: 109059.58 requests per second
ZADD: 120583.62 requests per second
ZREM: 161689.33 requests per second
PFADD: 6153.47 requests per second
PFCOUNT: 28312.57 requests per second
PFADD (needed to benchmark PFMERGE): 6166.37 requests per second
PFMERGE: 6007.09 requests per second
S
SongZhao 已提交
311 312
```

313 314 315 316
#### 结论

整体表现很不错,个别命令表现较弱(LRANGE,PFADD,PFMERGE)。

317
### 测试四
S
SongZhao 已提交
318

319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
#### 测试目的

Pika与Redis的极限QPS对比。

#### 测试条件

**pika的worker线程数**:20

**key数量**:10000

**field数量**:100(list除外)

**value**:128字节

**命令执行次数**:1000万(lrange除外)

**Redis版本**:3.2.0

#### 测试结果

<img src="https://deep011.github.io/public/images/pika_benchmark/pika_vs_redis_qps.png" height = "60%" width = "60%" alt="1"/>

K
KernelMaker 已提交
341
## 文档
S
SongZhao 已提交
342
1. [Wiki] (https://github.com/Qihoo360/pika/wiki)
K
KernelMaker 已提交
343 344

## 联系方式
Z
Zongzhi Chen 已提交
345
邮箱:g-infra-bada@360.cn
S
SongZhao 已提交
346 347

QQ群:294254078