executor

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 22, 2026 License: Apache-2.0 Imports: 39 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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
)

常量别名

View Source
const HeaderTraceparent = "traceparent"

HeaderTraceparent W3C trace-context 的传播头

用标准头而非自造的 X-Trace-Id:被压服务只要接了任意 OTel SDK 或主流框架的 链路中间件,就会自动把它作为父 span 接上,服务端那条链路与此处的压测结果 共享同一个 trace-id,无需对方改一行代码

Variables

This section is empty.

Functions

func WaitWhilePaused

func WaitWhilePaused(ctrl Controller) bool

WaitWhilePaused 等待直到不再暂停或停止

Types

type APIConfig

type APIConfig = config.APIConfig

配置相关 - 直接使用 config.APIConfig,不再转换

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

func NewDependencySelector(apis []config.APIConfig, log logger.ILogger) (APISelector, error)

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请求源(统一入口)

func (*APISource) Name

func (s *APISource) Name() string

Name 获取当前请求的名称

func (*APISource) NextRequest

func (s *APISource) NextRequest() (*APIConfig, uint64, bool)

NextRequest 获取下一个请求配置

type CSVSource

type CSVSource struct {
	// contains filtered or unexported fields
}

CSVSource CSV 数据源的共享部分,由全部 Worker 共用

数据在启动时一次性读入(见 config.LoadCSVData),此处只负责发号: 热路径上仅一次原子自增加一次下标访问,不做文件 IO、解析或分配

func NewCSVSource

func NewCSVSource(data *config.CSVData) *CSVSource

NewCSVSource 基于已载入的数据创建共享源

func (*CSVSource) Recycle

func (s *CSVSource) Recycle() bool

Recycle 返回数据用尽后是否回绕

func (*CSVSource) RowCount

func (s *CSVSource) RowCount() int

RowCount 返回数据行数

func (*CSVSource) Sharing

func (s *CSVSource) Sharing() config.CSVSharing

Sharing 返回游标共享方式

func (*CSVSource) Variables

func (s *CSVSource) Variables() []string

Variables 返回变量名列表

type Client

type Client = types.Client

协议相关

type ClientFactory

type ClientFactory = types.ClientFactory

类型别名 - 从 types 包导入

type ClientPool

type ClientPool struct {
	// contains filtered or unexported fields
}

ClientPool 客户端连接池(使用 syncx.Pool)

func NewClientPool

func NewClientPool(factory ClientFactory, maxSize int) *ClientPool

NewClientPool 创建客户端连接池

func (*ClientPool) Close

func (cp *ClientPool) Close()

Close 关闭连接池

func (*ClientPool) Get

func (cp *ClientPool) Get() (Client, error)

Get 从池中获取客户端

func (*ClientPool) Put

func (cp *ClientPool) Put(client Client)

Put 将客户端放回池中

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) Name

func (d *DependencyAPISource) Name() string

Name 获取当前请求的名称

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) IsDistributed

func (e *Executor) IsDistributed() bool

IsDistributed 是否为分布式模式

func (*Executor) ReplaceCollector

func (e *Executor) ReplaceCollector(collector *statistics.Collector)

ReplaceCollector 替换 Collector(用于分布式模式重用 Collector)

func (*Executor) Run

func (e *Executor) Run(ctx context.Context) (*statistics.Report, error)

Run 执行压测

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 ExtractorType

type ExtractorType = types.ExtractorType

类型别名 - 从 types 包导入

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 NewMiddlewareChain

func NewMiddlewareChain() *MiddlewareChain

NewMiddlewareChain 创建中间件链

func (*MiddlewareChain) Build

func (mc *MiddlewareChain) Build(handler RequestHandler) RequestHandler

Build 构建最终的处理器

func (*MiddlewareChain) Use

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) Complete

func (pt *ProgressTracker) Complete()

Complete 完成并打印底部边框

func (*ProgressTracker) GetProgress

func (pt *ProgressTracker) GetProgress() (completed, total uint64, percentage float64)

GetProgress 获取当前进度

func (*ProgressTracker) Increment

func (pt *ProgressTracker) Increment() uint64

Increment 增加完成数

func (*ProgressTracker) Start

func (pt *ProgressTracker) Start(ctx context.Context)

Start 启动进度显示 - 使用 EventLoop

type ProtocolType

type ProtocolType = types.ProtocolType

类型别名 - 从 types 包导入

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 表示不限速

func (*RateLimiter) QPS

func (r *RateLimiter) QPS() float64

QPS 返回配置的目标速率

func (*RateLimiter) Wait

func (r *RateLimiter) Wait(ctx context.Context) bool

Wait 阻塞到允许发出下一个请求为止

返回 false 表示等待期间 ctx 已取消。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 Request

type Request = types.Request

类型别名 - 从 types 包导入

func BuildRequest

func BuildRequest(apiCfg *APIConfig) *Request

BuildRequest 从API配置构建请求

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 Response

type Response = types.Response

类型别名 - 从 types 包导入

type Result

type Result = types.Result

执行器相关

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 任务执行结果

func RunTask

func RunTask(opts RunOptions) *RunResult

RunTask 执行压测任务(使用策略模式,消除分支判断)

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调度器

func NewScheduler

func NewScheduler(cfg SchedulerConfig) *Scheduler

NewScheduler 创建调度器

func (*Scheduler) Run

func (s *Scheduler) Run(ctx context.Context) error

Run 运行调度器

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

func (s *StandaloneStrategy) WaitForExit(exec *Executor, sigCh chan os.Signal, ctx context.Context)

WaitForExit 独立模式的等待退出

type StatsReporter

type StatsReporter interface {
	Add(result *RequestResult)
	SetTaskID(taskID string)
}

StatsReporter 统计上报接口(用于分布式模式)

type StorageMode

type StorageMode = types.StorageMode

存储相关

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 VerificationResult

type VerificationResult = types.VerificationResult

验证结果

type VerifyConfig

type VerifyConfig = config.VerifyConfig

类型别名 - 从 types 包导入

type VerifyType

type VerifyType = types.VerifyType

验证相关

type Worker

type Worker struct {
	// contains filtered or unexported fields
}

Worker 工作单元

func NewWorker

func NewWorker(cfg WorkerConfig, varResolver *config.VariableResolver) *Worker

NewWorker 创建Worker

func (*Worker) Run

func (w *Worker) Run(ctx context.Context) error

Run 运行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 创建新的依赖上下文

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL