Skip to content

Commit

Permalink
feat: worker default ema config (#103)
Browse files Browse the repository at this point in the history
FEAT: AONE#54578464
  • Loading branch information
mariodu authored Jan 24, 2024
1 parent 7105bf7 commit 828ae00
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
14 changes: 14 additions & 0 deletions src/config/default.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ConcurrencyStatsMode } from '#self/lib/json/function_profile';
import path from 'path';

const projectRoot = path.resolve(__dirname, '../../');
Expand Down Expand Up @@ -42,6 +43,19 @@ export default {
maxActivateRequests: 10,
defaultInitializerTimeout: 10_000,
replicaCountLimit: 10,

// ema 相关默认值
concurrencySlidingWindowSize: 60_000,
concurrencySlidingBucketCount: 6,
emaConcurrencyAlpha: 0.5,
concurrencyExpandThreshold: 0.7,
concurrencyShrinkThreshold: 0.3,
expandCooldown: 1000,
shrinkCooldown: 60_000,
scaleFactor: 0.5,
precisionZeroThreshold: 0.01,
concurrencyStatsMode: ConcurrencyStatsMode.INSTANT,
shrinkCooldownOnStartup: true,
},
starter: {
aworker: {
Expand Down
24 changes: 24 additions & 0 deletions src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { LoggerLevel } from '@midwayjs/logger';
import type { ChannelOptions } from '@grpc/grpc-js';
import { resolveConfig } from './loader';
import { ConcurrencyStatsMode } from '#self/lib/json/function_profile';

export const config = resolveConfig();
export { dumpConfig } from './loader';
Expand Down Expand Up @@ -204,6 +205,29 @@ export interface WorkerDefaultConfig {
* 默认为 10
*/
replicaCountLimit: number;

// 并发度滑动时间窗口大小,单位 ms,默认 60s
concurrencySlidingWindowSize?: number;
// 并发度滑动时间窗口分桶数,默认 6
concurrencySlidingBucketCount?: number;
// 指数移动平均平滑系数 (0,1],默认 0.5
emaConcurrencyAlpha?: number;
// 并发度扩容水位阈值,默认 0.7
concurrencyExpandThreshold?: number;
// 并发度缩容水位阈值,默认 0.3
concurrencyShrinkThreshold?: number;
// 扩容冷却时间,单位 ms,默认 1s
expandCooldown?: number;
// 缩容冷却时间,单位 ms,默认 60s
shrinkCooldown?: number;
// 扩缩容后并发度水位,影响扩缩容操作数量
scaleFactor?: number;
// ema concurrency 小于该值则视为 0
precisionZeroThreshold?: number;
// worker 并发度统计算法,默认为 ConcurrencyStatsMode.INSTANT
concurrencyStatsMode?: ConcurrencyStatsMode;
// 启动后是否进入缩容冷却期,默认为 true
shrinkCooldownOnStartup?: boolean;
}

export interface StarterConfig {
Expand Down
14 changes: 14 additions & 0 deletions src/lib/function_profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ function buildProfile(
disableRequestQueue: false,
v8Options: [],
execArgv: [],

concurrencySlidingWindowSize: config.worker.concurrencySlidingWindowSize,
concurrencySlidingBucketCount:
config.worker.concurrencySlidingBucketCount,
emaConcurrencyAlpha: config.worker.emaConcurrencyAlpha,
concurrencyExpandThreshold: config.worker.concurrencyExpandThreshold,
concurrencyShrinkThreshold: config.worker.concurrencyShrinkThreshold,
expandCooldown: config.worker.expandCooldown,
shrinkCooldown: config.worker.shrinkCooldown,
scaleFactor: config.worker.scaleFactor,
precisionZeroThreshold: config.worker.precisionZeroThreshold,
concurrencyStatsMode: config.worker.concurrencyStatsMode,
shrinkCooldownOnStartup: config.worker.shrinkCooldownOnStartup,

...(json.worker ?? {}),
},
environments: json.environments ?? [],
Expand Down
6 changes: 3 additions & 3 deletions src/lib/json/function_profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ export interface ProcessFunctionProfile {
expandCooldown?: number;
// 缩容冷却时间,单位 ms,默认 60s
shrinkCooldown?: number;
// 扩缩容后并发度水位,影响扩缩容操作数量
// 扩缩容后并发度水位,影响扩缩容操作数量,默认为 0.5
scaleFactor?: number;
// ema concurrency 小于该值则视为 0
// ema concurrency 小于该值则视为 0,默认为 0.01
precisionZeroThreshold?: number;
// worker 并发度统计算法
// worker 并发度统计算法,默认为 ConcurrencyStatsMode.INSTANT
concurrencyStatsMode?: ConcurrencyStatsMode;
// 启动后是否进入缩容冷却期,默认为 true
shrinkCooldownOnStartup?: boolean;
Expand Down

0 comments on commit 828ae00

Please sign in to comment.