CLUSTERING.md 3.6 KB
Newer Older
W
wangguibao 已提交
1
# 搭建预测服务集群
W
wangguibao 已提交
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

[客户端配置](CLIENT_CONFIGURE.md)中我们已经知道,通过在客户端SDK的配置文件predictors.prototxt适当配置,可以搭建多副本和多Variant的预测集群。以下以图像分类任务为例,在单机上模拟搭建单Variant的多副本、和多Variant的预测集群

## 1. 单Variant多副本的预测集群

### 1.1 在本机创建一个serving副本

首先复制一个sering目录

```shell
$ cd /path/to/paddle-serving/build/output/demo
$ cp -r serving/ serving_new/
$ cd serving_new/

```

在serving_new目录中,在conf/gflags.conf中增加如下一行,修改其启动端口为8011,这是为了让该副本监听不同端口

```shell
--port=8011
```

然后启动新副本

```shell
$ bin/serving&
```

### 1.2 修改client端配置,将新副本地址加入ip列表:

```shell
$ cd /path/to/paddle-serving/build/output/demo/client/image_classification
```

修改conf/predictors.prototxt ImageClassifyService部分如下所示

```JSON
predictors {
  name: "ximage"
  service_name: "baidu.paddle_serving.predictor.image_classification.ImageClassifyService"
  endpoint_router: "WeightedRandomRender"
  weighted_random_render_conf {
    variant_weight_list: "50"
  }
  variants {
    tag: "var1"
    naming_conf {
      cluster: "list://127.0.0.1:8010, 127.0.0.1:8011"  # 在这里增加一个新的副本地址
    }
  }
}
```

重启client端

```shell
$ bin/ximage&
```

查看2个serving副本目录下是否均有收到请求:

```shell
$ cd /path/to/paddle-serving/build/output/demo/serving
$ tail -f log/serving.INFO

$ cd /path/to/paddle-serving/build/output/demo/serving_new
$ tail -f log/serving.INFO
```

## 2. 多Variant

### 2.1 本机创建新的serving副本

步骤同1.1节,略过

### 2.2 修改client配置,增加一个Variant

```shell
$ cd /path/to/paddle-serving/build/output/demo/client/image_classification
```

修改conf/predictors.prototxt ImageClassifyService部分如下所示

```JSON
predictors {
  name: "ximage"
  service_name: "baidu.paddle_serving.predictor.image_classification.ImageClassifyService"
  endpoint_router: "WeightedRandomRender"
  weighted_random_render_conf {
    variant_weight_list: "50 | 50"      # 一共2个variant,代表模型的2个版本。这里的权重代表调度的流量比例关系
  }
  variants {
    tag: "var1"
    naming_conf {
      cluster: "list://127.0.0.1:8010"
    }
  }
  variants {                            # 增加一个variant
    tag: "var2"
    naming_conf {
      cluster: "list://127.0.0.1:8011"
    }
  }
}
```

重启client端

```shell
$ bin/ximage&
```

查看2个serving副本目录下是否均有收到请求:

```shell
$ cd /path/to/paddle-serving/build/output/demo/serving
$ tail -f log/serving.INFO

$ cd /path/to/paddle-serving/build/output/demo/serving_new
$ tail -f log/serving.INFO
```

查看client端是否有收到来自Variant1和Variant2的响应

```shell
$ cd /path/to/paddle-serving/build/output/demo/client/image_classification
$ tail -f log/ximage.INFO

```

以下是正常的输出

```
I0307 17:54:22.862087 24719 ximage.cpp:172] Debug string: 
I0307 17:54:22.862650 24719 ximage.cpp:110] sample-0's classify result: n02112018,博美犬, prop: 0.522815
I0307 17:54:22.862666 24719 ximage.cpp:114] Succ call predictor[ximage], the tag is: var1, elapse_ms: 333

I0307 17:54:23.194780 24719 ximage.cpp:172] Debug string: 
I0307 17:54:23.195322 24719 ximage.cpp:110] sample-0's classify result: n02112018,博美犬, prop: 0.522815
I0307 17:54:23.195334 24719 ximage.cpp:114] Succ call predictor[ximage], the tag is: var2, elapse_ms: 332
```