Skip to content

Commit

Permalink
add eval doc
Browse files Browse the repository at this point in the history
  • Loading branch information
rsonghuster committed Oct 2, 2021
1 parent f032a99 commit 3506249
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 42 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
- [层的操作:Layer](./docs/Usage/layer.md)
- [端云联调: Proxied](./docs/Usage/proxied.md)
- [压测操作: Stress](./docs/Usage/stress.md)
- [内存和并发度探测: Eval](./docs/Usage/eval.md)
- [远程调试: Remote](./docs/Usage/remote.md)
- 权限相关
- [Yaml 字段相关配置权限](./docs/Others/authority/yaml.md)
Expand Down
128 changes: 128 additions & 0 deletions docs/Usage/eval.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# 探测函数内存或并发度操作:Eval

- [简介](#简介)

- [快速使用](#快速使用)
- [简单使用](#简单使用)
- [开始探测](#开始探测)

---

阿里云函数计算(FC)组件为使用者提供了对 event 函数以及匿名 http 函数发起压测的能力。可以通过`eval`指令,快速进行压测操作。

您可以通过`s cli fc eval -h`指令,唤起帮助信息:

```
Eval
Power tunning online functions
Usage
s eval <sub-command>
SubCommand List
start Power tunning online functions, you can get help through [s cli fc eval start -h]
```

Eval 命令只有一个子命令:

- start: 开始探测流程,可以通过`s cli fc eval start -h`获取帮助文档:

```
Eval start
Power tunning start
Usage
s start <options>
Options
--concurrency-args string Concurrency args of power tunning that can convert to concurrency list,
only for --eval-type concurrency
--eval-type string Type of the power tunning, including memory and concurrency
--function-name string Specify the alicloud fc function name
--function-type string Type of the target function, including event and http
--memory number Function memory of power tunning, only for --eval-type concurrency
--memory-size string Function MemorySize List of power tunning, only for --eval-type memory
--method string Target method, only for --function-type http
--path string Target path, only for --function-type http
--payload string For --function-type event, represents the event passed to the function;
For --function-type http, represents the request body passed to the
function
-f, --payload-file string For --function-type event, contains the event passed to the function;
For --function-type http, contains the request body passed to the
function
--query string Target query, only for --function-type http
-r, --region string Specify the region of alicloud
--rt number Max response time, only for --eval-type concurrency
--run-count number Number of Invoke Function, only for --eval-type memory
--service-name string Specify the alicloud fc service name
Global Options
-a, --access string Specify key alias
--debug string Output debug informations
-h, --help string Help for command.
Examples with CLI
$ s cli fc eval start --region cn-hangzhou --function-name myFunctionName
--service-name myServiceName --function-type event --eval-type memory
--run-count 10 --payload-file ./payload.file --memory-size 128,256,512,1024
--access default
$ s cli fc start --region cn-hangzhou --function-name myFunctionName
--service-name myServiceName --function-type http --eval-type memory
--run-count 50 --payload 'hello world' --memory-size 128,256,512,1024
--method get --path '/login' --query 'a=1&b=2' --access default
$ s cli fc start --region cn-hangzhou --function-name myFunctionName
--service-name myServiceName --function-type event --eval-type concurrency
--memory 1536 --concurrency-args 2,30,5 --rt 250 --payload-file
./payload.file --access default
$ s cli fc start --region cn-hangzhou --function-name myFunctionName
--service-name myServiceName --function-type http --eval-type concurrency
--memory 1536 --concurrency-args 2,20,5 --rt 250 --method get --path '/login'
--query 'a=1&b=2' --access default
```

# 快速使用

当我们下载好[Serverless Devs 开发者工具](../Getting-started/Install-tutorial.md), 并完成[阿里云密钥配置](../Getting-started/Setting-up-credentials.md)之后,我们可以根据自身的需求进行函数进行内存或者并发度探测。

## 简单使用

### 内存探测模式
如果您的函数是 cpu 密集型, 一般就是默认的单实例单并发, 比如音视频处理, 游戏中的战斗结算等函数, 这时您可以选择 `eval-type ``memory` 对具体的函数进行探测, 比如:

``` bash
s cli fc eval start --region=cn-hangzhou --function-name cpu-test --service-name dsp-test --function-type event --eval-type memory --run-count 10 --payload {"key":"val"} --memory-size 128,256,512,1024,1536,3072 --access default
```
上述命令, 表示对 Event 类型的函数 dsp-test/cpu-test 进行内存模式探测, 探测的内存列表为 `[128, 256, 512, 1024, 1536, 3072]` , 被探测的函数在不同的内存模式下各自被调用 10 次,探测结束后, 会生成一个 url, 打开这个 url, 可以可视化展示结果, 比如:

[http://memory-tunning.devsapp.cn/#gAAAAQACAAQ=;ZMsORykTkEZcbQVGKexxRQ==;naKfOJZloTgdDZY4jhWIOA==](http://memory-tunning.devsapp.cn/#gAAAAQACAAQ=;ZMsORykTkEZcbQVGKexxRQ==;naKfOJZloTgdDZY4jhWIOA==)


### 并发度探测模式
如果您的函数是 IO 密集型, 您一般是设置[单实例多并发](https://help.aliyun.com/document_detail/144586.html),
在函数计算中, CPU 能力跟内存大小成正比, 大约 1.5G 对应 1 核 CPU, 所以在单实例多并发模式下, 一般建议函数内存足够大些, 比如 1.5G 进行探测:

```bash
s cli fc@dev eval start --region cn-hangzhou --function-name http-hello --service-name dsp-test --function-type http --eval-type concurrency --memory 1536 --concurrency-args 2,20,5 --rt 200 --method=get --path /login --query 'a=1&b=2' --access default
```
上述命令, 表示对 Http 类型的函数 dsp-test/http-hello 进行并发度模式探测,探测的函数内存为1.5G,并发度范围为 2-20, 步长为5,即探测的并发度列表为 `[2, 7, 12, 17]` ,最大 RT 为 200ms(即随着并发度增大, RT增加大超过这个限制值, 则后续更大的并发度不用探测了), 探测结束后, 会生成一个 url, 打开这个 url, 可以可视化展示结果, 比如:

[http://concurrency-tunning.devsapp.cn/#AgAHAAwAEQA=;MZ3FQWCjv0FrF7xBS63kQQ==;AADAQAAAIEIAAFBCAAAwQg==](http://concurrency-tunning.devsapp.cn/#AgAHAAwAEQA=;MZ3FQWCjv0FrF7xBS63kQQ==;AADAQAAAIEIAAFBCAAAwQg==)

#### 建议
- 您第一次探测的时候, 可以稍微将步长调整大些, 根据探测后的 UI, 缩小探测范围和步长, 直至逼近符合自己需求的最优解。

- 探测的时候, 选择 1.5G, 比如探测的最优并发度是4, 当函数内存调整为 3G 的时候, 正常来说, 最优并发度一般是 8

6 changes: 3 additions & 3 deletions docs/Usage/stress.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

阿里云函数计算(FC)组件为使用者提供了对 event 函数以及匿名 http 函数发起压测的能力。可以通过`stress`指令,快速进行压测操作。

您可以通过`s cli stress -h`指令,唤起帮助信息:
您可以通过`s cli fc stress -h`指令,唤起帮助信息:

```
Stress
Expand All @@ -30,7 +30,7 @@ SubCommand List
```

Stress 命令为我们提供了两个子命令:
- start: 开始压测流程,可以通过`s cli stress start -h`获取帮助文档:
- start: 开始压测流程,可以通过`s cli fc stress start -h`获取帮助文档:
```
Stress start
Expand Down Expand Up @@ -81,7 +81,7 @@ Stress 命令为我们提供了两个子命令:
--region myRegion --access myAccess
```

- clean: 清理压测的辅助资源和本地缓存文件,可以通过`s cli stress clean -h`获取帮助文档:
- clean: 清理压测的辅助资源和本地缓存文件,可以通过`s cli fc stress clean -h`获取帮助文档:
```
Stress clean
Expand Down
63 changes: 33 additions & 30 deletions docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

[阿里云函数计算(FC)组件](https://github.com/devsapp/fc) 是一个用于支持阿里云 Serverless 应用全生命周期的工具,它通过资源配置文件 (s.yml) ,可以快速帮助用户便捷地开发、构建、测试以及部署应用到[阿里云函数计算平台](https://www.aliyun.com/product/fc?spm=5176.19720258.J_8058803260.115.e9392c4aHejRf3)

阿里云函数计算(FC)组件基于[Serverless Devs](https://www.serverless-devs.com/) 进行开发,主要支持两种使用形态:
阿里云函数计算(FC)组件基于[Serverless Devs](https://www.serverless-devs.com/) 进行开发,主要支持两种使用形态:

1. 通过Yaml文件进行资源描述。使用阿里云函数计算(FC)组件的 YAML 规范(`s.yaml`)定义 Serverless 资源。它包含了函数计算的服务、函数、触发器以及自定义域名等资源,阿里云函数计算(FC)组件的 YAML 规范详细信息可参考[FC组件YAML规范](./Others/yaml.md)
1. 通过 Yaml 文件进行资源描述。使用阿里云函数计算(FC)组件的 YAML 规范(`s.yaml`)定义 Serverless 资源。它包含了函数计算的服务、函数、触发器以及自定义域名等资源,阿里云函数计算(FC)组件的 YAML 规范详细信息可参考[FC 组件 YAML 规范](./Others/yaml.md)

2. 通过交互式命令行进行相关能力管理。您能够利用阿里云函数计算(FC)组件命令行接口来完成 Serverless 应用的开发部署。该命令行接口能够帮助您校验 `s.yml`,构建函数,本地调试函数,部署函数至函数计算并对其进行观测。

Expand All @@ -31,37 +31,40 @@
## 文档目录

- [入门相关](./Getting-started/Getting-started.md)
- [开发工具安装](./Getting-started/Install-tutorial.md)
- [账号配置](./Getting-started/Setting-up-credentials.md)
- [快速体验](./Getting-started/Hello-world-application.md)
- [Yaml规范](./Others/yaml.md)
- [开发工具安装](./Getting-started/Install-tutorial.md)
- [账号配置](./Getting-started/Setting-up-credentials.md)
- [快速体验](./Getting-started/Hello-world-application.md)
- [Yaml 规范](./Others/yaml.md)
- 指令使用方法
- [部署操作:Deploy](./Usage/deploy.md)
- [构建操作:Build](./Usage/build.md)
- [查看操作:Info](./Usage/info.md)
- [远程调用操作:Invoke](./Usage/invoke.md)
- [本地调用操作:Local](./Usage/local.md)
- [查看日志操作:Logs](./Usage/logs.md)
- [指标查询操作:Metrics](./Usage/metrics.md)
- [硬盘挂载操作:Nas](./Usage/nas.md)
- [移除操作:Remove](./Usage/remove.md)
- [同步操作:Sync](./Usage/sync.md)
- [版本操作:Version](./Usage/version.md)
- [别名操作:Alias](./Usage/alias.md)
- [预留操作:Provision](./Usage/provision.md)
- [按量资源操作:OnDemand](./Usage/onDemand.md)
- [层的操作:Layer](./Usage/layer.md)
- [部署操作:Deploy](./Usage/deploy.md)
- [构建操作:Build](./Usage/build/build.md)
- [查看操作:Info](./Usage/info.md)
- [远程调用操作:Invoke](./Usage/invoke.md)
- [本地调用操作:Local](./Usage/local.md)
- [查看日志操作:Logs](./Usage/logs.md)
- [指标查询操作:Metrics](./Usage/metrics.md)
- [硬盘挂载操作:Nas](./Usage/nas.md)
- [移除操作:Remove](./Usage/remove.md)
- [同步操作:Sync](./Usage/sync.md)
- [版本操作:Version](./Usage/version.md)
- [别名操作:Alias](./Usage/alias.md)
- [预留操作:Provision](./Usage/provision.md)
- [按量资源操作:OnDemand](./Usage/onDemand.md)
- [层的操作:Layer](./Usage/layer.md)
- [端云联调: Proxied](./Usage/proxied.md)
- [压测操作: Stress](./Usage/stress.md)
- [内存和并发度探测: Eval](./Usage/eval.md)
- [远程调试: Remote](./Usage/remote.md)
- 权限相关
- [Yaml字段相关配置权限](./Others/authority/yaml.md)
- [命令使用相关权限](./Others/authority/command.md)
- [Yaml 字段相关配置权限](./Others/authority/yaml.md)
- [命令使用相关权限](./Others/authority/command.md)
- 更多
- [从Funcraft迁移到Serverless Devs](./Others/fun-fc.md)
- CI/CD相关
- [Github Action 与 Serverless Devs](./Others/github-action.md)
- [阿里云Custom Container的CI/CD最佳实践案例](http://www.serverless-devs.com/blog/aliyun-custom-container-ci-cd)
- [通过Gitee+Serverless Devs快速实现函数代码更新与版本发布](http://www.serverless-devs.com/blog/gitee-gitee-go-serverless-devs-ci-cd)
- [只更新代码,然后发布版本:基于Serverless Devs原子化操作阿里云函数计算](http://www.serverless-devs.com/blog/serverless-devs-update-fc-code)

- [从 Funcraft 迁移到 Serverless Devs](./Others/fun-fc.md)
- CI/CD 相关
- [Github Action 与 Serverless Devs](./Others/github-action.md)
- [阿里云 Custom Container 的 CI/CD 最佳实践案例](http://www.serverless-devs.com/blog/aliyun-custom-container-ci-cd)
- [通过 Gitee+Serverless Devs 快速实现函数代码更新与版本发布](http://www.serverless-devs.com/blog/gitee-gitee-go-serverless-devs-ci-cd)
- [只更新代码,然后发布版本:基于 Serverless Devs 原子化操作阿里云函数计算](http://www.serverless-devs.com/blog/serverless-devs-update-fc-code)

# More

Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@
"devDependencies": {
"@types/eslint": "^7.2.6",
"@types/jest": "^26.0.10",
"callsites": "^4.0.0",
"@types/lodash": "^4.14.171",
"@types/node": "14",
"@vercel/ncc": "^0.24.0",
"callsites": "^4.0.0",
"f2elint": "^0.4.4",
"husky": "^7.0.2",
"jest": "^26.4.0",
"rimraf": "^3.0.2",
"ts-jest": "^26.2.0",
"ts-loader": "^8.0.14",
"ts-node": "^9.1.1",
"typescript": "^3.9.7",
"@vercel/ncc": "^0.24.0",
"typedoc": "^0.20.35"
"typedoc": "^0.20.35",
"typescript": "^3.9.7"
},
"scripts": {
"start": "npm run dev",
Expand Down
4 changes: 2 additions & 2 deletions src/command/eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export async function start(inputs: IInputs): Promise<any> {
* @pre_help
* {"header":"Eval","content":"Power tunning online functions"}
* @after_help
* {"header": "SubCommand List", "content": [{"name":"start","summary":"Power tunning online functions, you can get help through [s eval start -h]"}]}
* {"header": "SubCommand List", "content": [{"name":"start","summary":"Power tunning online functions, you can get help through [s cli fc eval start -h]"}]}
*/
export interface EvalInputsArgs {}

Expand All @@ -21,7 +21,7 @@ export interface EvalInputsArgs {}
* @after_help
* {"ref":"GlobalParams"}
* @example
* {"header": "Examples with CLI","content": ["$ s cli fc-eval start --region=cn-hangzhou --function-name=myFunctionName --service-name=myServiceName --function-type=event --eval-type=memory --run-count=10 --payload-file=./payload.file --memory-size=128,256,512,1024 --access=default","$ s cli fc-eval start --region=cn-hangzhou --function-name=myFunctionName --service-name=myServiceName --function-type=http --eval-type=memory --run-count=50 --payload='hello world' --memory-size=128,256,512,1024 --method=get --path=/login --query='a=1&b=2' --access=default", "s cli fc-eval start --region=cn-hangzhou --function-name=myFunctionName --service-name=myServiceName --function-type=event --eval-type=concurrency --memory=1536 --concurrency-args=2,30,5 --rt 1000 --payload-file=./payload.file --access=default","s cli fc-eval start --region=cn-hangzhou --function-name=myFunctionName --service-name=myServiceName --function-type=http --eval-type=concurrency --memory=1536 --concurrency-args=2,20,5 --rt 1000 --method=get --path=/login --query='a=1&b=2' --access=default"]}
* {"header": "Examples with CLI","content": ["$ s cli fc eval start --region cn-hangzhou --function-name myFunctionName --service-name myServiceName --function-type event --eval-type memory --run-count 10 --payload-file ./payload.file --memory-size 128,256,512,1024 --access default","\n$ s cli fc start --region cn-hangzhou --function-name myFunctionName --service-name myServiceName --function-type http --eval-type memory --run-count 50 --payload 'hello world' --memory-size 128,256,512,1024 --method get --path '/login' --query 'a=1&b=2' --access default", "\n$ s cli fc start --region cn-hangzhou --function-name myFunctionName --service-name myServiceName --function-type event --eval-type concurrency --memory 1536 --concurrency-args 2,30,5 --rt 250 --payload-file ./payload.file --access default","\n$ s cli fc start --region cn-hangzhou --function-name myFunctionName --service-name myServiceName --function-type http --eval-type concurrency --memory 1536 --concurrency-args 2,20,5 --rt 250 --method get --path '/login' --query 'a=1&b=2' --access default"]}
*/
export interface EvalStartInputsArgs {
/**
Expand Down
7 changes: 4 additions & 3 deletions src/lib/help/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ export const COMPONENT_HELP_INFO = [
{ name: 'provision', summary: 'Resource reservation operation' },
{ name: 'onDemand', summary: 'Resource OnDemand operation' },
{ name: 'layer', summary: 'Resource layer operation' },
{ name: 'remote', summary: 'Remote invoke via proxied service'},
{ name: 'proxied', summary: 'Local invoke via proxied service.'},
{ name: 'stress', summary: 'Stress test for the serverless application'}
{ name: 'remote', summary: 'Remote invoke via proxied service' },
{ name: 'proxied', summary: 'Local invoke via proxied service.' },
{ name: 'stress', summary: 'Stress test for the serverless application' },
{ name: 'eval', summary: 'Eval test for the serverless application' },
],
},
{
Expand Down

0 comments on commit 3506249

Please sign in to comment.