无服务器架构
无服务器架构 (Serverless) 是一种云计算执行模型,云提供商动态管理服务器资源的分配和扩展。开发者只需关注业务代码,无需管理基础设施。本章深入探讨 Serverless 架构的核心概念和实践方法。
Serverless 概念
什么是 Serverless
Serverless 并非"没有服务器",而是"无需管理服务器":
text
传统架构 vs Serverless 架构:
┌─────────────────────────────────────────────────────────────┐
│ 传统架构 │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ 开发者负责:代码 + 运行时 + 中间件 + OS + 服务器 + 网络 │ │
│ └─────────────────────────────────────────────────────────┘ │
├─────────────────────────────────────────────────────────────┤
│ Serverless 架构 │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ 开发者负责:代码 │ │
│ │ 云厂商负责:运行时 + 中间件 + OS + 服务器 + 网络 │ │
│ └─────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
```text
### Serverless 核心特征
| 特征 | 描述 |
|------|------|
| **无服务器管理** | 无需配置、维护、打补丁服务器 |
| **自动弹性伸缩** | 根据请求量自动扩展或收缩 |
| **按需计费** | 只为实际执行付费,空闲时不收费 |
| **事件驱动** | 函数由事件触发执行 |
| **无状态** | 每次执行独立,不依赖之前的状态 |
### Serverless 组成部分
```text
Serverless 生态:
┌─────────────────────────────────────────────────────────────┐
│ Serverless 应用 │
├─────────────────────────────────────────────────────────────┤
│ │
│ FaaS (函数即服务) BaaS (后端即服务) │
│ ┌──────────────────┐ ┌──────────────────────────┐ │
│ │ AWS Lambda │ │ 数据库服务 │ │
│ │ Azure Functions │ │ ├── DynamoDB │ │
│ │ Google Cloud │ │ ├── Firestore │ │
│ │ Functions │ │ └── MongoDB Atlas │ │
│ │ 阿里云函数计算 │ │ │ │
│ │ 腾讯云 SCF │ │ 存储服务 │ │
│ └──────────────────┘ │ ├── S3 / OSS │ │
│ │ └── Cloud Storage │ │
│ │ │ │
│ │ 认证服务 │ │
│ │ ├── Cognito │ │
│ │ └── Auth0 │ │
│ │ │ │
│ │ 消息服务 │ │
│ │ ├── SQS │ │
│ │ └── EventBridge │ │
│ └──────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
```text
## FaaS 平台实践
### 主流 FaaS 平台对比
| 平台 | 提供商 | 运行时支持 | 执行时长限制 | 内存配置 |
|------|--------|-----------|-------------|---------|
| Lambda | AWS | Node.js, Python, Java, Go, .NET, Ruby | 15 分钟 | 128MB - 10GB |
| Azure Functions | Microsoft | Node.js, Python, Java, C#, PowerShell | 10 分钟 | 128MB - 14GB |
| Cloud Functions | Google | Node.js, Python, Java, Go, .NET, Ruby | 9 分钟 | 128MB - 32GB |
| 函数计算 | 阿里云 | Node.js, Python, Java, PHP, Go | 10 分钟 | 128MB - 3GB |
| SCF | 腾讯云 | Node.js, Python, Java, PHP, Go | 900 秒 | 128MB - 3GB |
### 函数开发示例
**AWS Lambda 函数**:
```typescript
// handler.ts
import { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda';
export const handler = async (
event: APIGatewayProxyEvent
): Promise<APIGatewayProxyResult> => {
try {
const body = JSON.parse(event.body || '{}');
// 业务逻辑处理
const result = await processOrder(body);
return {
statusCode: 200,
body: JSON.stringify({
message: 'Order processed successfully',
data: result
})
};
} catch (error) {
return {
statusCode: 500,
body: JSON.stringify({
message: 'Internal server error',
error: error.message
})
};
}
};
async function processOrder(orderData: any) {
// 处理订单逻辑
return { orderId: '12345', status: 'completed' };
}
```text
**函数配置**:
```yaml
# serverless.yml (Serverless Framework)
service: order-service
provider:
name: aws
runtime: nodejs18.x
region: us-east-1
timeout: 30
memorySize: 512
environment:
DB_TABLE: orders
functions:
createOrder:
handler: handler.createOrder
events:
- http:
path: orders
method: post
cors: true
getOrder:
handler: handler.getOrder
events:
- http:
path: orders/{id}
method: get
```text
### 触发器类型
```text
常见触发器类型:
┌─────────────────────────────────────────────────────────────┐
│ │
│ HTTP 触发器 │
│ ├── API Gateway (REST API) │
│ ├── Application Load Balancer │
│ └── HTTP API (简化版) │
│ │
│ 消息队列触发器 │
│ ├── SQS (Simple Queue Service) │
│ ├── SNS (Simple Notification Service) │
│ ├── Kinesis (数据流) │
│ └── Kafka / MSK │
│ │
│ 存储触发器 │
│ ├── S3 (对象上传/删除) │
│ ├── DynamoDB Streams │
│ └── Aurora Database │
│ │
│ 定时触发器 │
│ ├── EventBridge (CloudWatch Events) │
│ └── Schedule Expression │
│ │
│ 其他触发器 │
│ ├── Cognito (用户认证事件) │
│ ├── CloudWatch Logs │
│ └── SES (邮件事件) │
│ │
└─────────────────────────────────────────────────────────────┘
```text
**多触发器函数示例**:
```typescript
// 同一函数可由多种事件触发
export const handler = async (event: any) => {
// 判断触发源
if (event.Records) {
// SQS 或 S3 触发
for (const record of event.Records) {
if (record.eventSource === 'aws:sqs') {
await processSQSMessage(record);
} else if (record.eventSource === 'aws:s3') {
await processS3Event(record);
}
}
} else if (event['detail-type']) {
// EventBridge 触发
await processScheduledEvent(event);
} else if (event.httpMethod) {
// API Gateway 触发
return handleHttpRequest(event);
}
};
```text
### 函数设计模式
**1. 函数粒度**
```text
函数粒度选择:
┌─────────────────────────────────────────────────────────────┐
│ │
│ 单一用途函数 (推荐) │
│ ├── createOrder → 创建订单 │
│ ├── processPayment → 处理支付 │
│ └── sendEmail → 发送邮件 │
│ 优点:独立部署、独立扩展、职责清晰 │
│ │
│ 多用途函数 (不推荐) │
│ └── orderHandler → 创建/查询/取消订单 │
│ 缺点:耦合度高、难以独立扩展 │
│ │
└─────────────────────────────────────────────────────────────┘
```text
**2. 函数编排**
```typescript
// 使用 Step Functions 编排多个函数
// 定义状态机
{
"Comment": "Order processing workflow",
"StartAt": "ValidateOrder",
"States": {
"ValidateOrder": {
"Type": "Task",
"Resource": "arn:aws:lambda:...:validateOrder",
"Next": "ProcessPayment"
},
"ProcessPayment": {
"Type": "Task",
"Resource": "arn:aws:lambda:...:processPayment",
"Next": "UpdateInventory"
},
"UpdateInventory": {
"Type": "Task",
"Resource": "arn:aws:lambda:...:updateInventory",
"Next": "SendConfirmation"
},
"SendConfirmation": {
"Type": "Task",
"Resource": "arn:aws:lambda:...:sendConfirmation",
"End": true
}
}
}
```text
```text
Step Functions 流程图:
┌─────────────────────────────────────────────────────────────┐
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Validate │────→│ Process │────→│ Update │ │
│ │ Order │ │ Payment │ │ Inventory │ │
│ └─────────────┘ └─────────────┘ └──────┬──────┘ │
│ │ │
│ ↓ │
│ ┌─────────────┐ │
│ │ Send │ │
│ │ Confirmation│ │
│ └─────────────┘ │
│ │
└─────────────────────────────────────────────────────────────┘
```text
## BaaS 服务集成
### 数据库服务
**DynamoDB (AWS)**:
```typescript
// DynamoDB 操作示例
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
import { DynamoDBDocumentClient, GetCommand, PutCommand, QueryCommand } from '@aws-sdk/lib-dynamodb';
const client = new DynamoDBClient({});
const docClient = DynamoDBDocumentClient.from(client);
// 创建/更新
async function putOrder(order: Order) {
await docClient.send(new PutCommand({
TableName: 'Orders',
Item: order
}));
}
// 查询单条
async function getOrder(orderId: string): Promise<Order | null> {
const result = await docClient.send(new GetCommand({
TableName: 'Orders',
Key: { orderId }
}));
return result.Item as Order;
}
// 查询列表
async function getOrdersByUser(userId: string): Promise<Order[]> {
const result = await docClient.send(new QueryCommand({
TableName: 'Orders',
IndexName: 'UserIndex',
KeyConditionExpression: 'userId = :userId',
ExpressionAttributeValues: {
':userId': userId
}
}));
return result.Items as Order[];
}
```text
**DynamoDB 数据模型设计**:
```text
DynamoDB 单表设计:
┌─────────────────────────────────────────────────────────────┐
│ Table: Orders │
├─────────────────────────────────────────────────────────────┤
│ PK │ SK │ Attributes │
├─────────────────┼─────────────────┼────────────────────────┤
│ ORDER#123 │ ORDER#123 │ status, total, date │
│ ORDER#123 │ ITEM#001 │ productId, quantity │
│ ORDER#123 │ ITEM#002 │ productId, quantity │
│ USER#U001 │ ORDER#123 │ orderDate, status │
│ USER#U001 │ ORDER#124 │ orderDate, status │
└─────────────────────────────────────────────────────────────┘
访问模式:
- 按 orderId 查询:PK = ORDER#123
- 查询用户所有订单:PK = USER#U001, SK begins_with ORDER#
```text
### 存储服务
**S3 对象存储**:
```typescript
import { S3Client, GetObjectCommand, PutObjectCommand } from '@aws-sdk/client-s3';
const s3 = new S3Client({});
// 上传文件
async function uploadFile(bucket: string, key: string, body: Buffer) {
await s3.send(new PutObjectCommand({
Bucket: bucket,
Key: key,
Body: body,
ContentType: 'application/pdf'
}));
}
// 下载文件
async function downloadFile(bucket: string, key: string): Promise<Buffer> {
const result = await s3.send(new GetObjectCommand({
Bucket: bucket,
Key: key
}));
return Buffer.from(await result.Body.transformToByteArray());
}
// S3 触发器处理上传文件
export const processUpload = async (event: S3Event) => {
for (const record of event.Records) {
const bucket = record.s3.bucket.name;
const key = decodeURIComponent(record.s3.object.key);
// 处理上传的文件
const file = await downloadFile(bucket, key);
// ... 处理逻辑
}
};
```text
### 认证服务
**Cognito 用户池**:
```typescript
import {
CognitoIdentityProviderClient,
SignUpCommand,
InitiateAuthCommand
} from '@aws-sdk/client-cognito-identity-provider';
const cognito = new CognitoIdentityProviderClient({});
// 用户注册
async function signUp(email: string, password: string) {
await cognito.send(new SignUpCommand({
ClientId: process.env.COGNITO_CLIENT_ID,
Username: email,
Password: password,
UserAttributes: [
{ Name: 'email', Value: email }
]
}));
}
// 用户登录
async function signIn(email: string, password: string) {
const result = await cognito.send(new InitiateAuthCommand({
ClientId: process.env.COGNITO_CLIENT_ID,
AuthFlow: 'USER_PASSWORD_AUTH',
AuthParameters: {
USERNAME: email,
PASSWORD: password
}
}));
return {
accessToken: result.AuthenticationResult.AccessToken,
idToken: result.AuthenticationResult.IdToken,
refreshToken: result.AuthenticationResult.RefreshToken
};
}
```text
### 消息服务
**SQS 队列**:
```typescript
import { SQSClient, SendMessageCommand, ReceiveMessageCommand } from '@aws-sdk/client-sqs';
const sqs = new SQSClient({});
// 发送消息
async function sendMessage(queueUrl: string, message: any) {
await sqs.send(new SendMessageCommand({
QueueUrl: queueUrl,
MessageBody: JSON.stringify(message),
DelaySeconds: 0
}));
}
// Lambda 处理 SQS 消息
export const processSQS = async (event: SQSEvent) => {
for (const record of event.Records) {
const message = JSON.parse(record.body);
await processMessage(message);
}
};
```text
## 冷启动优化
### 什么是冷启动
```text
Lambda 执行生命周期:
┌─────────────────────────────────────────────────────────────┐
│ │
│ 冷启动流程: │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ 下载代码 │──→│ 创建容器 │──→│ 初始化 │──→│ 执行函数 │ │
│ │ ~100ms │ │ ~200ms │ │ ~500ms │ │ 业务逻辑 │ │
│ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │
│ │
│ 热启动流程: │
│ ┌──────────┐ │
│ │ 执行函数 │ ← 容器和运行时已就绪 │
│ │ 业务逻辑 │ │
│ └──────────┘ │
│ │
└─────────────────────────────────────────────────────────────┘
```text
### 冷启动影响因素
| 因素 | 影响 | 优化建议 |
|------|------|----------|
| 运行时 | Java > .NET > Node.js > Python > Go | 选择轻量级运行时 |
| 内存配置 | 内存越大,CPU 越强,冷启动越快 | 适当增加内存 |
| 代码包大小 | 包越大,加载越慢 | 减少依赖,使用 Layer |
| VPC 配置 | VPC 内冷启动更慢 | 非必要不使用 VPC |
| 初始化代码 | 全局初始化影响启动时间 | 延迟加载 |
### 优化策略
**1. 选择合适的运行时**
```typescript
// Go 函数:冷启动最快
package main
import (
"github.com/aws/aws-lambda-go/lambda"
)
func handler() (string, error) {
return "Hello from Go!", nil
}
func main() {
lambda.Start(handler)
}
```text
```typescript
// Node.js:冷启动较快,推荐使用
export const handler = async (event) => {
return { message: 'Hello from Node.js!' };
};
```text
**2. 减少依赖**
```typescript
// 不好的做法:引入整个库
import _ from 'lodash'; // 整个 lodash 约 70KB
// 好的做法:只引入需要的函数
import debounce from 'lodash/debounce'; // 只引入需要的部分
```text
**3. 使用 Layer 共享依赖**
```yaml
# serverless.yml
layers:
commonDeps:
path: layers/common
compatibleRuntimes:
- nodejs18.x
functions:
myFunction:
handler: handler.main
layers:
- { Ref: CommonDepsLambdaLayer }
```text
**4. 延迟初始化**
```typescript
// 不好的做法:全局初始化
const db = new DynamoDBClient({}); // 模块加载时就初始化
export const handler = async (event) => {
// 使用 db
};
// 好的做法:延迟初始化
let db: DynamoDBClient | null = null;
const getDb = () => {
if (!db) {
db = new DynamoDBClient({});
}
return db;
};
export const handler = async (event) => {
const database = getDb(); // 首次调用时才初始化
// 使用 database
};
```text
**5. Provisioned Concurrency**
```yaml
# 预置并发配置
functions:
criticalFunction:
handler: handler.main
provisionedConcurrency: 5 # 保持 5 个实例预热
```text
```text
预置并发效果:
┌─────────────────────────────────────────────────────────────┐
│ │
│ 无预置并发: │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ 请求 → 冷启动 → 执行 → 冷启动 → 执行 → 冷启动 → 执行 │ │
│ └─────────────────────────────────────────────────────┘ │
│ │
│ 有预置并发: │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ [预热实例][预热实例][预热实例] │ │
│ │ 请求 → 热启动 → 执行 → 热启动 → 执行 → 热启动 → 执行 │ │
│ └─────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────┘
```text
**6. 保持函数温暖**
```typescript
// 定时触发器保持函数温暖
export const warmup = async (event: any) => {
// 如果是预热请求,直接返回
if (event.source === 'serverless-plugin-warmup') {
return 'warmup';
}
// 正常业务逻辑
return processBusinessLogic(event);
};
```text
```yaml
# serverless.yml 配置预热
functions:
myFunction:
handler: handler.warmup
events:
- schedule:
rate: rate(5 minutes)
input:
source: serverless-plugin-warmup
```text
## 成本与限制
### 成本模型
**Lambda 定价模型**:
```text
成本 = 请求费用 + 计算费用
请求费用:
- 前 100 万次请求免费
- 之后每 100 万次请求 $0.20
计算费用:
- 内存 × 执行时间 × 请求次数
- 128MB × 100ms × 100 万次 ≈ $0.21
示例计算:
┌─────────────────────────────────────────────────────────────┐
│ 假设: │
│ - 每月 1000 万次请求 │
│ - 平均执行时间 100ms │
│ - 内存配置 512MB │
│ │
│ 请求费用:(1000万 - 100万) × $0.20 / 100万 = $1.80 │
│ 计算费用:1000万 × 0.1s × $0.0000002083 × 4 = $0.83 │
│ 总费用:$1.80 + $0.83 = $2.63/月 │
└─────────────────────────────────────────────────────────────┘
```text
**成本对比**:
```text
EC2 vs Lambda 成本对比(月度):
┌─────────────────────────────────────────────────────────────┐
│ 场景:API 服务,平均 100 QPS,峰值 1000 QPS │
├─────────────────────────────────────────────────────────────┤
│ EC2 (t3.medium × 2) │
│ ├── 实例费用:$60/月 │
│ ├── 负载均衡器:$20/月 │
│ └── 总计:$80/月 │
├─────────────────────────────────────────────────────────────┤
│ Lambda │
│ ├── 请求费用:$5/月 │
│ ├── 计算费用:$15/月 │
│ └── 总计:$20/月 │
├─────────────────────────────────────────────────────────────┤
│ 结论:低流量场景 Lambda 更划算 │
│ 高流量持续负载场景 EC2 可能更经济 │
└─────────────────────────────────────────────────────────────┘
```text
### 服务限制
**Lambda 限制**:
| 限制项 | 默认值 | 可调整 |
|--------|--------|--------|
| 执行时长 | 15 分钟 | 否 |
| 内存 | 128MB - 10GB | 是 |
| 临时存储 | 512MB - 10GB | 是 |
| 部署包大小 (直接上传) | 50MB | 否 |
| 部署包大小 (S3) | 250MB | 否 |
| 环境变量总大小 | 4KB | 否 |
| 并发执行数 | 1000 | 是 (可申请提高) |
**应对策略**:
```typescript
// 执行时长限制应对:拆分长时间任务
export const handler = async (event: any) => {
const timeout = Date.now() + 12000; // 预留 3 秒安全时间
while (hasMoreWork() && Date.now() < timeout) {
await processBatch();
}
if (hasMoreWork()) {
// 触发下一个 Lambda 继续处理
await lambda.send(new InvokeCommand({
FunctionName: process.env.FUNCTION_NAME,
InvocationType: 'Event', // 异步调用
Payload: JSON.stringify({ continueFrom: currentOffset })
}));
}
};
```text
### 适用场景分析
**适合 Serverless 的场景**:
```text
┌─────────────────────────────────────────────────────────────┐
│ │
│ 1. 流量波动大 │
│ ├── 促销活动期间流量激增 │
│ ├── 夜间流量极低 │
│ └── 自动伸缩,按需付费 │
│ │
│ 2. 事件驱动处理 │
│ ├── 文件上传后处理 │
│ ├── 数据库变更触发 │
│ └── 定时任务 │
│ │
│ 3. API 网关后端 │
│ ├── REST API │
│ ├── GraphQL │
│ └── WebSocket │
│ │
│ 4. 数据处理管道 │
│ ├── ETL 任务 │
│ ├── 日志分析 │
│ └── 图像处理 │
│ │
│ 5. 微服务架构 │
│ ├── 小型独立服务 │
│ ├── 快速迭代 │
│ └── 低运维需求 │
│ │
└─────────────────────────────────────────────────────────────┘
```text
**不适合 Serverless 的场景**:
```text
┌─────────────────────────────────────────────────────────────┐
│ │
│ 1. 长时间运行任务 │
│ ├── 视频转码(超过 15 分钟) │
│ ├── 大规模数据处理 │
│ └── 建议:使用 ECS/EC2 │
│ │
│ 2. 高频低延迟要求 │
│ ├── 实时游戏服务器 │
│ ├── 高频交易系统 │
│ └── 建议:使用 EC2/专用服务器 │
│ │
│ 3. 复杂依赖环境 │
│ ├── 需要特定系统库 │
│ ├── 大型机器学习模型 │
│ └── 建议:使用容器服务 │
│ │
│ 4. 持续高负载 │
│ ├── 稳定高流量 │
│ ├── 成本敏感 │
│ └── 建议:使用 EC2 预留实例 │
│ │
│ 5. 需要状态保持 │
│ ├── WebSocket 长连接 │
│ ├── 会话状态管理 │
│ └── 建议:使用 Fargate/ECS │
│ │
└─────────────────────────────────────────────────────────────┘
```text
## 最佳实践
### 函数设计
```typescript
// 单一职责原则
// 好的设计:每个函数做一件事
export const createOrder = async (event: APIGatewayProxyEvent) => {
const order = await orderService.create(event.body);
return successResponse(order);
};
export const processPayment = async (event: SQSEvent) => {
for (const record of event.Records) {
await paymentService.process(JSON.parse(record.body));
}
};
// 不好的设计:一个函数处理多种逻辑
export const orderHandler = async (event: any) => {
if (event.httpMethod === 'POST') {
// 创建订单
} else if (event.httpMethod === 'GET') {
// 查询订单
} else if (event.source === 'aws.sqs') {
// 处理队列消息
}
// 函数变得臃肿,难以维护
};
```text
### 错误处理
```typescript
export const handler = async (event: any) => {
try {
const result = await processEvent(event);
return result;
} catch (error) {
// 结构化错误日志
console.error(JSON.stringify({
level: 'ERROR',
message: error.message,
stack: error.stack,
requestId: event.requestContext?.requestId,
timestamp: new Date().toISOString()
}));
// 根据错误类型返回不同响应
if (error instanceof ValidationError) {
return {
statusCode: 400,
body: JSON.stringify({ message: error.message })
};
}
if (error instanceof NotFoundError) {
return {
statusCode: 404,
body: JSON.stringify({ message: 'Resource not found' })
};
}
// 未知错误
return {
statusCode: 500,
body: JSON.stringify({ message: 'Internal server error' })
};
}
};
```text
### 本地开发与测试
```typescript
// 使用 serverless-offline 本地开发
// 安装:npm install serverless-offline --save-dev
// 本地测试函数
import { handler } from './handler';
describe('Order Handler', () => {
it('should create order successfully', async () => {
const event = {
body: JSON.stringify({
productId: '123',
quantity: 2
})
};
const result = await handler(event);
expect(result.statusCode).toBe(200);
expect(JSON.parse(result.body).orderId).toBeDefined();
});
});
```text
### 监控与告警
```yaml
# CloudWatch 告警配置
Resources:
LambdaErrorAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: LambdaErrorRate
AlarmDescription: Alert on Lambda error rate
MetricName: Errors
Namespace: AWS/Lambda
Statistic: Sum
Period: 60
EvaluationPeriods: 1
Threshold: 5
ComparisonOperator: GreaterThanThreshold
Dimensions:
- Name: FunctionName
Value: myFunction
```text
## 小结
Serverless 架构的核心价值:
**优势**:
- 零运维:无需管理服务器
- 自动伸缩:按需扩展,应对流量波动
- 按需付费:只为实际使用付费
- 快速迭代:专注业务代码开发
**挑战**:
- 冷启动延迟:需要优化策略
- 执行限制:时长、内存、并发限制
- 调试复杂:分布式环境排查困难
- 厂商锁定:依赖特定云服务
**选择建议**:
1. **初创项目**:快速验证,低成本启动
2. **事件驱动**:文件处理、定时任务、消息处理
3. **流量波动大**:自动伸缩应对峰值
4. **微服务架构**:小型独立服务
Serverless 不是万能的,但在合适的场景下,它能显著降低运维成本,提高开发效率。理解其限制,选择合适的场景,才能真正发挥 Serverless 的价值。1
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920