一、参考内容
二、OpenFaas的架构设计及function的调用路径
架构中使用的组件及工作流程简图
架构中的组件功能流程
function的调用路径
调用路径三、扩缩容试验
部署成功的Function是具有扩缩容能力的。比如我们使用ab命令去压测昨天部署的Function。
- 压测之前,先观察pod的情况
$ kubectl -n openfaas-fn get pod
NAME READY STATUS RESTARTS AGE
env-6c79f7b946-4pg5t 1/1 Running 0 14h
helloworld-555784464d-ztvrc 1/1 Running 0 14h
- 执行压测命令,再观察pod的情况
$ ab -c 10 -n 10000 -k http://193.169.0.90:31112/function/helloworld
This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 193.169.0.90 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests
Server Software:
Server Hostname: 193.169.0.90
Server Port: 31112
Document Path: /function/helloworld
Document Length: 41 bytes
Concurrency Level: 10
Time taken for tests: 3.231 seconds
Complete requests: 10000
Failed requests: 0
Keep-Alive requests: 10000
Total transferred: 3600000 bytes
HTML transferred: 410000 bytes
Requests per second: 3095.47 [#/sec] (mean) Time per request: 3.231 [ms] (mean)
Time per request: 0.323 [ms] (mean, across all concurrent requests)
Transfer rate: 1088.25 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 1
Processing: 2 3 0.8 3 12
Waiting: 2 3 0.8 3 12
Total: 2 3 0.9 3 12
Percentage of the requests served within a certain time (ms)
50% 3
66% 3
75% 3
80% 4
90% 4
95% 5
98% 6
99% 6
100% 12 (longest request)
- 再观察Pod的运行情况,可以看到先进行了扩容,又进行了缩容。并最后恢复到压测之前的状态。
$ kubectl -n openfaas-fn get pod
NAME READY STATUS RESTARTS AGE
env-6c79f7b946-4pg5t 1/1 Running 0 14h
helloworld-555784464d-28pt8 0/1 ContainerCreating 0 1s
helloworld-555784464d-78k2n 0/1 ContainerCreating 0 1s
helloworld-555784464d-cdc5c 0/1 ContainerCreating 0 1s
helloworld-555784464d-jnnpn 0/1 ContainerCreating 0 1s helloworld-555784464d-ztvrc 1/1 Running 0 14h
$ kubectl -n openfaas-fn get pod
NAME READY STATUS RESTARTS AGE env-6c79f7b946-4pg5t 1/1 Running 0 14h helloworld-555784464d-28pt8 1/1 Terminating 0 10s
helloworld-555784464d-78k2n 0/1 Terminating 0 10s
helloworld-555784464d-cdc5c 1/1 Terminating 0 10s
helloworld-555784464d-jnnpn 1/1 Terminating 0 10s
helloworld-555784464d-ztvrc 1/1 Running 0 14h
$ kubectl -n openfaas-fn get pod
NAME READY STATUS RESTARTS AGE
env-6c79f7b946-4pg5t 1/1 Running 0 14h
helloworld-555784464d-ztvrc 1/1 Running 0 14h
四、自定义参数使用Auto-Scaling,自动扩缩容
Function的扩缩容由Label来设置。
例如:
$ faas-cli deploy -f helloworld.yml \
--label com.openfaas.scale.max=10 \
--label com.openfaas.scale.target=5 \
--label com.openfaas.scale.type=capacity \
--label com.openfaas.scale.target-proportion=1.0 \
--label com.openfaas.scale.zero=true \
--label com.openfaas.scale.zero-duration=5m
Deploying: helloworld.
Deployed. 202 Accepted.
URL: http://127.0.0.1:31112/function/helloworld
$
Function的扩缩容由Label来设置,说明文档如下:
标签 | 含义 | 默认值 |
---|---|---|
com.openfaas.scale.max | 最多扩容到几个replicaset | 20 |
com.openfaas.scale.min | 最小缩容到几个replicaset | 1 |
com.openfaas.scale.zero | 是否允许缩容到0个,即关闭所有的replicaset | false |
com.openfaas.scale.zero-duration | 空闲多久之后,缩容为0 | 15m |
com.openfaas.scale.target | 当每个replicaset的压力达到多少时进行扩容 | 50 |
com.openfaas.scale.target-proportion | 扩容时的缩放系数,用来避免爆炸式扩容或扩容不足的发生。为一个浮点数 | 0.90 |
com.openfaas.scale.type | 扩缩容的模式,可选择rps、capacity、cpu | rps |
扩缩容有一个计算公式如下
扩缩容Replicaset个数 = 当前的replicaset个数 * (当前的压力 / ( (
com.openfaas.scale.target
* 当前的replicaset个数 ) *com.openfaas.scale.target-proportion
) )
当前的压力
: 当扩缩容的模式为capacity
时,可以理解为排队请求的个数,或者正在等待响应的请求个数。具体参考下面的内容。
扩缩容模式
一个关键的参数com.openfaas.scale.type
的三种类型也需要精心选择。
-
rps
每秒钟完成的请求个数(Requests Per Second),适用于快速响应的函数类型 -
capacity
排队的请求个数,或者正在等待响应的请求个数,适用于响应较慢的函数,调用量不大但是容易发生堵塞的调用。 -
cpu
根据CPU的负载进行扩缩容,适用于CPU消耗很高的函数,比如AI计算函数。
综上所述
OpenFaas的扩缩容功能还是比较简单明了的,而且参数也够灵活,值得一试。
网友评论