You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Tensorflow CPU Inference API For Windows and Linux with docker swarm
2
+
Please use **docker swarm** only if you need to:
3
+
4
+
* Provide redundancy in terms of API containers: In case a container went down, the incoming requests will be redirected to another running instance.
5
+
6
+
* Coordinate between the containers: Swarm will orchestrate between the APIs and choose one of them to listen to the incoming request.
7
+
8
+
* Scale up the Inference service in order to get a faster prediction especially if there's traffic on the service.
9
+
10
+
## Run the docker container
11
+
12
+
Docker swarm can scale up the API into multiple replicas and can be used on one or multiple hosts(Linux users only). In both cases, a docker swarm setup is required for all hosts.
13
+
14
+
#### Docker swarm setup
15
+
16
+
1- Initialize Swarm:
17
+
18
+
```sh
19
+
docker swarm init
20
+
```
21
+
22
+
2- On the manager host, open the cpu-inference.yaml file and specify the number of replicas needed. In case you are using multiple hosts (With multiple hosts section), the number of replicas will be divided across all hosts.
23
+
24
+
```yaml
25
+
version: "3"
26
+
27
+
services:
28
+
api:
29
+
ports:
30
+
- "4343:4343"
31
+
image: tensorflow_inference_api_cpu
32
+
volumes:
33
+
- "/mnt/models:/models"
34
+
deploy:
35
+
replicas: 1
36
+
update_config:
37
+
parallelism: 2
38
+
delay: 10s
39
+
restart_policy:
40
+
condition: on-failure
41
+
```
42
+
43
+
**Notes about cpu-inference.yaml:**
44
+
45
+
* the volumes field on the left of ":" should be an absolute path, can be changeable by the user, and represents the models directory on your Operating System
46
+
* the following volume's field ":/models" should never be changed
1- In order to scale up the service to 4 replicas for example use this command:
81
+
82
+
```sh
83
+
docker service scale tensorflow-cpu_api=4
84
+
```
85
+
86
+
2- To check the available workers:
87
+
88
+
```sh
89
+
docker node ls
90
+
```
91
+
92
+
3- To check on which node the container is running:
93
+
94
+
```sh
95
+
docker service ps tensorflow-cpu_api
96
+
```
97
+
98
+
4- To check the number of replicas:
99
+
100
+
```sh
101
+
docker service ls
102
+
```
103
+
104
+
## Benchmarking
105
+
106
+
Here are two graphs showing time of prediction for different number of requests at the same time.
107
+
108
+
109
+

110
+
111
+
112
+

113
+
114
+
115
+
We can see that both graphs got the same result no matter what is the number of received requests at the same time. When we increase the number of workers (hosts) we are able to speed up the inference by at least 2 times. For example we can see in the last column we were able to process 40 requests in:
116
+
117
+
- 17.5 seconds with 20 replicas in 1 machine
118
+
- 8.8 seconds with 20 replicas in each of the 2 machines
119
+
120
+
Moreover, in case one of the machines is down the others are always ready to receive requests.
121
+
122
+
Finally since we are predicting on CPU scaling more replicas doesn't mean a faster prediction, 4 containers was faster than 20.
As mentioned before, this container can be deployed using either **docker** or **docker swarm**.
72
+
73
+
If you wish to deploy this API using **docker**, please issue the following run command.
74
+
75
+
If you wish to deploy this API using **docker swarm**, please refer to following link [docker swarm documentation](https://github.com/BMW-InnovationLab/BMW-TensorFlow-Inference-API-GPU/blob/dev-swarm/README-docker_swarm.md). After deploying the API with docker swarm, please consider returning to this documentation for further information about the API endpoints as well as the model structure sections.
94
76
95
77
To run the API, go the to the API's directory and run the following:
96
78
@@ -110,104 +92,6 @@ The <docker_host_port> can be any unique port of your choice.
110
92
111
93
The API file will be run automatically, and the service will listen to http requests on the chosen port.
112
94
113
-
114
-
115
-
In case you are deploying your API without **docker swarm**, please skip the next section and directly proceed to *API endpoints section*.
116
-
117
-
### Docker swarm
118
-
119
-
Docker swarm can scale up the API into multiple replicas and can be used on one or multiple hosts(Linux users only). In both cases, a docker swarm setup is required for all hosts.
120
-
121
-
#### Docker swarm setup
122
-
123
-
1- Initialize Swarm:
124
-
125
-
```sh
126
-
docker swarm init
127
-
```
128
-
129
-
2- On the manager host, open the cpu-inference.yaml file and specify the number of replicas needed. In case you are using multiple hosts (With multiple hosts section), the number of replicas will be divided across all hosts.
130
-
131
-
```yaml
132
-
version: "3"
133
-
134
-
services:
135
-
api:
136
-
ports:
137
-
- "4343:4343"
138
-
image: tensorflow_inference_api_cpu
139
-
volumes:
140
-
- "/mnt/models:/models"
141
-
deploy:
142
-
replicas: 1
143
-
update_config:
144
-
parallelism: 2
145
-
delay: 10s
146
-
restart_policy:
147
-
condition: on-failure
148
-
```
149
-
150
-
**Notes about cpu-inference.yaml:**
151
-
152
-
* the volumes field on the left of ":" should be an absolute path, can be changeable by the user, and represents the models directory on your Operating System
153
-
* the following volume's field ":/models" should never be changed
1- In order to scale up the service to 4 replicas for example use this command:
188
-
189
-
```sh
190
-
docker service scale tensorflow-cpu_api=4
191
-
```
192
-
193
-
2- To check the available workers:
194
-
195
-
```sh
196
-
docker node ls
197
-
```
198
-
199
-
3- To check on which node the container is running:
200
-
201
-
```sh
202
-
docker service ps tensorflow-cpu_api
203
-
```
204
-
205
-
4- To check the number of replicas:
206
-
207
-
```sh
208
-
docker service ls
209
-
```
210
-
211
95
## API Endpoints
212
96
213
97
To see all available endpoints, open your favorite browser and navigate to:
@@ -301,8 +185,6 @@ Inside each subfolder there should be a:
301
185
302
186
## Benchmarking
303
187
304
-
### Docker
305
-
306
188
<table>
307
189
<thead align="center">
308
190
<tr>
@@ -365,27 +247,6 @@ Inside each subfolder there should be a:
365
247
</tr>
366
248
</tbody>
367
249
</table>
368
-
369
-
### Docker swarm
370
-
371
-
Here are two graphs showing time of prediction for different number of requests at the same time.
372
-
373
-
374
-

375
-
376
-
377
-

378
-
379
-
380
-
We can see that both graphs got the same result no matter what is the number of received requests at the same time. When we increase the number of workers (hosts) we are able to speed up the inference by at least 2 times. For example we can see in the last column we were able to process 40 requests in:
381
-
382
-
- 17.5 seconds with 20 replicas in 1 machine
383
-
- 8.8 seconds with 20 replicas in each of the 2 machines
384
-
385
-
Moreover, in case one of the machines is down the others are always ready to receive requests.
386
-
387
-
Finally since we are predicting on CPU scaling more replicas doesn't mean a faster prediction, 4 containers was faster than 20.
0 commit comments