Documentation
¶
Overview ¶
* @Author: kamalyes 501893067@qq.com * @Date: 2025-12-30 13:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2026-01-26 10:36:08 * @FilePath: \go-stress\executor\aliases.go * @Description: executor 模块类型别名 * * Copyright (c) 2025 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2025-12-30 00:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2026-01-26 15:05:00 * @FilePath: \go-stress\executor\api_selector.go * @Description: API选择器 - 支持多API轮询和权重分配 * * Copyright (c) 2025 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2025-12-30 00:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2026-01-26 21:42:01 * @FilePath: \go-stress\executor\builder.go * @Description: 结果构建器 * * Copyright (c) 2025 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2026-01-23 00:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2026-01-23 09:40:00 * @FilePath: \go-stress\executor\controller.go * @Description: 压测控制器接口 * * Copyright (c) 2026 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2026-02-10 16:59:17 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2026-02-10 17:16:35 * @FilePath: \go-stress\executor\csvsource.go * @Description: CSV 数据源的取数游标 * * Copyright (c) 2026 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2025-12-30 00:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2025-12-30 13:30:52 * @FilePath: \go-stress\executor\dependency.go * @Description: API依赖解析和执行顺序管理 * * Copyright (c) 2025 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2025-12-30 00:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2025-12-30 13:25:08 * @FilePath: \go-stress\executor\executor.go * @Description: 压测执行器 - 核心编排器 * * Copyright (c) 2025 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2025-12-30 00:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2026-01-26 19:30:00 * @FilePath: \go-stress\executor\extractor.go * @Description: 数据提取器 - 支持从请求和响应提取,支持数据转换 * * Copyright (c) 2026 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2025-12-30 00:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2025-12-30 13:00:00 * @FilePath: \go-stress\executor\middleware.go * @Description: 中间件实现 * * Copyright (c) 2025 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2025-12-30 00:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2026-01-23 00:00:00 * @FilePath: \go-stress\executor\pool.go * @Description: 客户端连接池(使用 syncx.Pool 优化) * * Copyright (c) 2025 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2025-12-30 00:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2025-12-30 13:00:00 * @FilePath: \go-stress\executor\progress.go * @Description: 进度跟踪器 * * Copyright (c) 2025 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2026-02-10 17:38:26 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2026-02-10 17:55:03 * @FilePath: \go-stress\executor\ratelimit.go * @Description: 目标速率限流(定速压测) * * Copyright (c) 2026 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2026-01-26 00:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2026-01-26 22:00:00 * @FilePath: \go-stress\executor\request_source.go * @Description: 请求源接口 - 统一请求构建(消除单API和多API的冗余区分) * * Copyright (c) 2026 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2026-01-26 00:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2026-01-26 22:30:00 * @FilePath: \go-stress\executor\run_strategy.go * @Description: 运行策略接口 - 消除独立模式和分布式模式的分支判断 * * Copyright (c) 2026 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2026-01-26 00:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2026-01-26 00:00:00 * @FilePath: \go-stress\executor\runner.go * @Description: 通用任务执行器 - 支持独立模式和分布式模式 * * Copyright (c) 2026 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2025-12-30 00:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2025-12-30 12:00:00 * @FilePath: \go-stress\executor\scheduler.go * @Description: Worker调度器 * * Copyright (c) 2025 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2026-02-10 16:58:03 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2026-02-10 17:16:10 * @FilePath: \go-stress\executor\thinktime.go * @Description: 思考时间的等待实现 * * Copyright (c) 2026 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2026-02-10 16:20:08 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2026-02-10 16:50:12 * @FilePath: \go-stress\executor\trace.go * @Description: 请求级 trace 标识生成(W3C trace-context) * * Copyright (c) 2026 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2026-01-26 00:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2026-01-26 23:00:00 * @FilePath: \go-stress\executor\variable_replacer.go * @Description: 变量替换器 - 统一变量解析逻辑 * * Copyright (c) 2026 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2025-12-30 00:00:00 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2026-01-26 20:10:56 * @FilePath: \go-stress\executor\worker.go * @Description: Worker实现 * * Copyright (c) 2025 by kamalyes, All Rights Reserved.
Index ¶
- Constants
- func WaitWhilePaused(ctrl Controller) bool
- type APIConfig
- type APISelector
- type APISource
- type CSVSource
- type Client
- type ClientFactory
- type ClientPool
- type Controller
- type DependencyAPISource
- type DependencyResolver
- func (r *DependencyResolver) GetAPI(name string) *config.APIConfig
- func (r *DependencyResolver) GetAllExtractedVars() map[string]string
- func (r *DependencyResolver) GetExecutionOrder() []string
- func (r *DependencyResolver) GetExtractedVar(apiName, varName string) (string, bool)
- func (r *DependencyResolver) HasDependencies() bool
- func (r *DependencyResolver) IsAPIFailed(apiName string) bool
- func (r *DependencyResolver) MarkAPIFailed(apiName string)
- func (r *DependencyResolver) ShouldSkipAPI(apiName string) bool
- func (r *DependencyResolver) StoreExtractedVars(apiName string, vars map[string]string)
- type DistributedStrategy
- func (d *DistributedStrategy) AfterExecution(exec *Executor, report *statistics.Report) error
- func (d *DistributedStrategy) PrepareContext(baseCtx context.Context) (context.Context, context.CancelFunc, chan os.Signal)
- func (d *DistributedStrategy) WaitForExit(exec *Executor, sigCh chan os.Signal, ctx context.Context)
- type Executor
- func (e *Executor) GetCollector() *statistics.Collector
- func (e *Executor) GetRealtimeServer() *statistics.RealtimeServer
- func (e *Executor) IsDistributed() bool
- func (e *Executor) ReplaceCollector(collector *statistics.Collector)
- func (e *Executor) Run(ctx context.Context) (*statistics.Report, error)
- func (e *Executor) SetStatsReporter(reporter StatsReporter)
- type ExpressionExtractor
- type Extractor
- type ExtractorContext
- type ExtractorManager
- type ExtractorType
- type HeaderExtractor
- type JSONPathExtractor
- type Middleware
- type MiddlewareChain
- type NoOpController
- type ProgressTracker
- type ProtocolType
- type RateLimiter
- type RegexExtractor
- type Request
- type RequestContext
- type RequestHandler
- type RequestResult
- type RequestSource
- type Response
- type Result
- type RunOptions
- type RunResult
- type RunStrategy
- type Scheduler
- type SchedulerConfig
- type StandaloneStrategy
- func (s *StandaloneStrategy) AfterExecution(exec *Executor, report *statistics.Report) error
- func (s *StandaloneStrategy) PrepareContext(baseCtx context.Context) (context.Context, context.CancelFunc, chan os.Signal)
- func (s *StandaloneStrategy) WaitForExit(exec *Executor, sigCh chan os.Signal, ctx context.Context)
- type StatsReporter
- type StorageMode
- type TransformPipeline
- type VariableReplacer
- func (vr *VariableReplacer) GetExtractedVars() map[string]string
- func (vr *VariableReplacer) ReplaceHeaders(headers map[string]string) map[string]string
- func (vr *VariableReplacer) ReplaceInAPIConfig(apiCfg *APIConfig) *APIConfig
- func (vr *VariableReplacer) ReplaceString(s string) string
- func (vr *VariableReplacer) UpdateExtractedVars(vars map[string]string)
- type VerificationResult
- type VerifyConfig
- type VerifyType
- type Worker
- type WorkerConfig
- type WorkerDependencyContext
Constants ¶
const ( ProtocolHTTP = types.ProtocolHTTP ProtocolGRPC = types.ProtocolGRPC ProtocolWebSocket = types.ProtocolWebSocket ExtractorTypeJSONPath = types.ExtractorTypeJSONPath ExtractorTypeRegex = types.ExtractorTypeRegex ExtractorTypeHeader = types.ExtractorTypeHeader ExtractorTypeExpression = types.ExtractorTypeExpression // 存储模式 StorageModeMemory = types.StorageModeMemory StorageModeSQLite = types.StorageModeSQLite StorageModeBadger = types.StorageModeBadger )
常量别名
const HeaderTraceparent = "traceparent"
HeaderTraceparent W3C trace-context 的传播头
用标准头而非自造的 X-Trace-Id:被压服务只要接了任意 OTel SDK 或主流框架的 链路中间件,就会自动把它作为父 span 接上,服务端那条链路与此处的压测结果 共享同一个 trace-id,无需对方改一行代码
Variables ¶
This section is empty.
Functions ¶
Types ¶
type APISelector ¶
type APISelector interface {
// Next 获取下一个API请求配置
Next() *APIConfig
// HasDependencies 是否有依赖关系
HasDependencies() bool
// GetDependencyResolver 获取依赖解析器(如果有依赖)
GetDependencyResolver() *DependencyResolver
}
APISelector API选择器接口
func CreateAPISelector ¶
func CreateAPISelector(cfg *config.Config) APISelector
CreateAPISelector 创建API选择器
func NewDependencySelector ¶
NewDependencySelector 创建依赖选择器
func NewRoundRobinSelector ¶
func NewRoundRobinSelector(apis []config.APIConfig) APISelector
NewRoundRobinSelector 创建轮询选择器
func NewWeightedSelector ¶
func NewWeightedSelector(apis []config.APIConfig) APISelector
NewWeightedSelector 创建加权选择器
type APISource ¶
type APISource struct {
// contains filtered or unexported fields
}
APISource 通用API请求源(支持单个或多个API)
func NewAPISource ¶
func NewAPISource(selector APISelector, log logger.ILogger) *APISource
NewAPISource 创建API请求源(统一入口)
type CSVSource ¶
type CSVSource struct {
// contains filtered or unexported fields
}
CSVSource CSV 数据源的共享部分,由全部 Worker 共用
数据在启动时一次性读入(见 config.LoadCSVData),此处只负责发号: 热路径上仅一次原子自增加一次下标访问,不做文件 IO、解析或分配
type ClientPool ¶
type ClientPool struct {
// contains filtered or unexported fields
}
ClientPool 客户端连接池(使用 syncx.Pool)
func NewClientPool ¶
func NewClientPool(factory ClientFactory, maxSize int) *ClientPool
NewClientPool 创建客户端连接池
type Controller ¶
type Controller interface {
// IsPaused 检查是否暂停
IsPaused() bool
// IsStopped 检查是否停止
IsStopped() bool
}
Controller 压测控制器接口
type DependencyAPISource ¶
type DependencyAPISource struct {
// contains filtered or unexported fields
}
===== 依赖链专用(这个确实有特殊性:需要指定API名称和GroupID) =====
func NewDependencyAPISource ¶
func NewDependencyAPISource(apiName string, resolver *DependencyResolver, groupID uint64, log logger.ILogger) *DependencyAPISource
NewDependencyAPISource 创建依赖链API请求源
func (*DependencyAPISource) NextRequest ¶
func (d *DependencyAPISource) NextRequest() (*APIConfig, uint64, bool)
NextRequest 获取下一个请求配置
type DependencyResolver ¶
type DependencyResolver struct {
// contains filtered or unexported fields
}
DependencyResolver API依赖解析器
func NewDependencyResolver ¶
func NewDependencyResolver(apis []config.APIConfig, log logger.ILogger) (*DependencyResolver, error)
NewDependencyResolver 创建依赖解析器
func (*DependencyResolver) GetAPI ¶
func (r *DependencyResolver) GetAPI(name string) *config.APIConfig
GetAPI 获取API配置
func (*DependencyResolver) GetAllExtractedVars ¶
func (r *DependencyResolver) GetAllExtractedVars() map[string]string
GetAllExtractedVars 获取所有提取的变量(用于变量替换)
func (*DependencyResolver) GetExecutionOrder ¶
func (r *DependencyResolver) GetExecutionOrder() []string
GetExecutionOrder 获取API执行顺序
func (*DependencyResolver) GetExtractedVar ¶
func (r *DependencyResolver) GetExtractedVar(apiName, varName string) (string, bool)
GetExtractedVar 获取提取的变量
func (*DependencyResolver) HasDependencies ¶
func (r *DependencyResolver) HasDependencies() bool
HasDependencies 判断是否有API依赖关系
func (*DependencyResolver) IsAPIFailed ¶
func (r *DependencyResolver) IsAPIFailed(apiName string) bool
IsAPIFailed 检查API是否失败
func (*DependencyResolver) MarkAPIFailed ¶
func (r *DependencyResolver) MarkAPIFailed(apiName string)
MarkAPIFailed 标记API验证失败
func (*DependencyResolver) ShouldSkipAPI ¶
func (r *DependencyResolver) ShouldSkipAPI(apiName string) bool
ShouldSkipAPI 检查是否应该跳过该API(因为依赖的API失败)
func (*DependencyResolver) StoreExtractedVars ¶
func (r *DependencyResolver) StoreExtractedVars(apiName string, vars map[string]string)
StoreExtractedVars 存储提取的变量
type DistributedStrategy ¶
type DistributedStrategy struct {
// contains filtered or unexported fields
}
DistributedStrategy 分布式模式策略(Slave节点)
func NewDistributedStrategy ¶
func NewDistributedStrategy(externalCtx context.Context) *DistributedStrategy
NewDistributedStrategy 创建分布式模式策略
func (*DistributedStrategy) AfterExecution ¶
func (d *DistributedStrategy) AfterExecution(exec *Executor, report *statistics.Report) error
AfterExecution 分布式模式的后处理(不做任何操作,由Master统一处理)
func (*DistributedStrategy) PrepareContext ¶
func (d *DistributedStrategy) PrepareContext(baseCtx context.Context) (context.Context, context.CancelFunc, chan os.Signal)
PrepareContext 准备分布式模式的上下文(使用外部传入的context)
func (*DistributedStrategy) WaitForExit ¶
func (d *DistributedStrategy) WaitForExit(exec *Executor, sigCh chan os.Signal, ctx context.Context)
WaitForExit 分布式模式的等待退出(不等待,由Master控制)
type Executor ¶
type Executor struct {
// contains filtered or unexported fields
}
Executor 压测执行器(核心编排器) 职责: 1. 组装各个组件(连接池、中间件、调度器) 2. 编排整体压测流程 3. 生成最终报告
func NewExecutor ¶
func NewExecutor(cfg *config.Config, storageMode StorageMode, storagePath string, log logger.ILogger) (*Executor, error)
NewExecutor 根据存储模式创建执行器(使用存储工厂)
func (*Executor) GetCollector ¶
func (e *Executor) GetCollector() *statistics.Collector
GetCollector 获取统计收集器
func (*Executor) GetRealtimeServer ¶
func (e *Executor) GetRealtimeServer() *statistics.RealtimeServer
GetRealtimeServer 获取实时报告服务器
func (*Executor) ReplaceCollector ¶
func (e *Executor) ReplaceCollector(collector *statistics.Collector)
ReplaceCollector 替换 Collector(用于分布式模式重用 Collector)
func (*Executor) SetStatsReporter ¶
func (e *Executor) SetStatsReporter(reporter StatsReporter)
SetStatsReporter 设置统计上报器(用于分布式模式)
type ExpressionExtractor ¶
type ExpressionExtractor struct {
// contains filtered or unexported fields
}
func NewExpressionExtractor ¶
func NewExpressionExtractor(expression string) (*ExpressionExtractor, error)
func (*ExpressionExtractor) Extract ¶
func (e *ExpressionExtractor) Extract(ctx *ExtractorContext) (string, error)
type Extractor ¶
type Extractor interface {
Extract(ctx *ExtractorContext) (string, error)
}
Extractor 提取器接口
type ExtractorContext ¶
type ExtractorContext struct {
Request *Request
Response *types.Response
Variables map[string]string
}
ExtractorContext 提取器上下文
type ExtractorManager ¶
type ExtractorManager struct {
// contains filtered or unexported fields
}
func NewExtractorManager ¶
func NewExtractorManager(configs []config.ExtractorConfig, log logger.ILogger) (*ExtractorManager, error)
func (*ExtractorManager) ExtractAll ¶
func (m *ExtractorManager) ExtractAll(ctx *ExtractorContext, defaultValues map[string]string) map[string]string
type HeaderExtractor ¶
type HeaderExtractor struct {
// contains filtered or unexported fields
}
func NewHeaderExtractor ¶
func NewHeaderExtractor(headerName string, source config.ExtractorSource) *HeaderExtractor
func (*HeaderExtractor) Extract ¶
func (e *HeaderExtractor) Extract(ctx *ExtractorContext) (string, error)
type JSONPathExtractor ¶
type JSONPathExtractor struct {
// contains filtered or unexported fields
}
func NewJSONPathExtractor ¶
func NewJSONPathExtractor(path string, source config.ExtractorSource) *JSONPathExtractor
func (*JSONPathExtractor) Extract ¶
func (e *JSONPathExtractor) Extract(ctx *ExtractorContext) (string, error)
type Middleware ¶
type Middleware = types.Middleware
类型别名 - 从 types 包导入
func BreakerMiddleware ¶
func BreakerMiddleware(circuit *breaker.Circuit) Middleware
BreakerMiddleware 熔断中间件
func RetryMiddleware ¶
func RetryMiddleware(retrier *retry.Runner[error]) Middleware
RetryMiddleware 重试中间件
func VerifyMiddleware ¶
func VerifyMiddleware(verifier verify.Verifier) Middleware
VerifyMiddleware 验证中间件
type MiddlewareChain ¶
type MiddlewareChain struct {
// contains filtered or unexported fields
}
MiddlewareChain 中间件链
func (*MiddlewareChain) Build ¶
func (mc *MiddlewareChain) Build(handler RequestHandler) RequestHandler
Build 构建最终的处理器
func (*MiddlewareChain) Use ¶
func (mc *MiddlewareChain) Use(m Middleware) *MiddlewareChain
Use 添加中间件
type NoOpController ¶
type NoOpController struct{}
NoOpController 空操作控制器(默认实现)
func (*NoOpController) IsPaused ¶
func (n *NoOpController) IsPaused() bool
func (*NoOpController) IsStopped ¶
func (n *NoOpController) IsStopped() bool
type ProgressTracker ¶
type ProgressTracker struct {
// contains filtered or unexported fields
}
ProgressTracker 进度跟踪器
func NewProgressTracker ¶
func NewProgressTracker(total uint64, log logger.ILogger) *ProgressTracker
NewProgressTracker 创建进度跟踪器
func NewProgressTrackerWithCollector ¶
func NewProgressTrackerWithCollector(total uint64, collector *statistics.Collector, workerCount uint64, log logger.ILogger) *ProgressTracker
NewProgressTrackerWithCollector 创建带统计收集器的进度跟踪器
func (*ProgressTracker) GetProgress ¶
func (pt *ProgressTracker) GetProgress() (completed, total uint64, percentage float64)
GetProgress 获取当前进度
func (*ProgressTracker) Start ¶
func (pt *ProgressTracker) Start(ctx context.Context)
Start 启动进度显示 - 使用 EventLoop
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter 把全部 Worker 的发压速率约束到目标 QPS
为什么需要它:不限速的压测是「有多快打多快」,施加的压力取决于被测系统的 响应速度——系统一变慢,压力自己就降下来了,于是永远测不出「在固定 100 QPS 下延迟如何」。定速(开环)是容量规划与 SLO 验证的基本手段,也是 JMeter 的 ConstantThroughputTimer 所表达的语义
实现取匀速发牌而非令牌桶:桶会允许攒够的令牌一次性放行,造成尖刺, 而压测要的是平稳的到达率。每张牌的时刻由序号推算(start + n*interval), 不做增量累加,避免误差逐次累积
func NewRateLimiter ¶
func NewRateLimiter(qps float64) *RateLimiter
NewRateLimiter 创建限流器,qps <= 0 时返回 nil 表示不限速
type RegexExtractor ¶
type RegexExtractor struct {
// contains filtered or unexported fields
}
func NewRegexExtractor ¶
func NewRegexExtractor(pattern string, source config.ExtractorSource) (*RegexExtractor, error)
func (*RegexExtractor) Extract ¶
func (e *RegexExtractor) Extract(ctx *ExtractorContext) (string, error)
type RequestContext ¶
type RequestContext struct {
Source RequestSource
APIConfig *APIConfig
GroupID uint64
IsDependency bool
WorkerID uint64
WorkerDepCtx *WorkerDependencyContext
ShouldSkip bool
SkipReason string
FailedDeps []string
}
RequestContext 请求执行上下文(统一的执行信息)
func NewRequestContext ¶
func NewRequestContext(source RequestSource, workerID uint64, depCtx *WorkerDependencyContext) (*RequestContext, error)
NewRequestContext 创建请求执行上下文
type RequestHandler ¶
type RequestHandler = types.RequestHandler
类型别名 - 从 types 包导入
func ClientMiddleware ¶
func ClientMiddleware(client Client) RequestHandler
ClientMiddleware 客户端执行中间件(最底层)
type RequestResult ¶
type RequestResult = types.RequestResult
统计相关
func BuildRequestResult ¶
func BuildRequestResult(resp *Response, err error) *RequestResult
BuildRequestResult 构建请求结果
type RequestSource ¶
type RequestSource interface {
// NextRequest 获取下一个请求配置
// 返回: apiConfig, groupID, isFromDependency
NextRequest() (*APIConfig, uint64, bool)
// Name 获取当前请求的名称(用于日志)
Name() string
}
RequestSource 请求源接口(统一所有模式)
type RunOptions ¶
type RunOptions struct {
// === 配置来源(三选一) ===
ConfigFile string // 配置文件路径
CurlFile string // curl 文件路径
JMXFile string // JMeter .jmx 脚本路径
JMXLossy bool // 允许 .jmx 中存在会改变负载的丢失项
ConfigFunc func() *config.Config // 从命令行构建配置的函数
// === 运行时参数 ===
Concurrency uint64 // 并发数(可覆盖配置文件)
Requests uint64 // 请求数(可覆盖配置文件)
Timeout time.Duration // 超时时间(可覆盖配置文件)
Duration time.Duration // 压测持续时间,非零时优先于 Requests
// === 存储配置 ===
StorageMode StorageMode // 存储模式
ReportPrefix string // 报告文件前缀
MaxMemory string // 内存阈值
// === 日志配置 ===
Logger logger.ILogger // 日志器
// === 分布式模式专用 ===
IsDistributed bool // 是否为分布式模式
ExternalContext context.Context // 外部传入的 context(用于 Slave 控制)
ExternalCollector *statistics.Collector // 外部 Collector(Slave 模式使用)
NoReport bool // 不生成报告文件(Slave 模式与 -no-report 使用)
NoPrint bool // 不打印报告(Slave 模式与 -no-print 使用)
NoWait bool // 不等待退出(Slave 模式与 -no-wait 使用)
}
RunOptions 任务执行选项(通用,支持独立模式和分布式模式)
type RunResult ¶
type RunResult struct {
Report *statistics.Report
Executor *Executor
Error error
}
RunResult 任务执行结果
type RunStrategy ¶
type RunStrategy interface {
// PrepareContext 准备执行上下文和信号处理
PrepareContext(baseCtx context.Context) (context.Context, context.CancelFunc, chan os.Signal)
// AfterExecution 执行完成后的处理(打印报告、保存文件等)
AfterExecution(exec *Executor, report *statistics.Report) error
// WaitForExit 等待退出
WaitForExit(exec *Executor, sigCh chan os.Signal, ctx context.Context)
}
RunStrategy 运行策略接口(策略模式)
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler Worker调度器
type SchedulerConfig ¶
type SchedulerConfig struct {
WorkerCount uint64
RequestPerWorker uint64
RampUpDuration time.Duration
ClientPool *ClientPool
Handler RequestHandler
Collector *statistics.Collector
APISelector APISelector // API选择器(必需)
VarResolver *config.VariableResolver // 变量解析器
Controller Controller // 控制器(可选)
Logger logger.ILogger
InjectTraceHeader bool // 是否向请求注入 traceparent 头
ThinkTime *config.ThinkTimeConfig // 全局思考时间(可选)
CSVSource *CSVSource // CSV 数据源(可选)
Limiter *RateLimiter // 速率限流器(可选)
}
SchedulerConfig 调度器配置
type StandaloneStrategy ¶
type StandaloneStrategy struct {
// contains filtered or unexported fields
}
StandaloneStrategy 独立模式策略
func NewStandaloneStrategy ¶
func NewStandaloneStrategy(logger logger.ILogger, reportPrefix string, noPrint, noReport, noWait bool) *StandaloneStrategy
NewStandaloneStrategy 创建独立模式策略
func (*StandaloneStrategy) AfterExecution ¶
func (s *StandaloneStrategy) AfterExecution(exec *Executor, report *statistics.Report) error
AfterExecution 独立模式的后处理(打印报告、保存文件)
func (*StandaloneStrategy) PrepareContext ¶
func (s *StandaloneStrategy) PrepareContext(baseCtx context.Context) (context.Context, context.CancelFunc, chan os.Signal)
PrepareContext 准备独立模式的上下文(带信号监听)
func (*StandaloneStrategy) WaitForExit ¶
WaitForExit 独立模式的等待退出
type StatsReporter ¶
type StatsReporter interface {
Add(result *RequestResult)
SetTaskID(taskID string)
}
StatsReporter 统计上报接口(用于分布式模式)
type TransformPipeline ¶
type TransformPipeline struct {
// contains filtered or unexported fields
}
func NewTransformPipeline ¶
func NewTransformPipeline(resolver *config.VariableResolver) *TransformPipeline
func (*TransformPipeline) Apply ¶
func (p *TransformPipeline) Apply(value string, transforms []config.TransformConfig) (string, error)
type VariableReplacer ¶
type VariableReplacer struct {
// contains filtered or unexported fields
}
VariableReplacer 变量替换器(统一处理动态变量和提取变量)
func NewVariableReplacer ¶
func NewVariableReplacer(resolver *config.VariableResolver, extractedVars map[string]string) *VariableReplacer
NewVariableReplacer 创建变量替换器
func (*VariableReplacer) GetExtractedVars ¶
func (vr *VariableReplacer) GetExtractedVars() map[string]string
GetExtractedVars 获取所有提取的变量
func (*VariableReplacer) ReplaceHeaders ¶
func (vr *VariableReplacer) ReplaceHeaders(headers map[string]string) map[string]string
ReplaceHeaders 替换 Headers 中的变量(返回新的 map)
func (*VariableReplacer) ReplaceInAPIConfig ¶
func (vr *VariableReplacer) ReplaceInAPIConfig(apiCfg *APIConfig) *APIConfig
ReplaceInAPIConfig 替换 API 配置中的所有变量
func (*VariableReplacer) ReplaceString ¶
func (vr *VariableReplacer) ReplaceString(s string) string
ReplaceString 替换字符串中的变量(两步:1.提取变量 2.动态变量)
func (*VariableReplacer) UpdateExtractedVars ¶
func (vr *VariableReplacer) UpdateExtractedVars(vars map[string]string)
UpdateExtractedVars 更新提取的变量
type Worker ¶
type Worker struct {
// contains filtered or unexported fields
}
Worker 工作单元
func NewWorker ¶
func NewWorker(cfg WorkerConfig, varResolver *config.VariableResolver) *Worker
NewWorker 创建Worker
type WorkerConfig ¶
type WorkerConfig struct {
ID uint64
Client Client
Handler RequestHandler
Collector *statistics.Collector
ReqCount uint64
APISelector APISelector // API选择器(必需)
Controller Controller // 控制器(可选)
Logger logger.ILogger
InjectTraceHeader bool // 是否向请求注入 traceparent 头
ThinkTime *config.ThinkTimeConfig // 全局思考时间(可选)
CSVSource *CSVSource // CSV 数据源(可选,全部 Worker 共享)
Limiter *RateLimiter // 速率限流器(可选,全部 Worker 共享)
}
WorkerConfig Worker配置
type WorkerDependencyContext ¶
type WorkerDependencyContext struct {
// contains filtered or unexported fields
}
WorkerDependencyContext 每个 worker 的本地依赖上下文
func NewWorkerDependencyContext ¶
func NewWorkerDependencyContext() *WorkerDependencyContext
NewWorkerDependencyContext 创建新的依赖上下文