Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/jiangyu-docs' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
anycodes committed Nov 18, 2021
2 parents b1b841b + 77f6dc1 commit 6e92cea
Showing 1 changed file with 33 additions and 104 deletions.
137 changes: 33 additions & 104 deletions docs/command/eval.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# Eval 命令

`eval` 命令是对函数进行探测的命令;通过 `eval` 指令,可以对函数探测内存(单实例单并发)或者探测并发度(单实例多并发)。根据探测结果,可以有效的对内存等进行更为科学的配置。
`eval` 命令是对函数进行探测的命令;通过 `eval` 指令,可以对函数探测内存(单实例单并发)或者探测并发度(单实例多并发)。例如给CPU密集型场景的函数设置合适的内存,给I/O密集型场景的函数设置合适的并发值,根据探测结果,获取满足需求的最佳内存大小或最佳并发度值。

> 注意: 这个命令只是针对开发上线前阶段的函数, 不要对生产函数执行探测操作
- [命令解析](#命令解析)
- [eval start 命令](#eval-start-命令)
- [参数解析](#参数解析)
- [操作案例](#操作案例)
- [eval clean 命令](#eval-clean-命令)
- [参数解析](#参数解析-1)
- [操作案例](#操作案例-1)
- [权限与策略说明](#权限与策略说明)

> 关于 `eval` 命令的常见问题和解决方法,可以参考[ FC 组件自动问答系统](http://qa.devsapp.cn/ )
Expand All @@ -32,15 +31,13 @@ Document

SubCommand List

start Power tuning online functions; help command [s eval start -h]
clear Clean the relevant resources; help command [s eval clean -h]
start Power tuning online functions; help command [s eval start -h]
```


在该命令中,包括了两个子命令
在该命令中,包括了一个子命令

- [start:线上函数探测](#eval-start-命令)
- [clean:清理探测时创建的资源](#eval-clean-命令)

## eval start 命令

Expand Down Expand Up @@ -77,7 +74,7 @@ Options
Global Options

-h, --help [Optional] Help for command
-a, --access [string] [Optional] Specify key alias
-a, --access [string] [Optional] Specify key alias
--debug [Optional] Output debug informations

Options Help
Expand All @@ -90,130 +87,62 @@ Options Help

Examples with Yaml

$ s eval start --eval-type memory --run-count 10 --payload-file ./payload.file --memory-size 128,256,512,1024
$ s eval start --eval-type memory --run-count 50 --payload 'hello world' --memory-size 128,256,512,1024 --method get --path '/login' --query 'a=1&b=2'
$ s eval start --eval-type memory --run-count 10 --payload-file ./payload.file --memory-size 128,256,512,1024 $ s eval start --eval-type memory --run-count 50 --payload 'hello world' --memory-size 128,256,512,1024 --method get --path '/login' --query 'a=1&b=2'

Examples with CLI

$ s cli fc eval start --region cn-hangzhou --function-name myFunctionName --service-name myServiceName --eval-type memory --run-count 50 --payload 'hello world' --memory-size 128,256,512,1024 --method get --path '/login' --query 'a=1&b=2'
$ s cli fc eval start --region cn-hangzhou --function-name myFunctionName --service-name myServiceName --eval-type concurrency --memory 1536 --concurrency-args 2,30,5 --rt 250 --payload-file ./payload.file
$ s cli fc eval start --region cn-hangzhou --function-name functionName --service-name serviceName --eval-type memory --run-count 50 --payload 'hello world' --memory-size 128,256,512,1024 --method get --path '/login' --query 'a=1&b=2'
$ s cli fc eval start --region cn-hangzhou --function-name functionName --service-name serviceName --eval-type concurrency --memory 1536 --concurrency-args 2,30,5 --rt 250 --payload-file ./payload.file
```

### 参数解析

| 参数全称 | 参数缩写 | Yaml模式下必填 | Cli模式下必填 | 参数含义 |
| ---------------- | -------- | -------------- | ------------- | ------------------------------------------------------------ |
| region | - | 选填 | 选填 | 探测的函数所处的地区,取值范围:`cn-hangzhou, cn-beijing, cn-beijing, cn-hangzhou, cn-shanghai, cn-qingdao, cn-zhangjiakou, cn-huhehaote, cn-shenzhen, cn-chengdu, cn-hongkong, ap-southeast-1, ap-southeast-2, ap-southeast-3, ap-southeast-5, ap-northeast-1, eu-central-1, eu-west-1, us-west-1, us-east-1, ap-south-1` |
| service-name | - | 选填 | 选填 | 探测的函数所处的服务名 |
| function-name | - | 选填 | 选填 | 探测的函数名 |
| concurrency-args | - | 选填 | 选填 | |
| eval-type | - | 选填 | 选填 | |
| memory | - | 选填 | 选填 | |
| memory-size | - | 选填 | 选填 | |
| method | - | 选填 | 选填 | |
| path | - | 选填 | 选填 | |
| payload | - | 选填 | 选填 | |
| payload-file | - | 选填 | 选填 | |
| query | - | 选填 | 选填 | |
| rt | - | 选填 | 选填 | |
| run-count | - | 选填 | 选填 | |
| access | a | 选填 | 选填 | 本次请求使用的密钥,可以使用通过[config命令](https://github.com/Serverless-Devs/Serverless-Devs/tree/master/docs/zh/command/config.md#config-add-命令) 配置的密钥信息,以及[配置到环境变量的密钥信息](https://github.com/Serverless-Devs/Serverless-Devs/tree/master/docs/zh/command/config.md#通过环境变量配置密钥信息) |
| region | - | 选填 | 必填 | 探测的函数所处的地区,取值范围:`cn-hangzhou, cn-beijing, cn-beijing, cn-hangzhou, cn-shanghai, cn-qingdao, cn-zhangjiakou, cn-huhehaote, cn-shenzhen, cn-chengdu, cn-hongkong, ap-southeast-1, ap-southeast-2, ap-southeast-3, ap-southeast-5, ap-northeast-1, eu-central-1, eu-west-1, us-west-1, us-east-1, ap-south-1` |
| service-name | - | 选填 | 必填 | 探测的函数所处的服务名 |
| function-name | - | 选填 | 必填 | 探测的函数名 |
| eval-type | - | 选填 | 选填 | 探测类型, 分为 memory 和 concurrency 两种, 默认是memory |
| memory-size | - | 选填 | 选填 | 探测类型为 memory 需要的参数,示例 `128,256,512,1024` |
| run-count | - | 选填 | 选填 | 探测类型为 memory 需要的参数, 指定目标函数在不同内存规格下被分别调用的次数 |
| memory | - | 选填 | 选填 | 探测类型为 concurrency 需要的参数, 建议设置的较大内存, 比如 1.5G(约 1vCPU) 或者 3G(约 2vCPU) |
| concurrency-args | - | 选填 | 选填 | 探测类型为 concurrency 需要的参数, 指定目标函数被探测时的并发度参数范围和步长,例如该参数的配置信息为--concurrency-args 2,20,5,表示并发范围[2,20],步长为5,即被探测的目标函数分别在2、7、12和17不同并发值下实现探测。 |
| rt | - | 选填 | 选填 | 探测类型为 concurrency 需要的参数,期望最大响应时间|
| method | - | 选填 | 选填 | 针对被探测的函数是 Http 函数,取值为GET、POST、PUT、PATCH、DELETE、OPTIONS或HEAD。 |
| path | - | 选填 | 选填 | 针对被探测的函数是 Http 函数, http 请求的 path |
| payload | - | 选填 | 选填 | 如果被探测函数是 Http 函数时,是 http 请求的 body; 如果被探测函数是 event 函数时,是函数入参 event |
| payload-file | - | 选填 | 选填 | 如果被探测函数是 Http 函数时,文件内容是 http 请求的 body; 如果被探测函数是 event 函数时,文件内容是函数入参 event |
| query | - | 选填 | 选填 | 针对被探测的函数是 Http 函数, http 请求的 query |
| access | a | 选填 | 必填 | 本次请求使用的密钥,可以使用通过[config命令](https://github.com/Serverless-Devs/Serverless-Devs/tree/master/docs/zh/command/config.md#config-add-命令) 配置的密钥信息,以及[配置到环境变量的密钥信息](https://github.com/Serverless-Devs/Serverless-Devs/tree/master/docs/zh/command/config.md#通过环境变量配置密钥信息) |
| debug | - | 选填 | 选填 | 打开`debug`模式,将会输出更多日志信息 |
| help | h | 选填 | 选填 | 查看帮助信息 |

### 操作案例

- **有资源描述文件(Yaml)时**,可以直接执行`s eval start`进行函数探测;
- **纯命令行形式(在没有资源描述 Yaml 文件时)**,需要指定服务所在地区以及服务名称,函数名等,例如`s cli fc eval start --region cn-hangzhou --service-name fc-deploy-service --function-name http-trigger-py36 --eval-type memory --run-count 50 --payload 'hello world' --memory-size 128,256,512,1024 --method get --path '/login' --query 'a=1&b=2'`
- **纯命令行形式(在没有资源描述 Yaml 文件时)**,需要指定服务所在地区以及服务名称,函数名等,例如`s cli fc eval start --region cn-hangzhou --function-name cpu-test --function-name test --service-name Service --eval-type memory --run-count 10 --payload '{"key":"val"}' --memory-size 128,256,512,1024 --access default`

上述命令的执行结果示例:

```text
fc-deploy-test: http://memory-tuning.devsapp.cn/#gAAAAQACAAQ=;KVwPQGZmBkCkcB1AcT0KQA==;N/8EM4ZeeTMjDxI0Pj+ANA==
http://memory-tuning.devsapp.cn/#gAAAAQACAAQ=;AIAARwBYgEYAoPdFAHiBRQ==;37w+OH+BPjiqxzc4/SxAOA==
```

此时,可以通过浏览器系统返回的地址,查看相关探测信息:

![图片alt](https://serverless-article-picture.oss-cn-hangzhou.aliyuncs.com/1636357746695_20211108074928902791.png)
![图片alt](https://img.alicdn.com/imgextra/i3/O1CN01nZNiZX1dQO2nqqWVf_!!6000000003730-2-tps-1533-649.png)

关于该结果的解析如下:

1. 图中红色的线表示执行时间与内存大小的关系;蓝色的线表示所消耗的成本与内存之间的关系;
2. 右侧四个数字分别是:
- Best Cost:消费最少的时候,内存是128MB
- Best Time:执行耗时最小的时候,内存是256MB
- Best Cost:消费最少的时候,内存是512MB
- Best Time:执行耗时最小的时候,内存是1024MB
- Worst Cost:消费最多的时候,内存是1024MB;
- Worst Time:执行耗时最长的时候,内存是512MB;

此时可以根据这个数据,当前函数资源进行内存设定,可以综合曲线和实际业务需求,例如,在当前时刻,内存设置在128MB或者256MB相对是合理的,而设置512MB或者1024MB是不合理的。

## eval clean 命令

`eval clean` 命令,是清理因进行线上函数探测所创建资源的命令。

当执行命令`eval clean -h`/`eval clean --help`时,可以获取帮助文档:

```shell script
Eval clean

Clean the relevant resources, including helper resources.

Usage

s eval clean <options>

Options

--region [string] [C-Required] Specify the fc region, value: cn-hangzhou/cn-beijing/cn-beijing/cn-hangzhou/cn-shanghai/cn-qingdao/cn-zhangjiakou/cn-huhehaote/cn-shenzhen/cn-chengdu/cn-hongkong/ap-southeast-1/ap-southeast-2/ap-southeast-3/ap-southeast-5/ap-northeast-1/eu-central-1/eu-west-1/us-west-1/us-east-1/ap-south-1
--service-name [string] [C-Required] Specify the fc service name
--function-name [string] [C-Required] Specify the fc function name
-y, --assume-yes [Optional] Assume that the answer to any question which would be asked is yes

Global Options

-h, --help [Optional] Help for command
-a, --access [string] [Optional] Specify key alias
--debug [Optional] Output debug informations

Options Help

Required: Required parameters in YAML mode and CLI mode
C-Required: Required parameters in CLI mode
Y-Required: Required parameters in Yaml mode
Optional: Non mandatory parameter
✋ The difference between Yaml mode and CLI mode: https://github.com/Serverless-Devs/Serverless-Devs/blob/docs/docs/zh/yaml_and_cli.md

Examples with Yaml

$ s eval clean

Examples with CLI

$ s cli fc eval clean --region myRegion --service-name xxx --function-name xxx -y
```

### 参数解析

| 参数全称 | 参数缩写 | Yaml模式下必填 | Cli模式下必填 | 参数含义 |
| ------------- | -------- | -------------- | ------------- | ------------------------------------------------------------ |
| region | - | 选填 | 选填 | 探测的函数所处的地区,取值范围:`cn-hangzhou, cn-beijing, cn-beijing, cn-hangzhou, cn-shanghai, cn-qingdao, cn-zhangjiakou, cn-huhehaote, cn-shenzhen, cn-chengdu, cn-hongkong, ap-southeast-1, ap-southeast-2, ap-southeast-3, ap-southeast-5, ap-northeast-1, eu-central-1, eu-west-1, us-west-1, us-east-1, ap-south-1` |
| service-name | - | 选填 | 选填 | 探测的函数所处的服务名 |
| function-name | - | 选填 | 选填 | 探测的函数名 |
| assume-yes | y | 选填 | 选填 | 在交互时,默认选择`y` |
| access | a | 选填 | 选填 | 本次请求使用的密钥,可以使用通过[config命令](https://github.com/Serverless-Devs/Serverless-Devs/tree/master/docs/zh/command/config.md#config-add-命令) 配置的密钥信息,以及[配置到环境变量的密钥信息](https://github.com/Serverless-Devs/Serverless-Devs/tree/master/docs/zh/command/config.md#通过环境变量配置密钥信息) |
| debug | - | 选填 | 选填 | 打开`debug`模式,将会输出更多日志信息 |
| help | h | 选填 | 选填 | 查看帮助信息 |

### 操作案例

- **有资源描述文件(Yaml)时**,可以直接执行`s eval clean`对因函数探测所创建的辅助资源进行清理;
- **纯命令行形式(在没有资源描述 Yaml 文件时)**,需要指定服务所在地区以及服务名称,函数名等,例如`s cli fc eval clean --region cn-hangzhou --service-name fc-deploy-service --function-name http-trigger-py36 `

上述命令的执行结果示例:

```text
Resource cleanup succeeded.
```
- Worst Time:执行耗时最长的时候,内存是128MB;

此时可以根据这个数据,当前函数资源进行内存设定,可以综合曲线和实际业务需求,例如,在当前时刻,延迟要求在 20000ms 以内,256M 是成本最佳, 如果要求延迟在 5000ms 以内, 这个时候 1024M 是最佳选择。

## 权限与策略说明

不需要特殊权限, 一般 s 使用的 access 有 FCFullAccess 即可

0 comments on commit 6e92cea

Please sign in to comment.