Compare commits
3
Commits
main
...
191785021e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
191785021e | ||
|
|
1838c1d559 | ||
|
|
a6f82d5a0b |
No files matched your search
@@ -0,0 +1,3 @@
|
||||
/bin/
|
||||
*.exe
|
||||
*.log
|
||||
@@ -0,0 +1 @@
|
||||
production.md是产品需求设计文档,功能实现都必须参考它。
|
||||
@@ -1,52 +1,11 @@
|
||||
# LLM API 基准测试工具
|
||||
# llm-api-benchmark-tool
|
||||
|
||||
这是一个用于测试兼容OpenAI风格API的LLM性能基准测试工具。该工具支持动态生成提示词、高并发请求和详细的性能报告。
|
||||
基于 Go 的 LLM API 压测工具。
|
||||
|
||||
## 功能特点
|
||||
目录结构:
|
||||
|
||||
- **API兼容性**:支持OpenAI Compatible风格的LLM API
|
||||
- **提示词生成**:
|
||||
- 集成tiktoken-go/tokenizer
|
||||
- 自动生成短咨询提示词(50 tokens ±5%)和长文档提示词(1000 tokens ±5%)
|
||||
- 基于模板动态调整至目标Token数
|
||||
- **并发请求**:支持高并发异步请求,模拟真实负载
|
||||
- **场景建模**:支持混合负载(短咨询70%,长文档30%)
|
||||
- **用户行为模拟**:请求间隔遵循泊松分布
|
||||
- **梯度增压**:支持阶梯式加压(50→200→500并发)
|
||||
- **性能指标收集**:响应时间、QPS、Token生成速率等
|
||||
- **报告生成**:生成包含性能指标统计和可视化图表的质量报告
|
||||
|
||||
## 安装
|
||||
|
||||
```bash
|
||||
git clone https://github.com/yourusername/llm-api-benchmark-tool.git
|
||||
cd llm-api-benchmark-tool
|
||||
go mod download
|
||||
```
|
||||
|
||||
## 使用方法
|
||||
|
||||
1. 配置 `config.yaml` 文件:
|
||||
|
||||
```yaml
|
||||
api:
|
||||
endpoint: "https://api.example.com/v1/completions"
|
||||
api_key: "your_api_key"
|
||||
model: "gpt-3.5-turbo"
|
||||
cmd/ # 可执行程序入口
|
||||
pkg/httpclient/ # HTTPClient 接口及实现
|
||||
internal/config/ # 配置加载模块
|
||||
```
|
||||
|
||||
2. 运行测试:
|
||||
|
||||
```bash
|
||||
go run main.go -config config.yaml
|
||||
```
|
||||
|
||||
3. 查看生成的报告(位于 `reports` 目录)
|
||||
|
||||
## 配置说明
|
||||
|
||||
详细配置选项请参考 [配置文档](docs/configuration.md)。
|
||||
|
||||
## 许可证
|
||||
|
||||
MIT
|
||||
@@ -1,673 +0,0 @@
|
||||
package benchmark
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
"math/rand"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/montanaflynn/stats"
|
||||
"github.com/valyala/fasthttp"
|
||||
|
||||
"github.com/acmestudio/llm-api-benchmark-tool/config"
|
||||
"github.com/acmestudio/llm-api-benchmark-tool/logger"
|
||||
"github.com/acmestudio/llm-api-benchmark-tool/prompt"
|
||||
)
|
||||
|
||||
// Benchmark 表示基准测试执行器
|
||||
type Benchmark struct {
|
||||
config *config.Config
|
||||
generator *prompt.Generator
|
||||
client *fasthttp.Client
|
||||
rand *rand.Rand
|
||||
}
|
||||
|
||||
// Response 表示API响应
|
||||
type Response struct {
|
||||
ID string `json:"id"`
|
||||
Object string `json:"object"`
|
||||
Created int64 `json:"created"`
|
||||
Model string `json:"model"`
|
||||
Choices []Choice `json:"choices"`
|
||||
Usage Usage `json:"usage"`
|
||||
}
|
||||
|
||||
// StreamResponse 表示流式API响应
|
||||
type StreamResponse struct {
|
||||
ID string `json:"id"`
|
||||
Object string `json:"object"`
|
||||
Created int64 `json:"created"`
|
||||
Model string `json:"model"`
|
||||
Choices []StreamChoice `json:"choices"`
|
||||
}
|
||||
|
||||
// StreamChoice 表示流式响应中的选择
|
||||
type StreamChoice struct {
|
||||
Delta StreamDelta `json:"delta"`
|
||||
Index int `json:"index"`
|
||||
FinishReason string `json:"finish_reason"`
|
||||
}
|
||||
|
||||
// StreamDelta 表示流式响应中的增量内容
|
||||
type StreamDelta struct {
|
||||
Role string `json:"role"`
|
||||
Content string `json:"content"`
|
||||
}
|
||||
|
||||
// Choice 表示API响应中的选择
|
||||
type Choice struct {
|
||||
Message Message `json:"message"`
|
||||
Index int `json:"index"`
|
||||
FinishReason string `json:"finish_reason"`
|
||||
}
|
||||
|
||||
// Message 表示聊天消息
|
||||
type Message struct {
|
||||
Role string `json:"role"`
|
||||
Content string `json:"content"`
|
||||
}
|
||||
|
||||
// Usage 表示API响应中的使用情况
|
||||
type Usage struct {
|
||||
PromptTokens int `json:"prompt_tokens"`
|
||||
CompletionTokens int `json:"completion_tokens"`
|
||||
TotalTokens int `json:"total_tokens"`
|
||||
}
|
||||
|
||||
// Request 表示API请求
|
||||
type Request struct {
|
||||
Model string `json:"model"`
|
||||
Messages []Message `json:"messages"`
|
||||
MaxTokens int `json:"max_tokens"`
|
||||
Temperature float64 `json:"temperature"`
|
||||
Stream bool `json:"stream"`
|
||||
}
|
||||
|
||||
// Result 表示单个API请求的结果
|
||||
type Result struct {
|
||||
Timestamp time.Time // 请求时间戳
|
||||
Concurrency int // 并发级别
|
||||
PromptType string // 提示词类型 (short/long)
|
||||
PromptTokenCount int // 提示词token数量
|
||||
PromptTokens int // 提示词token数量(API返回)
|
||||
CompletionTokens int // 完成token数量
|
||||
TotalTokens int // 总token数量
|
||||
ResponseTime time.Duration // 响应时间
|
||||
Response string // 响应内容
|
||||
Error error // 错误信息
|
||||
}
|
||||
|
||||
// BenchmarkResults 表示基准测试结果
|
||||
type BenchmarkResults struct {
|
||||
Results []Result // 所有请求结果
|
||||
StartTime time.Time // 开始时间
|
||||
EndTime time.Time // 结束时间
|
||||
Config *config.Config // 配置信息
|
||||
ConcurrencyData map[int][]Result // 按并发步骤分组的结果
|
||||
TotalRequests int // 总请求数
|
||||
SuccessRequests int // 成功请求数
|
||||
FailedRequests int // 失败请求数
|
||||
AvgResponseTime time.Duration // 平均响应时间
|
||||
P50ResponseTime time.Duration // 响应时间50百分位
|
||||
P90ResponseTime time.Duration // 响应时间90百分位
|
||||
P99ResponseTime time.Duration // 响应时间99百分位
|
||||
QPS float64 // 每秒请求数
|
||||
AvgPromptTokens int // 平均提示词token数
|
||||
AvgCompletionTokens int // 平均完成token数
|
||||
AvgTotalTokens int // 平均总token数
|
||||
AvgTokenRate float64 // 平均token生成速率
|
||||
}
|
||||
|
||||
// NewBenchmark 创建新的基准测试执行器
|
||||
func NewBenchmark(cfg *config.Config) (*Benchmark, error) {
|
||||
// 初始化提示词生成器
|
||||
logger.Debug("初始化提示词生成器...")
|
||||
gen, err := prompt.NewGenerator(cfg)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("初始化提示词生成器失败: %w", err)
|
||||
}
|
||||
logger.Debug("提示词生成器初始化成功")
|
||||
|
||||
// 初始化HTTP客户端
|
||||
logger.Debug("初始化HTTP客户端...")
|
||||
client := &fasthttp.Client{
|
||||
MaxConnsPerHost: 10000,
|
||||
ReadTimeout: time.Duration(cfg.Timeout) * time.Second,
|
||||
WriteTimeout: time.Duration(cfg.Timeout) * time.Second,
|
||||
}
|
||||
logger.Debug("HTTP客户端初始化成功,超时设置: %d秒", cfg.Timeout)
|
||||
|
||||
// 初始化随机数生成器
|
||||
source := rand.NewSource(time.Now().UnixNano())
|
||||
|
||||
return &Benchmark{
|
||||
config: cfg,
|
||||
generator: gen,
|
||||
client: client,
|
||||
rand: rand.New(source),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Run 执行基准测试
|
||||
func (b *Benchmark) Run() (*BenchmarkResults, error) {
|
||||
// 创建结果对象
|
||||
results := &BenchmarkResults{
|
||||
StartTime: time.Now(),
|
||||
Config: b.config,
|
||||
ConcurrencyData: make(map[int][]Result),
|
||||
}
|
||||
|
||||
// 执行每个并发步骤
|
||||
for _, concurrency := range b.config.Concurrency.Steps {
|
||||
logger.Info("开始执行并发步骤: %d 并发用户", concurrency)
|
||||
logger.Info("预计持续时间: %d秒", b.config.Concurrency.DurationPerStep)
|
||||
|
||||
// 执行单个并发步骤
|
||||
stepResults, err := b.runConcurrencyStep(concurrency)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("执行并发步骤 %d 失败: %w", concurrency, err)
|
||||
}
|
||||
|
||||
// 统计成功率
|
||||
successCount := 0
|
||||
for _, result := range stepResults {
|
||||
if result.Error == nil {
|
||||
successCount++
|
||||
}
|
||||
// 添加到总结果
|
||||
results.Results = append(results.Results, result)
|
||||
}
|
||||
|
||||
// 记录步骤结果
|
||||
results.ConcurrencyData[concurrency] = stepResults
|
||||
|
||||
// 输出步骤统计
|
||||
successRate := 0.0
|
||||
if len(stepResults) > 0 {
|
||||
successRate = float64(successCount) / float64(len(stepResults)) * 100
|
||||
}
|
||||
logger.Info("完成并发步骤: %d 并发用户,共 %d 个请求,成功率: %.2f%%",
|
||||
concurrency, len(stepResults), successRate)
|
||||
}
|
||||
|
||||
results.EndTime = time.Now()
|
||||
logger.Info("所有并发步骤测试完成")
|
||||
|
||||
return results, nil
|
||||
}
|
||||
|
||||
// runConcurrencyStep 执行单个并发步骤
|
||||
func (b *Benchmark) runConcurrencyStep(concurrencyStep int) ([]Result, error) {
|
||||
var results []Result
|
||||
var resultsMutex sync.Mutex
|
||||
|
||||
// 创建上下文,用于控制测试时间
|
||||
ctx, cancel := context.WithTimeout(
|
||||
context.Background(),
|
||||
time.Duration(b.config.Concurrency.DurationPerStep)*time.Second,
|
||||
)
|
||||
defer cancel()
|
||||
|
||||
// 创建工作通道
|
||||
workChan := make(chan struct{}, concurrencyStep)
|
||||
|
||||
// 统计变量
|
||||
var statsMutex sync.Mutex
|
||||
totalRequests := 0
|
||||
successRequests := 0
|
||||
failedRequests := 0
|
||||
totalResponseTime := time.Duration(0)
|
||||
|
||||
// 启动统计协程
|
||||
statsTicker := time.NewTicker(5 * time.Second)
|
||||
defer statsTicker.Stop()
|
||||
|
||||
go func() {
|
||||
startTime := time.Now()
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-statsTicker.C:
|
||||
statsMutex.Lock()
|
||||
currentTotal := totalRequests
|
||||
currentSuccess := successRequests
|
||||
currentFailed := failedRequests
|
||||
var avgResponseTime time.Duration
|
||||
if successRequests > 0 {
|
||||
avgResponseTime = totalResponseTime / time.Duration(successRequests)
|
||||
}
|
||||
statsMutex.Unlock()
|
||||
|
||||
elapsedTime := time.Since(startTime).Seconds()
|
||||
qps := float64(currentTotal) / elapsedTime
|
||||
|
||||
logger.Info("实时统计 - 请求: %d (成功: %d, 失败: %d), QPS: %.2f, 平均响应时间: %v",
|
||||
currentTotal, currentSuccess, currentFailed, qps, avgResponseTime)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
// 启动工作协程
|
||||
var wg sync.WaitGroup
|
||||
logger.Debug("启动 %d 个工作协程...", concurrencyStep)
|
||||
for i := 0; i < concurrencyStep; i++ {
|
||||
wg.Add(1)
|
||||
go func(workerID int) {
|
||||
defer wg.Done()
|
||||
logger.Debug("工作协程 #%d 已启动", workerID)
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
// 测试时间结束
|
||||
logger.Debug("工作协程 #%d 收到结束信号", workerID)
|
||||
return
|
||||
case workChan <- struct{}{}:
|
||||
// 执行请求前先更新计数器
|
||||
statsMutex.Lock()
|
||||
totalRequests++
|
||||
requestID := totalRequests
|
||||
statsMutex.Unlock()
|
||||
|
||||
logger.Debug("工作协程 #%d 开始执行请求 #%d", workerID, requestID)
|
||||
|
||||
// 执行请求
|
||||
result := b.executeRequest(concurrencyStep)
|
||||
|
||||
// 更新统计
|
||||
statsMutex.Lock()
|
||||
if result.Error == nil {
|
||||
successRequests++
|
||||
totalResponseTime += result.ResponseTime
|
||||
logger.Debug("请求 #%d 成功,响应时间: %v", requestID, result.ResponseTime)
|
||||
} else {
|
||||
failedRequests++
|
||||
logger.Debug("请求 #%d 失败: %v", requestID, result.Error)
|
||||
}
|
||||
statsMutex.Unlock()
|
||||
|
||||
// 添加结果
|
||||
resultsMutex.Lock()
|
||||
results = append(results, result)
|
||||
resultsMutex.Unlock()
|
||||
|
||||
// 根据泊松分布等待
|
||||
waitTime := b.getPoissonWaitTime()
|
||||
logger.Debug("请求 #%d 完成,等待 %v 后发送下一个请求", requestID, waitTime)
|
||||
time.Sleep(waitTime)
|
||||
|
||||
<-workChan
|
||||
}
|
||||
}
|
||||
}(i)
|
||||
}
|
||||
|
||||
// 等待所有工作协程完成
|
||||
logger.Debug("等待所有工作协程完成...")
|
||||
wg.Wait()
|
||||
logger.Debug("所有工作协程已完成")
|
||||
|
||||
return results, nil
|
||||
}
|
||||
|
||||
// executeRequest 执行单个请求
|
||||
func (b *Benchmark) executeRequest(concurrencyStep int) Result {
|
||||
result := Result{
|
||||
Timestamp: time.Now(),
|
||||
Concurrency: concurrencyStep,
|
||||
}
|
||||
|
||||
// 选择提示词类型
|
||||
promptType := b.generator.SelectPromptType()
|
||||
result.PromptType = promptType
|
||||
|
||||
// 生成提示词
|
||||
prompt, err := b.generator.GeneratePrompt(promptType)
|
||||
if err != nil {
|
||||
result.Error = fmt.Errorf("生成提示词失败: %w", err)
|
||||
return result
|
||||
}
|
||||
|
||||
// 创建请求
|
||||
req := Request{
|
||||
Model: b.config.API.Model,
|
||||
Messages: []Message{
|
||||
{
|
||||
Role: "user",
|
||||
Content: prompt,
|
||||
},
|
||||
},
|
||||
MaxTokens: 2048,
|
||||
Temperature: 0.7,
|
||||
Stream: true, // 启用流式响应
|
||||
}
|
||||
|
||||
// 序列化请求
|
||||
reqBody, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
result.Error = fmt.Errorf("序列化请求失败: %w", err)
|
||||
return result
|
||||
}
|
||||
|
||||
// 创建HTTP请求
|
||||
httpReq := fasthttp.AcquireRequest()
|
||||
httpResp := fasthttp.AcquireResponse()
|
||||
defer fasthttp.ReleaseRequest(httpReq)
|
||||
defer fasthttp.ReleaseResponse(httpResp)
|
||||
|
||||
httpReq.SetRequestURI(b.config.API.Endpoint)
|
||||
httpReq.Header.SetMethod("POST")
|
||||
httpReq.Header.Set("Content-Type", "application/json")
|
||||
httpReq.Header.Set("Authorization", "Bearer "+b.config.API.APIKey)
|
||||
httpReq.Header.Set("Accept", "text/event-stream") // 设置接受流式响应
|
||||
httpReq.SetBody(reqBody)
|
||||
|
||||
// 记录开始时间
|
||||
startTime := time.Now()
|
||||
|
||||
// 发送请求
|
||||
logger.Debug("发送请求到 %s,提示词类型: %s,提示词长度: %d字符",
|
||||
b.config.API.Endpoint, promptType, len(prompt))
|
||||
|
||||
err = b.client.Do(httpReq, httpResp)
|
||||
|
||||
// 计算响应时间
|
||||
responseTime := time.Since(startTime)
|
||||
result.ResponseTime = responseTime
|
||||
|
||||
// 处理错误
|
||||
if err != nil {
|
||||
result.Error = fmt.Errorf("发送请求失败: %w", err)
|
||||
logger.Error("请求失败: %v", err)
|
||||
return result
|
||||
}
|
||||
|
||||
// 检查状态码
|
||||
statusCode := httpResp.StatusCode()
|
||||
if statusCode != 200 {
|
||||
result.Error = fmt.Errorf("API返回错误状态码: %d, 响应: %s", statusCode, httpResp.Body())
|
||||
logger.Error("API返回错误状态码: %d, 响应: %s", statusCode, httpResp.Body())
|
||||
return result
|
||||
}
|
||||
|
||||
// 处理流式响应
|
||||
if req.Stream {
|
||||
return b.handleStreamResponse(httpResp, result, startTime)
|
||||
}
|
||||
|
||||
// 处理非流式响应
|
||||
return b.handleNormalResponse(httpResp, result)
|
||||
}
|
||||
|
||||
// handleStreamResponse 处理流式响应
|
||||
func (b *Benchmark) handleStreamResponse(httpResp *fasthttp.Response, result Result, startTime time.Time) Result {
|
||||
body := httpResp.Body()
|
||||
responseContent := ""
|
||||
tokenCount := 0
|
||||
|
||||
// 打印响应头和原始响应体的前100个字符,用于调试
|
||||
logger.Debug("响应头: %s", httpResp.Header.String())
|
||||
if len(body) > 0 {
|
||||
previewLen := 100
|
||||
if len(body) < previewLen {
|
||||
previewLen = len(body)
|
||||
}
|
||||
logger.Debug("响应体预览: %s", string(body[:previewLen]))
|
||||
} else {
|
||||
logger.Warn("收到空响应体")
|
||||
result.Error = fmt.Errorf("收到空响应体")
|
||||
return result
|
||||
}
|
||||
|
||||
// 解析流式响应
|
||||
// 流式响应格式为: data: {...}\n\ndata: {...}\n\ndata: [DONE]\n\n
|
||||
lines := bytes.Split(body, []byte("\n\n"))
|
||||
if len(lines) == 0 {
|
||||
logger.Warn("无法解析流式响应")
|
||||
result.Error = fmt.Errorf("无法解析流式响应")
|
||||
return result
|
||||
}
|
||||
|
||||
logger.Debug("解析到 %d 个数据块", len(lines))
|
||||
|
||||
// 超时控制
|
||||
timeout := time.After(30 * time.Second)
|
||||
|
||||
// 使用通道处理解析结果
|
||||
doneChan := make(chan struct{})
|
||||
|
||||
go func() {
|
||||
for _, line := range lines {
|
||||
if len(line) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
// 检查是否为数据行
|
||||
if !bytes.HasPrefix(line, []byte("data: ")) {
|
||||
continue
|
||||
}
|
||||
|
||||
// 移除 "data: " 前缀
|
||||
data := line[6:]
|
||||
|
||||
// 检查是否为结束标记
|
||||
if bytes.Equal(data, []byte("[DONE]")) {
|
||||
logger.Debug("收到流式响应结束标记")
|
||||
break
|
||||
}
|
||||
|
||||
// 解析JSON
|
||||
var chunk map[string]interface{}
|
||||
if err := json.Unmarshal(data, &chunk); err != nil {
|
||||
logger.Warn("解析JSON数据块失败: %v, 数据: %s", err, string(data))
|
||||
continue
|
||||
}
|
||||
|
||||
// 提取内容
|
||||
choices, ok := chunk["choices"].([]interface{})
|
||||
if !ok || len(choices) == 0 {
|
||||
logger.Warn("无法从数据块中提取choices")
|
||||
continue
|
||||
}
|
||||
|
||||
choice, ok := choices[0].(map[string]interface{})
|
||||
if !ok {
|
||||
logger.Warn("无法从choices中提取第一个元素")
|
||||
continue
|
||||
}
|
||||
|
||||
delta, ok := choice["delta"].(map[string]interface{})
|
||||
if !ok {
|
||||
logger.Warn("无法从choice中提取delta")
|
||||
continue
|
||||
}
|
||||
|
||||
content, ok := delta["content"].(string)
|
||||
if !ok {
|
||||
// 某些delta可能没有content,这是正常的
|
||||
continue
|
||||
}
|
||||
|
||||
// 累加内容
|
||||
responseContent += content
|
||||
tokenCount += len(strings.Split(content, " "))
|
||||
}
|
||||
|
||||
close(doneChan)
|
||||
}()
|
||||
|
||||
// 等待处理完成或超时
|
||||
select {
|
||||
case <-doneChan:
|
||||
// 处理完成
|
||||
case <-timeout:
|
||||
logger.Warn("解析流式响应超时")
|
||||
result.Error = fmt.Errorf("解析流式响应超时")
|
||||
return result
|
||||
}
|
||||
|
||||
// 计算响应时间
|
||||
result.ResponseTime = time.Since(startTime)
|
||||
|
||||
// 设置结果
|
||||
result.Response = responseContent
|
||||
result.PromptTokenCount = len(result.PromptType) / 2 // 简单估计
|
||||
result.PromptTokens = len(result.PromptType) / 2 // 简单估计
|
||||
result.CompletionTokens = tokenCount
|
||||
result.TotalTokens = result.PromptTokens + result.CompletionTokens
|
||||
|
||||
logger.Debug("流式响应处理完成,响应时间: %v, 提示词Token: %d, 完成Token: %d, 总Token: %d",
|
||||
result.ResponseTime, result.PromptTokens, result.CompletionTokens, result.TotalTokens)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// handleNormalResponse 处理普通响应
|
||||
func (b *Benchmark) handleNormalResponse(httpResp *fasthttp.Response, result Result) Result {
|
||||
// 解析响应
|
||||
var response Response
|
||||
if err := json.Unmarshal(httpResp.Body(), &response); err != nil {
|
||||
result.Error = fmt.Errorf("解析响应失败: %w", err)
|
||||
logger.Error("解析响应失败: %v", err)
|
||||
return result
|
||||
}
|
||||
|
||||
// 记录Token数
|
||||
result.PromptTokens = response.Usage.PromptTokens
|
||||
result.CompletionTokens = response.Usage.CompletionTokens
|
||||
result.TotalTokens = response.Usage.TotalTokens
|
||||
|
||||
// 记录详细日志
|
||||
logger.Debug("请求完成 - 类型: %s, 提示词Token: %d, 响应Token: %d, 响应时间: %v",
|
||||
result.PromptType, result.PromptTokens, result.CompletionTokens, result.ResponseTime)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// getPoissonWaitTime 根据泊松分布获取等待时间
|
||||
func (b *Benchmark) getPoissonWaitTime() time.Duration {
|
||||
// 生成泊松分布随机数
|
||||
lambda := b.config.PoissonLambda
|
||||
L := math.Exp(-lambda)
|
||||
k := 0
|
||||
p := 1.0
|
||||
|
||||
for p > L {
|
||||
k++
|
||||
p *= b.rand.Float64()
|
||||
}
|
||||
|
||||
// 转换为等待时间(毫秒)
|
||||
waitTime := time.Duration(k * 100) * time.Millisecond
|
||||
|
||||
// 限制最大等待时间为1秒
|
||||
if waitTime > time.Second {
|
||||
waitTime = time.Second
|
||||
}
|
||||
|
||||
return waitTime
|
||||
}
|
||||
|
||||
// convertToFloat64 将整数切片转换为浮点数切片
|
||||
func convertToFloat64(ints []int) []float64 {
|
||||
floats := make([]float64, len(ints))
|
||||
for i, v := range ints {
|
||||
floats[i] = float64(v)
|
||||
}
|
||||
return floats
|
||||
}
|
||||
|
||||
// calculateStats 计算统计数据
|
||||
func (b *Benchmark) calculateStats(results []Result) *BenchmarkResults {
|
||||
var stats BenchmarkResults
|
||||
|
||||
// 过滤出成功的请求
|
||||
var successResults []Result
|
||||
for _, r := range results {
|
||||
if r.Error == nil {
|
||||
successResults = append(successResults, r)
|
||||
}
|
||||
}
|
||||
|
||||
// 如果没有成功的请求,返回空结果
|
||||
if len(successResults) == 0 {
|
||||
return &stats
|
||||
}
|
||||
|
||||
// 计算基本统计数据
|
||||
stats.TotalRequests = len(results)
|
||||
stats.SuccessRequests = len(successResults)
|
||||
stats.FailedRequests = stats.TotalRequests - stats.SuccessRequests
|
||||
|
||||
// 计算响应时间统计
|
||||
var responseTimes []float64
|
||||
for _, r := range successResults {
|
||||
responseTimes = append(responseTimes, float64(r.ResponseTime.Milliseconds()))
|
||||
}
|
||||
|
||||
// 计算平均响应时间
|
||||
avg, _ := stats.Mean(responseTimes)
|
||||
stats.AvgResponseTime = time.Duration(avg) * time.Millisecond
|
||||
|
||||
// 计算响应时间百分位数
|
||||
p50, _ := stats.Percentile(responseTimes, 50)
|
||||
p90, _ := stats.Percentile(responseTimes, 90)
|
||||
p99, _ := stats.Percentile(responseTimes, 99)
|
||||
stats.P50ResponseTime = time.Duration(p50) * time.Millisecond
|
||||
stats.P90ResponseTime = time.Duration(p90) * time.Millisecond
|
||||
stats.P99ResponseTime = time.Duration(p99) * time.Millisecond
|
||||
|
||||
// 计算QPS
|
||||
totalDuration := successResults[len(successResults)-1].Timestamp.Sub(successResults[0].Timestamp).Seconds()
|
||||
if totalDuration > 0 {
|
||||
stats.QPS = float64(stats.SuccessRequests) / totalDuration
|
||||
}
|
||||
|
||||
// 计算Token统计
|
||||
var promptTokens, completionTokens, totalTokens []int
|
||||
for _, r := range successResults {
|
||||
promptTokens = append(promptTokens, r.PromptTokens)
|
||||
completionTokens = append(completionTokens, r.CompletionTokens)
|
||||
totalTokens = append(totalTokens, r.TotalTokens)
|
||||
}
|
||||
|
||||
// 计算平均Token数
|
||||
if len(promptTokens) > 0 {
|
||||
promptAvg, _ := stats.Mean(convertToFloat64(promptTokens))
|
||||
completionAvg, _ := stats.Mean(convertToFloat64(completionTokens))
|
||||
totalAvg, _ := stats.Mean(convertToFloat64(totalTokens))
|
||||
stats.AvgPromptTokens = int(promptAvg)
|
||||
stats.AvgCompletionTokens = int(completionAvg)
|
||||
stats.AvgTotalTokens = int(totalAvg)
|
||||
}
|
||||
|
||||
// 计算Token生成速率 (tokens/s)
|
||||
var tokenRates []float64
|
||||
for _, r := range successResults {
|
||||
if r.ResponseTime.Seconds() > 0 {
|
||||
tokenRate := float64(r.CompletionTokens) / r.ResponseTime.Seconds()
|
||||
tokenRates = append(tokenRates, tokenRate)
|
||||
}
|
||||
}
|
||||
|
||||
if len(tokenRates) > 0 {
|
||||
tokenRateAvg, _ := stats.Mean(tokenRates)
|
||||
stats.AvgTokenRate = tokenRateAvg
|
||||
}
|
||||
|
||||
return &stats
|
||||
}
|
||||
|
||||
func (b *BenchmarkResults) Mean(data []float64) (float64, error) {
|
||||
return stats.Mean(data)
|
||||
}
|
||||
|
||||
func (b *BenchmarkResults) Percentile(data []float64, p float64) (float64, error) {
|
||||
return stats.Percentile(data, p)
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println("LLM API Benchmark Tool 初始化成功")
|
||||
}
|
||||
-38
@@ -1,38 +0,0 @@
|
||||
api:
|
||||
endpoint: "http://139.9.229.200:8080/v1/chat/completions"
|
||||
api_key: "devserver-9aB3-7fG5q2Yd-8C4T-1R6k-Ew9p-3MnL7bZx4Wv2"
|
||||
model: "DeepSeek-R1"
|
||||
|
||||
prompt_templates:
|
||||
short:
|
||||
target_tokens: 50
|
||||
templates:
|
||||
- "什么是{concept}?"
|
||||
- "请简要解释{concept}的基本原理。"
|
||||
- "简述{topic}的主要观点。"
|
||||
- "{country}的首都是哪里?"
|
||||
- "如何快速入门{concept}?"
|
||||
long:
|
||||
target_tokens: 1000
|
||||
templates:
|
||||
- "请撰写一篇关于{country}历史的详细介绍,包括主要历史事件和文化发展。"
|
||||
- "请对{topic}进行深入分析,包括其背景、现状、问题和未来发展趋势。"
|
||||
- "请撰写一份关于{event}影响的综合报告,包括社会、经济和政治层面的分析。"
|
||||
- "请详细介绍{concept}的技术原理、应用场景和未来发展方向。"
|
||||
- "请撰写一篇关于{topic}的学术论文,包括研究背景、方法、结果和讨论。"
|
||||
|
||||
requests:
|
||||
- type: "short"
|
||||
weight: 0.7
|
||||
- type: "long"
|
||||
weight: 0.3
|
||||
|
||||
concurrency:
|
||||
steps: [1,2]
|
||||
duration_per_step: 60 # 秒
|
||||
|
||||
timeout: 60 # 秒
|
||||
poisson_lambda: 1.0 # 请求间隔泊松分布参数
|
||||
|
||||
tokenizer:
|
||||
model: "gpt-3.5-turbo" # 用于tiktoken-go的分词器模型
|
||||
@@ -1,103 +0,0 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
// Config 表示应用程序的配置
|
||||
type Config struct {
|
||||
API APIConfig `mapstructure:"api"`
|
||||
PromptTemplates PromptTemplatesConfig `mapstructure:"prompt_templates"`
|
||||
Requests []RequestConfig `mapstructure:"requests"`
|
||||
Concurrency ConcurrencyConfig `mapstructure:"concurrency"`
|
||||
Timeout int `mapstructure:"timeout"`
|
||||
PoissonLambda float64 `mapstructure:"poisson_lambda"`
|
||||
Tokenizer TokenizerConfig `mapstructure:"tokenizer"`
|
||||
}
|
||||
|
||||
// APIConfig 表示API相关配置
|
||||
type APIConfig struct {
|
||||
Endpoint string `mapstructure:"endpoint"`
|
||||
APIKey string `mapstructure:"api_key"`
|
||||
Model string `mapstructure:"model"`
|
||||
}
|
||||
|
||||
// PromptTemplatesConfig 表示提示词模板配置
|
||||
type PromptTemplatesConfig struct {
|
||||
Short PromptTypeConfig `mapstructure:"short"`
|
||||
Long PromptTypeConfig `mapstructure:"long"`
|
||||
}
|
||||
|
||||
// PromptTypeConfig 表示特定类型提示词的配置
|
||||
type PromptTypeConfig struct {
|
||||
TargetTokens int `mapstructure:"target_tokens"`
|
||||
Templates []string `mapstructure:"templates"`
|
||||
}
|
||||
|
||||
// RequestConfig 表示请求配置
|
||||
type RequestConfig struct {
|
||||
Type string `mapstructure:"type"`
|
||||
Weight float64 `mapstructure:"weight"`
|
||||
}
|
||||
|
||||
// ConcurrencyConfig 表示并发配置
|
||||
type ConcurrencyConfig struct {
|
||||
Steps []int `mapstructure:"steps"`
|
||||
DurationPerStep int `mapstructure:"duration_per_step"`
|
||||
}
|
||||
|
||||
// TokenizerConfig 表示分词器配置
|
||||
type TokenizerConfig struct {
|
||||
Model string `mapstructure:"model"`
|
||||
}
|
||||
|
||||
// LoadConfig 从指定路径加载配置
|
||||
func LoadConfig(path string) (*Config, error) {
|
||||
viper.SetConfigFile(path)
|
||||
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
return nil, fmt.Errorf("读取配置文件失败: %w", err)
|
||||
}
|
||||
|
||||
var config Config
|
||||
if err := viper.Unmarshal(&config); err != nil {
|
||||
return nil, fmt.Errorf("解析配置失败: %w", err)
|
||||
}
|
||||
|
||||
// 验证配置
|
||||
if err := validateConfig(&config); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &config, nil
|
||||
}
|
||||
|
||||
// validateConfig 验证配置的有效性
|
||||
func validateConfig(config *Config) error {
|
||||
if config.API.Endpoint == "" {
|
||||
return fmt.Errorf("API端点不能为空")
|
||||
}
|
||||
|
||||
if config.API.APIKey == "" {
|
||||
return fmt.Errorf("API密钥不能为空")
|
||||
}
|
||||
|
||||
if config.API.Model == "" {
|
||||
return fmt.Errorf("模型名称不能为空")
|
||||
}
|
||||
|
||||
if len(config.Requests) == 0 {
|
||||
return fmt.Errorf("请求配置不能为空")
|
||||
}
|
||||
|
||||
if len(config.Concurrency.Steps) == 0 {
|
||||
return fmt.Errorf("并发步骤不能为空")
|
||||
}
|
||||
|
||||
if config.Timeout <= 0 {
|
||||
return fmt.Errorf("超时时间必须大于0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -1,130 +0,0 @@
|
||||
# 配置文档
|
||||
|
||||
本文档详细说明了LLM API基准测试工具的配置选项。
|
||||
|
||||
## 配置文件格式
|
||||
|
||||
配置文件使用YAML格式,默认文件名为`config.yaml`。您可以通过命令行参数`-config`指定其他配置文件路径。
|
||||
|
||||
## 配置选项
|
||||
|
||||
### API配置
|
||||
|
||||
```yaml
|
||||
api:
|
||||
endpoint: "https://api.example.com/v1/completions" # API端点URL
|
||||
api_key: "your_api_key" # API密钥
|
||||
model: "gpt-3.5-turbo" # 模型名称
|
||||
```
|
||||
|
||||
### 提示词模板配置
|
||||
|
||||
```yaml
|
||||
prompt_templates:
|
||||
short: # 短咨询提示词配置
|
||||
target_tokens: 50 # 目标Token数(±5%)
|
||||
templates: # 提示词模板列表
|
||||
- "什么是{concept}?"
|
||||
- "请简要解释{concept}的基本原理。"
|
||||
- "简述{topic}的主要观点。"
|
||||
|
||||
long: # 长文档提示词配置
|
||||
target_tokens: 1000 # 目标Token数(±5%)
|
||||
templates: # 提示词模板列表
|
||||
- "请撰写一篇关于{country}历史的详细介绍,包括主要历史事件和文化发展。"
|
||||
- "请对{topic}进行深入分析,包括其背景、现状、问题和未来发展趋势。"
|
||||
```
|
||||
|
||||
提示词模板中可以使用以下占位符:
|
||||
- `{country}`: 国家名称
|
||||
- `{concept}`: 概念名称
|
||||
- `{topic}`: 主题名称
|
||||
- `{event}`: 事件名称
|
||||
|
||||
系统会自动替换这些占位符,并根据目标Token数动态调整提示词长度。
|
||||
|
||||
### 请求配置
|
||||
|
||||
```yaml
|
||||
requests:
|
||||
- type: "short" # 提示词类型
|
||||
weight: 0.7 # 权重(占比)
|
||||
- type: "long"
|
||||
weight: 0.3
|
||||
```
|
||||
|
||||
权重总和应为1.0,表示各类型提示词的比例。
|
||||
|
||||
### 并发配置
|
||||
|
||||
```yaml
|
||||
concurrency:
|
||||
steps: [50, 200, 500] # 并发步骤
|
||||
duration_per_step: 300 # 每个步骤的持续时间(秒)
|
||||
```
|
||||
|
||||
系统会按照指定的并发步骤逐步增加并发用户数,每个步骤持续指定的时间。
|
||||
|
||||
### 超时配置
|
||||
|
||||
```yaml
|
||||
timeout: 60 # 请求超时时间(秒)
|
||||
```
|
||||
|
||||
### 泊松分布参数
|
||||
|
||||
```yaml
|
||||
poisson_lambda: 1.0 # 请求间隔泊松分布参数
|
||||
```
|
||||
|
||||
该参数控制请求间隔的随机性,模拟真实用户行为。
|
||||
|
||||
### 分词器配置
|
||||
|
||||
```yaml
|
||||
tokenizer:
|
||||
model: "gpt-3.5-turbo" # 用于tiktoken-go的分词器模型
|
||||
```
|
||||
|
||||
## 完整配置示例
|
||||
|
||||
```yaml
|
||||
api:
|
||||
endpoint: "https://api.example.com/v1/completions"
|
||||
api_key: "your_api_key"
|
||||
model: "gpt-3.5-turbo"
|
||||
|
||||
prompt_templates:
|
||||
short:
|
||||
target_tokens: 50
|
||||
templates:
|
||||
- "什么是{concept}?"
|
||||
- "请简要解释{concept}的基本原理。"
|
||||
- "简述{topic}的主要观点。"
|
||||
- "{country}的首都是哪里?"
|
||||
- "如何快速入门{concept}?"
|
||||
long:
|
||||
target_tokens: 1000
|
||||
templates:
|
||||
- "请撰写一篇关于{country}历史的详细介绍,包括主要历史事件和文化发展。"
|
||||
- "请对{topic}进行深入分析,包括其背景、现状、问题和未来发展趋势。"
|
||||
- "请撰写一份关于{event}影响的综合报告,包括社会、经济和政治层面的分析。"
|
||||
- "请详细介绍{concept}的技术原理、应用场景和未来发展方向。"
|
||||
- "请撰写一篇关于{topic}的学术论文,包括研究背景、方法、结果和讨论。"
|
||||
|
||||
requests:
|
||||
- type: "short"
|
||||
weight: 0.7
|
||||
- type: "long"
|
||||
weight: 0.3
|
||||
|
||||
concurrency:
|
||||
steps: [50, 200, 500]
|
||||
duration_per_step: 300 # 秒
|
||||
|
||||
timeout: 60 # 秒
|
||||
poisson_lambda: 1.0 # 请求间隔泊松分布参数
|
||||
|
||||
tokenizer:
|
||||
model: "gpt-3.5-turbo" # 用于tiktoken-go的分词器模型
|
||||
```
|
||||
@@ -1,38 +1,18 @@
|
||||
module github.com/acmestudio/llm-api-benchmark-tool
|
||||
module mingor/llm-api-benchmark-tool
|
||||
|
||||
go 1.21
|
||||
go 1.23.0
|
||||
|
||||
toolchain go1.24.1
|
||||
|
||||
require (
|
||||
github.com/go-echarts/go-echarts/v2 v2.3.3
|
||||
github.com/montanaflynn/stats v0.7.1
|
||||
github.com/pkoukk/tiktoken-go v0.1.6
|
||||
github.com/spf13/viper v1.18.2
|
||||
github.com/valyala/fasthttp v1.52.0
|
||||
github.com/tiktoken-go/tokenizer v0.6.1
|
||||
github.com/valyala/fasthttp v1.60.0
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/andybalholm/brotli v1.1.0 // indirect
|
||||
github.com/dlclark/regexp2 v1.10.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
||||
github.com/google/uuid v1.4.0 // indirect
|
||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||
github.com/klauspost/compress v1.17.6 // indirect
|
||||
github.com/magiconair/properties v1.8.7 // indirect
|
||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
|
||||
github.com/sagikazarmark/locafero v0.4.0 // indirect
|
||||
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
|
||||
github.com/sourcegraph/conc v0.3.0 // indirect
|
||||
github.com/spf13/afero v1.11.0 // indirect
|
||||
github.com/spf13/cast v1.6.0 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/subosito/gotenv v1.6.0 // indirect
|
||||
github.com/andybalholm/brotli v1.1.1 // indirect
|
||||
github.com/dlclark/regexp2 v1.11.5 // indirect
|
||||
github.com/klauspost/compress v1.18.0 // indirect
|
||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||
go.uber.org/atomic v1.9.0 // indirect
|
||||
go.uber.org/multierr v1.9.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
|
||||
golang.org/x/sys v0.17.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
@@ -1,87 +1,18 @@
|
||||
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
|
||||
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dlclark/regexp2 v1.10.0 h1:+/GIL799phkJqYW+3YbOd8LCcbHzT0Pbo8zl70MHsq0=
|
||||
github.com/dlclark/regexp2 v1.10.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
|
||||
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
|
||||
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
|
||||
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
|
||||
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
|
||||
github.com/go-echarts/go-echarts/v2 v2.3.3 h1:uImZAk6qLkC6F9ju6mZ5SPBqTyK8xjZKwSmwnCg4bxg=
|
||||
github.com/go-echarts/go-echarts/v2 v2.3.3/go.mod h1:56YlvzhW/a+du15f3S2qUGNDfKnFOeJSThBIrVFHDtI=
|
||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
|
||||
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
|
||||
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
||||
github.com/klauspost/compress v1.17.6 h1:60eq2E/jlfwQXtvZEeBUYADs+BwKBWURIY+Gj2eRGjI=
|
||||
github.com/klauspost/compress v1.17.6/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
|
||||
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
|
||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE=
|
||||
github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
|
||||
github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
|
||||
github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
|
||||
github.com/pkoukk/tiktoken-go v0.1.6 h1:JF0TlJzhTbrI30wCvFuiw6FzP2+/bR+FIxUdgEAcUsw=
|
||||
github.com/pkoukk/tiktoken-go v0.1.6/go.mod h1:9NiV+i9mJKGj1rYOT+njbv+ZwA/zJxYdewGl6qVatpg=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
|
||||
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
|
||||
github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ=
|
||||
github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4=
|
||||
github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE=
|
||||
github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ=
|
||||
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
|
||||
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
|
||||
github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
|
||||
github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY=
|
||||
github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
|
||||
github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
|
||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/spf13/viper v1.18.2 h1:LUXCnvUvSM6FXAsj6nnfc8Q2tp1dIgUfY9Kc8GsSOiQ=
|
||||
github.com/spf13/viper v1.18.2/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
|
||||
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
|
||||
github.com/andybalholm/brotli v1.1.1 h1:PR2pgnyFznKEugtsUo0xLdDop5SKXd5Qf5ysW+7XdTA=
|
||||
github.com/andybalholm/brotli v1.1.1/go.mod h1:05ib4cKhjx3OQYUY22hTVd34Bc8upXjOLL2rKwwZBoA=
|
||||
github.com/dlclark/regexp2 v1.11.5 h1:Q/sSnsKerHeCkc/jSTNq1oCm7KiVgUMZRDUoRu0JQZQ=
|
||||
github.com/dlclark/regexp2 v1.11.5/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
|
||||
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
|
||||
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
|
||||
github.com/tiktoken-go/tokenizer v0.6.1 h1:iuhZJUEYY4Fn5vYbDX0Clgqzus8w8rM410YbovUzyLM=
|
||||
github.com/tiktoken-go/tokenizer v0.6.1/go.mod h1:6UCYI/DtOallbmL7sSy30p6YQv60qNyU/4aVigPOx6w=
|
||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||
github.com/valyala/fasthttp v1.52.0 h1:wqBQpxH71XW0e2g+Og4dzQM8pk34aFYlA1Ga8db7gU0=
|
||||
github.com/valyala/fasthttp v1.52.0/go.mod h1:hf5C4QnVMkNXMspnsUlfM3WitlgYflyhHYoKol/szxQ=
|
||||
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
|
||||
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
|
||||
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
|
||||
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
|
||||
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
|
||||
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
|
||||
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
github.com/valyala/fasthttp v1.60.0 h1:kBRYS0lOhVJ6V+bYN8PqAHELKHtXqwq9zNMLKx1MBsw=
|
||||
github.com/valyala/fasthttp v1.60.0/go.mod h1:iY4kDgV3Gc6EqhRZ8icqcmlG6bqhcDXfuHgTO4FXCvc=
|
||||
github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU=
|
||||
github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
|
||||
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
@@ -0,0 +1,56 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
// Config 定义压测配置结构
|
||||
// 可根据 production.md 扩展字段
|
||||
|
||||
type APIConfig struct {
|
||||
Endpoint string `yaml:"endpoint"`
|
||||
APIKey string `yaml:"api_key"`
|
||||
Model string `yaml:"model"`
|
||||
Streaming bool `yaml:"streaming"`
|
||||
ClientType string `yaml:"client"`
|
||||
}
|
||||
|
||||
type PromptTemplate struct {
|
||||
TargetTokens int `yaml:"target_tokens"`
|
||||
Templates []string `yaml:"templates"`
|
||||
}
|
||||
|
||||
type RequestMix struct {
|
||||
Type string `yaml:"type"`
|
||||
Weight float64 `yaml:"weight"`
|
||||
}
|
||||
|
||||
type ConcurrencyConfig struct {
|
||||
Steps []int `yaml:"steps"`
|
||||
DurationPerStep int `yaml:"duration_per_step"`
|
||||
MaxGoroutines int `yaml:"max_goroutines"`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
API APIConfig `yaml:"api"`
|
||||
PromptTemplates map[string]PromptTemplate `yaml:"prompt_templates"`
|
||||
Requests []RequestMix `yaml:"requests"`
|
||||
Concurrency ConcurrencyConfig `yaml:"concurrency"`
|
||||
Timeout int `yaml:"timeout"`
|
||||
PoissonLambda float64 `yaml:"poisson_lambda"`
|
||||
TokenizerModel string `yaml:"tokenizer_model"`
|
||||
}
|
||||
|
||||
func LoadConfig(path string) (*Config, error) {
|
||||
data, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var cfg Config
|
||||
if err := yaml.Unmarshal(data, &cfg); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &cfg, nil
|
||||
}
|
||||
Binary file not shown.
@@ -1,200 +0,0 @@
|
||||
package logger
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 日志级别
|
||||
const (
|
||||
DEBUG = iota
|
||||
INFO
|
||||
WARN
|
||||
ERROR
|
||||
FATAL
|
||||
)
|
||||
|
||||
// 日志级别名称
|
||||
var levelNames = []string{
|
||||
"调试",
|
||||
"信息",
|
||||
"警告",
|
||||
"错误",
|
||||
"致命",
|
||||
}
|
||||
|
||||
// 日志级别颜色
|
||||
var levelColors = []string{
|
||||
"\033[36m", // 青色 - 调试
|
||||
"\033[32m", // 绿色 - 信息
|
||||
"\033[33m", // 黄色 - 警告
|
||||
"\033[31m", // 红色 - 错误
|
||||
"\033[35m", // 紫色 - 致命
|
||||
}
|
||||
|
||||
// 重置颜色
|
||||
const resetColor = "\033[0m"
|
||||
|
||||
// Logger 日志记录器
|
||||
type Logger struct {
|
||||
level int
|
||||
logger *log.Logger
|
||||
useColors bool
|
||||
timeFormat string
|
||||
}
|
||||
|
||||
// 全局日志记录器
|
||||
var defaultLogger *Logger
|
||||
|
||||
// 初始化默认日志记录器
|
||||
func init() {
|
||||
defaultLogger = NewLogger(INFO, true)
|
||||
}
|
||||
|
||||
// NewLogger 创建新的日志记录器
|
||||
func NewLogger(level int, useColors bool) *Logger {
|
||||
return &Logger{
|
||||
level: level,
|
||||
logger: log.New(os.Stdout, "", 0),
|
||||
useColors: useColors,
|
||||
timeFormat: "2006-01-02 15:04:05.000",
|
||||
}
|
||||
}
|
||||
|
||||
// SetLevel 设置日志级别
|
||||
func SetLevel(level int) {
|
||||
defaultLogger.level = level
|
||||
}
|
||||
|
||||
// SetUseColors 设置是否使用颜色
|
||||
func SetUseColors(useColors bool) {
|
||||
defaultLogger.useColors = useColors
|
||||
}
|
||||
|
||||
// formatLog 格式化日志消息
|
||||
func (l *Logger) formatLog(level int, format string, args ...interface{}) string {
|
||||
// 格式化消息
|
||||
var msg string
|
||||
if len(args) > 0 {
|
||||
msg = fmt.Sprintf(format, args...)
|
||||
} else {
|
||||
msg = format
|
||||
}
|
||||
|
||||
// 获取当前时间
|
||||
now := time.Now().Format(l.timeFormat)
|
||||
|
||||
// 获取级别名称
|
||||
levelName := levelNames[level]
|
||||
|
||||
// 构建日志前缀
|
||||
prefix := fmt.Sprintf("[%s] [%s] ", now, levelName)
|
||||
|
||||
// 添加颜色
|
||||
if l.useColors {
|
||||
prefix = levelColors[level] + prefix
|
||||
msg = msg + resetColor
|
||||
}
|
||||
|
||||
// 处理多行消息,确保每行都有正确的前缀
|
||||
lines := strings.Split(msg, "\n")
|
||||
for i := 1; i < len(lines); i++ {
|
||||
if len(lines[i]) > 0 {
|
||||
padding := strings.Repeat(" ", len(now)+3) // +3 for "[] "
|
||||
lines[i] = fmt.Sprintf("%s%s", padding, lines[i])
|
||||
}
|
||||
}
|
||||
|
||||
return prefix + strings.Join(lines, "\n")
|
||||
}
|
||||
|
||||
// log 记录日志
|
||||
func (l *Logger) log(level int, format string, args ...interface{}) {
|
||||
if level >= l.level {
|
||||
l.logger.Println(l.formatLog(level, format, args...))
|
||||
}
|
||||
}
|
||||
|
||||
// Debug 调试日志
|
||||
func (l *Logger) Debug(format string, args ...interface{}) {
|
||||
l.log(DEBUG, format, args...)
|
||||
}
|
||||
|
||||
// Info 信息日志
|
||||
func (l *Logger) Info(format string, args ...interface{}) {
|
||||
l.log(INFO, format, args...)
|
||||
}
|
||||
|
||||
// Warn 警告日志
|
||||
func (l *Logger) Warn(format string, args ...interface{}) {
|
||||
l.log(WARN, format, args...)
|
||||
}
|
||||
|
||||
// Error 错误日志
|
||||
func (l *Logger) Error(format string, args ...interface{}) {
|
||||
l.log(ERROR, format, args...)
|
||||
}
|
||||
|
||||
// Fatal 致命日志
|
||||
func (l *Logger) Fatal(format string, args ...interface{}) {
|
||||
l.log(FATAL, format, args...)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Debug 调试日志
|
||||
func Debug(format string, args ...interface{}) {
|
||||
defaultLogger.Debug(format, args...)
|
||||
}
|
||||
|
||||
// Info 信息日志
|
||||
func Info(format string, args ...interface{}) {
|
||||
defaultLogger.Info(format, args...)
|
||||
}
|
||||
|
||||
// Warn 警告日志
|
||||
func Warn(format string, args ...interface{}) {
|
||||
defaultLogger.Warn(format, args...)
|
||||
}
|
||||
|
||||
// Error 错误日志
|
||||
func Error(format string, args ...interface{}) {
|
||||
defaultLogger.Error(format, args...)
|
||||
}
|
||||
|
||||
// Fatal 致命日志
|
||||
func Fatal(format string, args ...interface{}) {
|
||||
defaultLogger.Fatal(format, args...)
|
||||
}
|
||||
|
||||
// 进度条相关
|
||||
const (
|
||||
progressBarWidth = 50
|
||||
)
|
||||
|
||||
// PrintProgressBar 打印进度条
|
||||
func PrintProgressBar(current, total int, prefix string) {
|
||||
percentage := float64(current) / float64(total)
|
||||
filled := int(progressBarWidth * percentage)
|
||||
empty := progressBarWidth - filled
|
||||
|
||||
// 构建进度条
|
||||
bar := fmt.Sprintf("\r%s [%s%s] %.1f%% (%d/%d)",
|
||||
prefix,
|
||||
strings.Repeat("█", filled),
|
||||
strings.Repeat("░", empty),
|
||||
percentage*100,
|
||||
current,
|
||||
total,
|
||||
)
|
||||
|
||||
// 打印进度条(不换行)
|
||||
fmt.Print(bar)
|
||||
|
||||
// 如果完成,打印换行
|
||||
if current == total {
|
||||
fmt.Println()
|
||||
}
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/acmestudio/llm-api-benchmark-tool/config"
|
||||
"github.com/acmestudio/llm-api-benchmark-tool/benchmark"
|
||||
"github.com/acmestudio/llm-api-benchmark-tool/report"
|
||||
"github.com/acmestudio/llm-api-benchmark-tool/logger"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// 解析命令行参数
|
||||
configPath := flag.String("config", "config.yaml", "配置文件路径")
|
||||
outputDir := flag.String("output", "reports", "报告输出目录")
|
||||
debugMode := flag.Bool("debug", false, "启用调试模式")
|
||||
noColor := flag.Bool("no-color", false, "禁用彩色日志输出")
|
||||
flag.Parse()
|
||||
|
||||
// 配置日志级别
|
||||
if *debugMode {
|
||||
logger.SetLevel(logger.DEBUG)
|
||||
} else {
|
||||
logger.SetLevel(logger.INFO)
|
||||
}
|
||||
|
||||
// 配置日志颜色
|
||||
logger.SetUseColors(!*noColor)
|
||||
|
||||
logger.Info("LLM API基准测试工具启动")
|
||||
logger.Info("版本: v0.1.0")
|
||||
logger.Debug("调试模式已启用")
|
||||
|
||||
// 加载配置
|
||||
logger.Info("正在加载配置文件: %s", *configPath)
|
||||
cfg, err := config.LoadConfig(*configPath)
|
||||
if err != nil {
|
||||
logger.Fatal("加载配置失败: %v", err)
|
||||
}
|
||||
logger.Info("配置加载成功")
|
||||
logger.Debug("API端点: %s", cfg.API.Endpoint)
|
||||
logger.Debug("模型: %s", cfg.API.Model)
|
||||
logger.Debug("并发步骤: %v", cfg.Concurrency.Steps)
|
||||
logger.Debug("每步持续时间: %d秒", cfg.Concurrency.DurationPerStep)
|
||||
|
||||
// 创建输出目录
|
||||
if err := os.MkdirAll(*outputDir, 0755); err != nil {
|
||||
logger.Fatal("创建输出目录失败: %v", err)
|
||||
}
|
||||
logger.Debug("输出目录已创建: %s", *outputDir)
|
||||
|
||||
// 初始化基准测试
|
||||
logger.Info("正在初始化基准测试...")
|
||||
bench, err := benchmark.NewBenchmark(cfg)
|
||||
if err != nil {
|
||||
logger.Fatal("初始化基准测试失败: %v", err)
|
||||
}
|
||||
logger.Info("基准测试初始化成功")
|
||||
|
||||
// 运行基准测试
|
||||
logger.Info("开始运行LLM API基准测试...")
|
||||
startTime := time.Now()
|
||||
results, err := bench.Run()
|
||||
if err != nil {
|
||||
logger.Fatal("运行基准测试失败: %v", err)
|
||||
}
|
||||
duration := time.Since(startTime)
|
||||
logger.Info("基准测试完成,总耗时: %v", duration)
|
||||
|
||||
// 生成报告
|
||||
logger.Info("正在生成性能报告...")
|
||||
reportTime := time.Now().Format("2006-01-02_15-04-05")
|
||||
reportPath := fmt.Sprintf("%s/report_%s", *outputDir, reportTime)
|
||||
|
||||
if err := report.GenerateReport(results, cfg, reportPath); err != nil {
|
||||
logger.Fatal("生成报告失败: %v", err)
|
||||
}
|
||||
|
||||
logger.Info("基准测试完成!报告已生成: %s", reportPath)
|
||||
logger.Info("HTML报告: %s/report.html", reportPath)
|
||||
logger.Info("CSV数据: %s/results.csv", reportPath)
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package httpclient
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// NewHTTPClient 根据配置类型返回对应 HTTPClient 实例
|
||||
func NewHTTPClient(clientType string) (HTTPClient, error) {
|
||||
switch clientType {
|
||||
case "fasthttp":
|
||||
return NewFastHTTPClient(), nil
|
||||
case "net-http":
|
||||
return NewNetHTTPClient(), nil
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported client: %s", clientType)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package httpclient
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
// FastHTTPClient 使用 fasthttp 实现 HTTPClient 接口
|
||||
type FastHTTPClient struct {
|
||||
client *fasthttp.Client
|
||||
reqPool *sync.Pool
|
||||
respPool *sync.Pool
|
||||
}
|
||||
|
||||
// NewFastHTTPClient 返回一个初始化的 FastHTTPClient
|
||||
func NewFastHTTPClient() *FastHTTPClient {
|
||||
return &FastHTTPClient{
|
||||
client: &fasthttp.Client{},
|
||||
reqPool: &sync.Pool{New: func() interface{} { return new(fasthttp.Request) }},
|
||||
respPool: &sync.Pool{New: func() interface{} { return new(fasthttp.Response) }},
|
||||
}
|
||||
}
|
||||
|
||||
// Do 发送非流式请求
|
||||
func (c *FastHTTPClient) Do(req *Request) (*Response, error) {
|
||||
fr := c.reqPool.Get().(*fasthttp.Request)
|
||||
defer c.reqPool.Put(fr)
|
||||
fr.Header.SetMethod(req.Method)
|
||||
fr.SetRequestURI(req.URL)
|
||||
if len(req.Body) > 0 {
|
||||
fr.SetBody(req.Body)
|
||||
}
|
||||
for k, v := range req.Headers {
|
||||
fr.Header.Set(k, v)
|
||||
}
|
||||
fresp := c.respPool.Get().(*fasthttp.Response)
|
||||
defer c.respPool.Put(fresp)
|
||||
if err := c.client.Do(fr, fresp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp := &Response{
|
||||
StatusCode: fresp.StatusCode(),
|
||||
Body: append([]byte(nil), fresp.Body()...),
|
||||
Headers: make(map[string]string),
|
||||
}
|
||||
fresp.Header.VisitAll(func(k, v []byte) {
|
||||
resp.Headers[string(k)] = string(v)
|
||||
})
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// Stream 发送流式请求,逐块通过 callback 回调 SSE 数据
|
||||
// 目前使用 net/http 实现 SSE 解析,后续可优化为 fasthttp 原生实现
|
||||
func (c *FastHTTPClient) Stream(req *Request, callback func(chunk SSEChunk) error) error {
|
||||
return NewNetHTTPClient().Stream(req, callback)
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package httpclient
|
||||
|
||||
// Request 表示 HTTP 请求
|
||||
// 包含方法、URL、Body 和 Header
|
||||
// 可在后续实现中扩展 Field
|
||||
|
||||
type Request struct {
|
||||
Method string
|
||||
URL string
|
||||
Body []byte
|
||||
Headers map[string]string
|
||||
}
|
||||
|
||||
// Response 表示 HTTP 响应
|
||||
// 包含状态码、Body 和 Header
|
||||
|
||||
type Response struct {
|
||||
StatusCode int
|
||||
Body []byte
|
||||
Headers map[string]string
|
||||
}
|
||||
|
||||
// SSEChunk 表示 SSE 流中的一块数据
|
||||
// Data 为 JSON 数据,Timestamp 记录接收时间,IsDone 标记 [DONE]
|
||||
|
||||
type SSEChunk struct {
|
||||
Data []byte // JSON 数据
|
||||
Timestamp int64 // 接收时间戳(UnixNano)
|
||||
IsDone bool // 是否为 [DONE]
|
||||
}
|
||||
|
||||
// HTTPClient 定义通用的 Do 和 Stream 方法接口
|
||||
// 后续根据 client 类型实现 fasthttp 或 net/http
|
||||
|
||||
type HTTPClient interface {
|
||||
Do(req *Request) (*Response, error)
|
||||
Stream(req *Request, callback func(chunk SSEChunk) error) error
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package httpclient
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// NetHTTPClient 使用 net/http 实现 HTTPClient 接口
|
||||
type NetHTTPClient struct {
|
||||
client *http.Client
|
||||
// 可根据需要添加对象池
|
||||
}
|
||||
|
||||
// NewNetHTTPClient 返回一个初始化的 NetHTTPClient
|
||||
func NewNetHTTPClient() *NetHTTPClient {
|
||||
return &NetHTTPClient{client: &http.Client{}}
|
||||
}
|
||||
|
||||
// Do 发送非流式请求
|
||||
func (c *NetHTTPClient) Do(req *Request) (*Response, error) {
|
||||
r, err := http.NewRequest(req.Method, req.URL, bytes.NewReader(req.Body))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for k, v := range req.Headers {
|
||||
r.Header.Set(k, v)
|
||||
}
|
||||
resp, err := c.client.Do(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
headers := make(map[string]string)
|
||||
for k, v := range resp.Header {
|
||||
headers[k] = v[0]
|
||||
}
|
||||
return &Response{StatusCode: resp.StatusCode, Body: body, Headers: headers}, nil
|
||||
}
|
||||
|
||||
// Stream 发送流式请求,逐块通过 callback 回调 SSE 数据
|
||||
func (c *NetHTTPClient) Stream(req *Request, callback func(chunk SSEChunk) error) error {
|
||||
r, err := http.NewRequest(req.Method, req.URL, bytes.NewReader(req.Body))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for k, v := range req.Headers {
|
||||
r.Header.Set(k, v)
|
||||
}
|
||||
resp, err := c.client.Do(r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
scanner := bufio.NewScanner(resp.Body)
|
||||
for scanner.Scan() {
|
||||
text := scanner.Text()
|
||||
if text == "" {
|
||||
continue
|
||||
}
|
||||
const prefix = "data: "
|
||||
if strings.HasPrefix(text, prefix) {
|
||||
payload := text[len(prefix):]
|
||||
isDone := payload == "[DONE]"
|
||||
var dataBytes []byte
|
||||
if !isDone {
|
||||
dataBytes = []byte(payload)
|
||||
}
|
||||
chunk := SSEChunk{
|
||||
Data: dataBytes,
|
||||
Timestamp: time.Now().UnixNano(),
|
||||
IsDone: isDone,
|
||||
}
|
||||
if err := callback(chunk); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
if err := scanner.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package prompt
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/tiktoken-go/tokenizer"
|
||||
"mingor/llm-api-benchmark-tool/internal/config"
|
||||
)
|
||||
|
||||
// PromptGenerator 生成短/长提示词
|
||||
// 使用 tiktoken-go tokenizer 计算 token 数
|
||||
|
||||
type PromptGenerator struct {
|
||||
cfg *config.Config
|
||||
tok *tokenizer.Tokenizer
|
||||
}
|
||||
|
||||
// NewPromptGenerator 初始化生成器,model 用于 tokenizer
|
||||
func NewPromptGenerator(model string, cfg *config.Config) (*PromptGenerator, error) {
|
||||
tok, err := tokenizer.NewTokenizer(model)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
return &PromptGenerator{cfg: cfg, tok: tok}, nil
|
||||
}
|
||||
|
||||
// Generate 根据类型(tp)和占位值(values)生成提示词
|
||||
// tp 可为 "short" 或 "long" 等配置中的键
|
||||
func (g *PromptGenerator) Generate(tp string, values map[string]string) (string, error) {
|
||||
pt, ok := g.cfg.PromptTemplates[tp]
|
||||
if !ok {
|
||||
return "", fmt.Errorf("unknown prompt type: %s", tp)
|
||||
}
|
||||
if len(pt.Templates) == 0 {
|
||||
return "", fmt.Errorf("no templates for type: %s", tp)
|
||||
}
|
||||
tpl := pt.Templates[rand.Intn(len(pt.Templates))]
|
||||
prompt := fillTemplate(tpl, values)
|
||||
// 计算 token 数
|
||||
toks, err := g.tok.Encode(prompt)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
target := pt.TargetTokens
|
||||
tol := int(float64(target) * 0.05)
|
||||
cnt := len(toks)
|
||||
if cnt < target-tol || cnt > target+tol {
|
||||
// 长度不在范围,用户可根据需要调整
|
||||
}
|
||||
return prompt, nil
|
||||
}
|
||||
|
||||
// CountTokens 返回文本的 token 数
|
||||
func (g *PromptGenerator) CountTokens(text string) (int, error) {
|
||||
toks, err := g.tok.Encode(text)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return len(toks), nil
|
||||
}
|
||||
|
||||
// fillTemplate 用 map[string]string 替换模板中的 {key}
|
||||
func fillTemplate(tpl string, values map[string]string) string {
|
||||
out := tpl
|
||||
for k, v := range values {
|
||||
out = strings.ReplaceAll(out, "{"+k+"}", v)
|
||||
}
|
||||
return out
|
||||
}
|
||||
+227
@@ -0,0 +1,227 @@
|
||||
### 技术选型
|
||||
- **语言**:Go。
|
||||
- **HTTP客户端**:
|
||||
- 抽象接口:`HTTPClient`。
|
||||
- 实现:
|
||||
- `fasthttp`(`github.com/valyala/fasthttp`):高性能,优先选择。
|
||||
- `net/http`(标准库):兼容性强,备选。
|
||||
- **Tokenizer 库**:`github.com/tiktoken-go/tokenizer`。
|
||||
- **并发管理**:goroutine池、`sync.Pool`、`context.Context`。
|
||||
- **数据处理**:`sync.Map`存储响应数据,`gonum/stat`计算百分位数。
|
||||
- **图表生成**:`go-echarts`。
|
||||
|
||||
### 产品需求设计
|
||||
|
||||
#### 功能需求
|
||||
- **API兼容性**:
|
||||
- 支持OpenAI Compatible风格的LLM API(包括`stream=true`的SSE流式响应)。
|
||||
- 兼容推理模型(如DeepSeek-R1)的响应结构,包含`reasoning_content`字段(与`content`同级)。
|
||||
- **HTTP客户端抽象层**:
|
||||
- 定义`HTTPClient`接口,包含以下方法:
|
||||
- `Do(req *Request) (*Response, error)`:发送非流式请求。
|
||||
- `Stream(req *Request, callback func(chunk SSEChunk) error) error`:处理流式响应,逐块回调SSE数据。
|
||||
- 实现:
|
||||
- `fasthttp`:基于`fasthttp.RequestCtx`和`Response.BodyStream`。
|
||||
- `net/http`:基于`http.Client`和`Response.Body`。
|
||||
- 配置项`client: "fasthttp"`或`client: "net-http"`切换客户端。
|
||||
- **提示词生成**:
|
||||
- 使用`tiktoken-go/tokenizer`动态生成短咨询提示词(50 tokens ±5%)和长文档提示词(1000 tokens ±5%)。
|
||||
- **并发请求**:
|
||||
- 支持最大500并发,持续5分钟(300秒)或更长时间。
|
||||
- 使用goroutine池(最大600 goroutine),`sync.Pool`重用请求对象。
|
||||
- 通过`context.Context`支持任务终止。
|
||||
- **场景建模**:
|
||||
- 混合负载:短咨询(50 tokens,70%比例),长文档生成(1000 tokens,30%比例)。
|
||||
- **用户行为模拟**:请求间隔遵循泊松分布(`math/rand`实现)。
|
||||
- **梯度增压**:支持阶梯式加压(50→200→500并发),每阶段持续300秒。
|
||||
- **性能指标收集**:
|
||||
- **请求统计**:总请求数、成功请求数、失败请求数、超时比率(目标:<1%,默认超时30-60秒)。
|
||||
- **响应时间**:平均、最小/最大、P90/P95/P99(目标:<2秒至<10秒,<3秒至<15秒,<5秒至<20秒)。
|
||||
- **TTFT**:
|
||||
- 最小/最大TTFT,P90/P95/P99 TTFT。
|
||||
- 通过SSE流式响应测量,精度达毫秒,兼容`content`和`reasoning_content`。
|
||||
- **QPS**:平均QPS(目标:50-200+),最大QPS。
|
||||
- **Token生成速率**:平均速率(目标:>100 tokens/秒),最大速率,兼容`content`和`reasoning_content`。
|
||||
- **最大有效并发用户数**:记录仍有请求成功的最大并发数(目标:50-500+)。
|
||||
- **报告生成**:
|
||||
- 生成质量报告,包含所有指标统计。
|
||||
- 提供图表(如响应时间分布、TTFT分布、QPS曲线)。
|
||||
|
||||
#### 非功能需求
|
||||
- **高性能**:
|
||||
- 支持500并发,持续5分钟以上,`fasthttp`优化吞吐量,goroutine池降低GC压力。
|
||||
- **统计准确性**:
|
||||
- TTFT和响应时间测量精度达毫秒,使用`time.Now().UnixNano()`。
|
||||
- 使用`sync.Mutex`或`sync/atomic`确保并发统计线程安全。
|
||||
- **可扩展性**:支持新服务提供商、提示词模板、响应字段。
|
||||
- **易用性**:配置文件指定API、提示词、超时、客户端类型(`fasthttp`或`net-http`)。
|
||||
- **稳定性**:长时间运行无崩溃、死锁或内存泄漏。
|
||||
|
||||
#### 技术实现建议
|
||||
- **HTTP客户端抽象层**:
|
||||
- 定义`HTTPClient`接口:
|
||||
```go
|
||||
type HTTPClient interface {
|
||||
Do(req *Request) (*Response, error)
|
||||
Stream(req *Request, callback func(chunk SSEChunk) error) error
|
||||
}
|
||||
type Request struct {
|
||||
Method string
|
||||
URL string
|
||||
Body []byte
|
||||
Headers map[string]string
|
||||
}
|
||||
type Response struct {
|
||||
StatusCode int
|
||||
Body []byte
|
||||
Headers map[string]string
|
||||
}
|
||||
type SSEChunk struct {
|
||||
Data []byte // JSON数据
|
||||
Timestamp int64 // 接收时间戳(UnixNano)
|
||||
IsDone bool // 是否为[data: [DONE]]
|
||||
}
|
||||
```
|
||||
- **fasthttp实现**:
|
||||
- `Do`:使用`fasthttp.Do`,构造OpenAI Compatible JSON请求,解析响应。
|
||||
- `Stream`:使用`fasthttp.Response.BodyStream`,逐行解析SSE(`data: {...}`),调用回调函数传递`SSEChunk`。
|
||||
- 使用`sync.Pool`重用`fasthttp.Request`和`fasthttp.Response`。
|
||||
- **net/http实现**:
|
||||
- `Do`:使用`http.Client.Do`,构造请求,解析响应。
|
||||
- `Stream`:使用`bufio.Scanner`读取`http.Response.Body`,解析SSE,调用回调函数。
|
||||
- **切换逻辑**:
|
||||
- 解析配置项`client`,实例化对应客户端:
|
||||
```go
|
||||
func NewHTTPClient(clientType string) (HTTPClient, error) {
|
||||
switch clientType {
|
||||
case "fasthttp":
|
||||
return &FastHTTPClient{}, nil
|
||||
case "net-http":
|
||||
return &NetHTTPClient{}, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported client: %s", clientType)
|
||||
}
|
||||
}
|
||||
```
|
||||
- **SSE与TTFT处理**:
|
||||
- `Stream`方法逐块解析SSE,提取`choices[0].delta.content`或`choices[0].delta.reasoning_content`。
|
||||
- 记录请求发送时间(`t0 = time.Now().UnixNano()`)。
|
||||
- 检测首个非空Token块,记录时间(`t1`),TTFT = (`t1 - t0`) / 1e6(毫秒)。
|
||||
- 兼容推理模型:优先检查`reasoning_content`,若为空则使用`content`。
|
||||
- **Go性能优化**:
|
||||
- **Goroutine池**:使用`ants`库或自定义池,限制最大600 goroutine。
|
||||
- **对象池**:`sync.Pool`重用请求/响应对象。
|
||||
- **上下文控制**:`context.WithTimeout`设置压测时长(默认300秒)。
|
||||
- **资源监控**:使用`runtime`包记录CPU、内存、goroutine数。
|
||||
- **统计准确性**:
|
||||
- 使用`sync/atomic`累加请求计数。
|
||||
- 使用`sync.Mutex`保护响应时间和TTFT切片。
|
||||
- 使用`gonum/stat`计算P90/P95/P99。
|
||||
- **提示词生成**:`tiktoken-go/tokenizer`动态调整模板至50或1000 tokens。
|
||||
- **报告生成**:`go-echarts`生成图表,模板引擎生成HTML/PDF。
|
||||
|
||||
#### 压测流程
|
||||
1. **配置加载**:读取API端点、客户端类型(`fasthttp`或`net-http`)、并发数、提示词模板等。
|
||||
2. **初始化HTTP客户端**:根据配置项`client`实例化`fasthttp`或`net/http`客户端。
|
||||
3. **提示词生成**:使用`tiktoken-go/tokenizer`生成短咨询(50 tokens)和长文档(1000 tokens)提示词。
|
||||
4. **并发执行**:
|
||||
- 初始化goroutine池(最大600)。
|
||||
- 使用`HTTPClient.Stream`发送请求(`stream=true`),间隔符合泊松分布。
|
||||
- 处理SSE流,记录TTFT。
|
||||
5. **响应处理**:
|
||||
- 解析`content`和`reasoning_content`,计算Token数。
|
||||
- 记录响应时间、TTFT、成功/失败状态。
|
||||
6. **指标计算**:
|
||||
- 计算请求统计、响应时间、TTFT、QPS、Token生成速率、最大并发用户数。
|
||||
7. **报告生成**:输出统计数据和图表。
|
||||
|
||||
#### 配置示例与报告内容
|
||||
以下是更新后的配置和报告示例,包含HTTP客户端抽象层和切换逻辑:
|
||||
|
||||
```yaml
|
||||
# 配置示例
|
||||
api:
|
||||
endpoint: "https://api.example.com/v1/completions"
|
||||
api_key: "your_api_key"
|
||||
model: "deepseek-r1" # 支持推理模型
|
||||
streaming: true # 启用流式响应
|
||||
client: "fasthttp" # HTTP客户端:fasthttp 或 net-http
|
||||
|
||||
prompt_templates:
|
||||
short:
|
||||
target_tokens: 50
|
||||
templates:
|
||||
- "What is the capital of {country}?"
|
||||
- "Please briefly explain the concept of {concept}."
|
||||
- "Summarize the main idea of {topic} in one sentence."
|
||||
long:
|
||||
target_tokens: 1000
|
||||
templates:
|
||||
- "Write a detailed history of {country} covering major events."
|
||||
- "Compose an in-depth analysis of {topic} with examples."
|
||||
- "Generate a comprehensive report on the impact of {event}."
|
||||
|
||||
requests:
|
||||
- type: "short"
|
||||
weight: 0.7
|
||||
- type: "long"
|
||||
weight: 0.3
|
||||
|
||||
concurrency:
|
||||
steps: [50, 200, 500]
|
||||
duration_per_step: 300 # 秒,5分钟
|
||||
max_goroutines: 600 # 最大goroutine数
|
||||
|
||||
timeout: 60 # 秒
|
||||
poisson_lambda: 1.0 # 请求间隔泊松分布参数
|
||||
|
||||
tokenizer:
|
||||
model: "gpt-3.5-turbo" # 用于tiktoken-go的分词器模型
|
||||
|
||||
# 报告内容示例
|
||||
report:
|
||||
overview:
|
||||
api_endpoint: "https://api.example.com/v1/completions"
|
||||
model: "deepseek-r1"
|
||||
concurrency_steps: [50, 200, 500]
|
||||
duration_per_step: "300s"
|
||||
request_mix: "70% short (50 tokens), 30% long (1000 tokens)"
|
||||
tokenizer: "tiktoken-go (gpt-3.5-turbo)"
|
||||
streaming_enabled: true
|
||||
http_client: "fasthttp"
|
||||
metrics:
|
||||
total_requests: 15000
|
||||
successful_requests: 14850
|
||||
failed_requests: 150
|
||||
timeout_ratio: "1.0%"
|
||||
response_time:
|
||||
avg: "1.8s"
|
||||
min: "0.5s"
|
||||
max: "10.2s"
|
||||
p90: "2.5s"
|
||||
p95: "3.0s"
|
||||
p99: "4.5s"
|
||||
ttft:
|
||||
min: "0.1s"
|
||||
max: "2.0s"
|
||||
p90: "0.3s"
|
||||
p95: "0.4s"
|
||||
p99: "0.6s"
|
||||
qps:
|
||||
avg: 180
|
||||
max: 220
|
||||
token_rate:
|
||||
avg: "120 tokens/s"
|
||||
max: "150 tokens/s"
|
||||
max_concurrent_users: 500
|
||||
resource_usage:
|
||||
avg_cpu: "60%"
|
||||
max_memory: "1.1GB"
|
||||
max_goroutines: 600
|
||||
charts:
|
||||
- "response_time_distribution.png"
|
||||
- "ttft_distribution.png"
|
||||
- "qps_over_time.png"
|
||||
- "token_rate_over_time.png"
|
||||
- "concurrency_vs_response_time.png"
|
||||
```
|
||||
@@ -1,327 +0,0 @@
|
||||
package prompt
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/acmestudio/llm-api-benchmark-tool/config"
|
||||
"github.com/acmestudio/llm-api-benchmark-tool/logger"
|
||||
"github.com/pkoukk/tiktoken-go"
|
||||
)
|
||||
|
||||
// 填充词,用于调整提示词长度
|
||||
var fillerWords = []string{
|
||||
"详细", "简要", "请", "麻烦", "帮忙", "认真", "仔细", "全面", "系统性地",
|
||||
"清晰地", "准确地", "深入地", "专业地", "客观地", "科学地", "有条理地",
|
||||
"具体地", "简洁地", "完整地", "精确地", "有逻辑地", "有说服力地",
|
||||
}
|
||||
|
||||
// 长文本填充段落,用于扩展长文档提示词
|
||||
var longFillerParagraphs = []string{
|
||||
"请确保分析全面深入,考虑各个方面的影响和变化。需要包含具体的数据和案例来支持你的观点,同时也要有理论依据。",
|
||||
"在回答中,请注意逻辑性和连贯性,确保各部分之间有合理的过渡。同时,请尽量使用专业术语,但也要确保非专业人士能够理解。",
|
||||
"希望你能够从多个角度进行分析,包括但不限于社会学、经济学、政治学、心理学等视角。同时,也请考虑不同群体、不同地区的差异性。",
|
||||
"在分析中,请注意历史背景和未来趋势,将当前情况放在更广阔的时空背景下考量。同时,也请关注国际比较,了解全球范围内的相似与差异。",
|
||||
"请在回答中提供一些可行的建议或解决方案,这些建议应该是具体的、可操作的,并且考虑到实施过程中可能遇到的困难和阻力。",
|
||||
"在分析问题时,请注意考虑各种可能的因素,包括社会、经济、政治、文化、技术等方面。同时,也请思考这些因素之间的相互作用和影响。",
|
||||
"请在回答中使用清晰的结构,可以考虑使用小标题、要点列表等方式组织内容,使读者能够更容易地理解和把握核心内容。",
|
||||
"在分析过程中,请注意区分事实和观点,确保事实准确无误,观点有理有据。同时,也请尽量避免个人偏见,保持客观中立的态度。",
|
||||
"请确保你的回答既有理论深度,又有实践指导意义。理论分析应该有学术依据,实践建议应该考虑可行性和有效性。",
|
||||
"在回答中,请注意时效性,考虑最新的发展和变化。同时,也请关注长期趋势和基本规律,避免被短期波动所干扰。",
|
||||
}
|
||||
|
||||
// 替换词,用于模板中的占位符
|
||||
var replacements = map[string][]string{
|
||||
"country": {"中国", "美国", "日本", "英国", "法国", "德国", "俄罗斯", "加拿大", "澳大利亚", "巴西", "印度"},
|
||||
"concept": {"人工智能", "机器学习", "区块链", "量子计算", "云计算", "边缘计算", "物联网", "大数据", "虚拟现实", "增强现实"},
|
||||
"topic": {"全球变暖", "可持续发展", "数字化转型", "远程工作", "网络安全", "太空探索", "生物技术", "清洁能源", "智慧城市", "数字隐私"},
|
||||
"event": {"工业革命", "互联网诞生", "冷战", "登月", "柏林墙倒塌", "9/11事件", "COVID-19疫情", "阿拉伯之春", "2008金融危机", "人类基因组计划"},
|
||||
}
|
||||
|
||||
// Generator 提示词生成器
|
||||
type Generator struct {
|
||||
config *config.Config
|
||||
tokenizer *tiktoken.Tiktoken
|
||||
rand *rand.Rand
|
||||
}
|
||||
|
||||
// NewGenerator 创建新的提示词生成器
|
||||
func NewGenerator(cfg *config.Config) (*Generator, error) {
|
||||
// 初始化分词器
|
||||
logger.Debug("初始化分词器,模型: %s", cfg.Tokenizer.Model)
|
||||
tkm, err := tiktoken.EncodingForModel(cfg.Tokenizer.Model)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("初始化分词器失败: %w", err)
|
||||
}
|
||||
logger.Debug("分词器初始化成功")
|
||||
|
||||
// 初始化随机数生成器
|
||||
source := rand.NewSource(time.Now().UnixNano())
|
||||
|
||||
logger.Debug("提示词模板配置 - 短咨询: %d个模板, 目标Token: %d",
|
||||
len(cfg.PromptTemplates.Short.Templates), cfg.PromptTemplates.Short.TargetTokens)
|
||||
logger.Debug("提示词模板配置 - 长文档: %d个模板, 目标Token: %d",
|
||||
len(cfg.PromptTemplates.Long.Templates), cfg.PromptTemplates.Long.TargetTokens)
|
||||
|
||||
return &Generator{
|
||||
config: cfg,
|
||||
tokenizer: tkm,
|
||||
rand: rand.New(source),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GeneratePrompt 生成指定类型的提示词
|
||||
func (g *Generator) GeneratePrompt(promptType string) (string, error) {
|
||||
var templateConfig config.PromptTypeConfig
|
||||
|
||||
// 根据类型选择模板配置
|
||||
switch promptType {
|
||||
case "short":
|
||||
templateConfig = g.config.PromptTemplates.Short
|
||||
case "long":
|
||||
templateConfig = g.config.PromptTemplates.Long
|
||||
default:
|
||||
return "", fmt.Errorf("未知的提示词类型: %s", promptType)
|
||||
}
|
||||
|
||||
// 检查模板是否存在
|
||||
if len(templateConfig.Templates) == 0 {
|
||||
return "", fmt.Errorf("提示词模板为空: %s", promptType)
|
||||
}
|
||||
|
||||
// 随机选择一个模板
|
||||
templateIndex := g.rand.Intn(len(templateConfig.Templates))
|
||||
template := templateConfig.Templates[templateIndex]
|
||||
logger.Debug("为%s类型选择模板 #%d: %s", promptType, templateIndex, template)
|
||||
|
||||
// 替换模板中的占位符
|
||||
prompt := g.replacePlaceholders(template)
|
||||
logger.Debug("替换占位符后: %s", prompt)
|
||||
|
||||
// 调整提示词长度至目标Token数
|
||||
result, err := g.adjustPromptLength(prompt, templateConfig.TargetTokens)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// 计算最终Token数
|
||||
tokens := g.tokenizer.Encode(result, nil, nil)
|
||||
logger.Debug("生成%s类型提示词成功,目标Token: %d, 实际Token: %d",
|
||||
promptType, templateConfig.TargetTokens, len(tokens))
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// replacePlaceholders 替换模板中的占位符
|
||||
func (g *Generator) replacePlaceholders(template string) string {
|
||||
result := template
|
||||
|
||||
// 替换所有占位符
|
||||
for placeholder, options := range replacements {
|
||||
placeholderTag := fmt.Sprintf("{%s}", placeholder)
|
||||
if strings.Contains(result, placeholderTag) {
|
||||
// 随机选择一个替换选项
|
||||
replacementIndex := g.rand.Intn(len(options))
|
||||
replacement := options[replacementIndex]
|
||||
logger.Debug("替换占位符 %s -> %s", placeholderTag, replacement)
|
||||
result = strings.Replace(result, placeholderTag, replacement, -1)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// adjustPromptLength 调整提示词长度至目标Token数
|
||||
func (g *Generator) adjustPromptLength(prompt string, targetTokens int) (string, error) {
|
||||
// 计算当前Token数
|
||||
tokens := g.tokenizer.Encode(prompt, nil, nil)
|
||||
currentTokens := len(tokens)
|
||||
|
||||
// 计算目标范围(±5%)
|
||||
minTokens := int(float64(targetTokens) * 0.95)
|
||||
maxTokens := int(float64(targetTokens) * 1.05)
|
||||
|
||||
logger.Debug("调整提示词长度 - 当前: %d, 目标范围: %d-%d", currentTokens, minTokens, maxTokens)
|
||||
|
||||
// 如果当前Token数在目标范围内,直接返回
|
||||
if currentTokens >= minTokens && currentTokens <= maxTokens {
|
||||
logger.Debug("提示词长度已在目标范围内,无需调整")
|
||||
return prompt, nil
|
||||
}
|
||||
|
||||
// 如果Token数过少,添加填充词
|
||||
if currentTokens < minTokens {
|
||||
logger.Debug("提示词长度过短,需要扩展")
|
||||
return g.extendPrompt(prompt, targetTokens)
|
||||
}
|
||||
|
||||
// 如果Token数过多,截断提示词
|
||||
logger.Debug("提示词长度过长,需要截断")
|
||||
return g.truncatePrompt(prompt, targetTokens)
|
||||
}
|
||||
|
||||
// extendPrompt 通过添加填充词扩展提示词
|
||||
func (g *Generator) extendPrompt(prompt string, targetTokens int) (string, error) {
|
||||
result := prompt
|
||||
|
||||
// 计算当前Token数
|
||||
tokens := g.tokenizer.Encode(result, nil, nil)
|
||||
currentTokens := len(tokens)
|
||||
|
||||
// 计算目标范围
|
||||
minTokens := int(float64(targetTokens) * 0.95)
|
||||
|
||||
// 根据目标token数选择不同的扩展策略
|
||||
if targetTokens > 500 {
|
||||
// 长文档提示词,使用段落填充
|
||||
logger.Debug("使用段落填充扩展长文档提示词")
|
||||
return g.extendPromptWithParagraphs(prompt, targetTokens)
|
||||
}
|
||||
|
||||
// 短咨询提示词,使用填充词
|
||||
logger.Debug("使用填充词扩展短咨询提示词")
|
||||
|
||||
// 添加填充词,直到达到目标Token数
|
||||
fillerCount := 0
|
||||
for currentTokens < minTokens {
|
||||
// 随机选择一个填充词
|
||||
fillerIndex := g.rand.Intn(len(fillerWords))
|
||||
filler := fillerWords[fillerIndex]
|
||||
|
||||
// 在提示词前添加填充词
|
||||
result = filler + " " + result
|
||||
fillerCount++
|
||||
|
||||
// 重新计算Token数
|
||||
tokens = g.tokenizer.Encode(result, nil, nil)
|
||||
currentTokens = len(tokens)
|
||||
|
||||
// 防止无限循环
|
||||
if currentTokens > int(float64(targetTokens)*1.05) {
|
||||
// 如果添加填充词后超过了最大Token数,回退并尝试截断
|
||||
logger.Debug("添加%d个填充词后超过最大Token数,尝试截断", fillerCount)
|
||||
return g.truncatePrompt(result, targetTokens)
|
||||
}
|
||||
|
||||
if fillerCount > 100 {
|
||||
logger.Warn("添加填充词超过100次,尝试使用段落填充")
|
||||
return g.extendPromptWithParagraphs(prompt, targetTokens)
|
||||
}
|
||||
}
|
||||
|
||||
logger.Debug("扩展提示词成功,添加了%d个填充词,当前Token数: %d", fillerCount, currentTokens)
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// extendPromptWithParagraphs 通过添加段落扩展长文档提示词
|
||||
func (g *Generator) extendPromptWithParagraphs(prompt string, targetTokens int) (string, error) {
|
||||
result := prompt
|
||||
|
||||
// 计算当前Token数
|
||||
tokens := g.tokenizer.Encode(result, nil, nil)
|
||||
currentTokens := len(tokens)
|
||||
|
||||
// 计算目标范围
|
||||
minTokens := int(float64(targetTokens) * 0.95)
|
||||
|
||||
// 添加段落,直到达到目标Token数
|
||||
paragraphCount := 0
|
||||
usedParagraphs := make(map[int]bool)
|
||||
|
||||
for currentTokens < minTokens && paragraphCount < 20 {
|
||||
// 随机选择一个未使用的段落
|
||||
var paragraphIndex int
|
||||
for {
|
||||
paragraphIndex = g.rand.Intn(len(longFillerParagraphs))
|
||||
if !usedParagraphs[paragraphIndex] {
|
||||
usedParagraphs[paragraphIndex] = true
|
||||
break
|
||||
}
|
||||
// 如果所有段落都已使用,重置使用记录
|
||||
if len(usedParagraphs) >= len(longFillerParagraphs) {
|
||||
usedParagraphs = make(map[int]bool)
|
||||
}
|
||||
}
|
||||
|
||||
paragraph := longFillerParagraphs[paragraphIndex]
|
||||
|
||||
// 添加段落
|
||||
if paragraphCount == 0 {
|
||||
result = result + "\n\n" + paragraph
|
||||
} else {
|
||||
result = result + "\n\n" + paragraph
|
||||
}
|
||||
paragraphCount++
|
||||
|
||||
// 重新计算Token数
|
||||
tokens = g.tokenizer.Encode(result, nil, nil)
|
||||
currentTokens = len(tokens)
|
||||
|
||||
logger.Debug("添加第%d个段落后,当前Token数: %d", paragraphCount, currentTokens)
|
||||
|
||||
// 如果已经达到目标范围,退出循环
|
||||
if currentTokens >= minTokens {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// 如果添加了最大段落数仍未达到目标,给出警告
|
||||
if currentTokens < minTokens {
|
||||
logger.Warn("即使添加了%d个段落,仍未达到目标Token数(当前: %d, 目标: %d)",
|
||||
paragraphCount, currentTokens, targetTokens)
|
||||
} else {
|
||||
logger.Debug("扩展长文档提示词成功,添加了%d个段落,当前Token数: %d", paragraphCount, currentTokens)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// truncatePrompt 通过截断缩短提示词
|
||||
func (g *Generator) truncatePrompt(prompt string, targetTokens int) (string, error) {
|
||||
// 计算目标范围
|
||||
maxTokens := int(float64(targetTokens) * 1.05)
|
||||
|
||||
// 编码提示词
|
||||
tokens := g.tokenizer.Encode(prompt, nil, nil)
|
||||
|
||||
// 如果Token数超过最大值,截断
|
||||
if len(tokens) > maxTokens {
|
||||
// 保留目标Token数
|
||||
originalLength := len(tokens)
|
||||
tokens = tokens[:maxTokens]
|
||||
|
||||
// 解码截断后的Token
|
||||
result := g.tokenizer.Decode(tokens)
|
||||
logger.Debug("截断提示词成功,从%d个Token截断到%d个Token", originalLength, len(tokens))
|
||||
return result, nil
|
||||
}
|
||||
|
||||
return prompt, nil
|
||||
}
|
||||
|
||||
// SelectPromptType 根据权重随机选择提示词类型
|
||||
func (g *Generator) SelectPromptType() string {
|
||||
// 计算累积权重
|
||||
var cumulativeWeights []float64
|
||||
var sum float64
|
||||
|
||||
for _, req := range g.config.Requests {
|
||||
sum += req.Weight
|
||||
cumulativeWeights = append(cumulativeWeights, sum)
|
||||
}
|
||||
|
||||
// 生成随机数
|
||||
r := g.rand.Float64() * sum
|
||||
|
||||
// 根据随机数选择提示词类型
|
||||
for i, weight := range cumulativeWeights {
|
||||
if r <= weight {
|
||||
return g.config.Requests[i].Type
|
||||
}
|
||||
}
|
||||
|
||||
// 默认返回第一个类型
|
||||
return g.config.Requests[0].Type
|
||||
}
|
||||
@@ -1,635 +0,0 @@
|
||||
package report
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"github.com/acmestudio/llm-api-benchmark-tool/benchmark"
|
||||
"github.com/acmestudio/llm-api-benchmark-tool/config"
|
||||
"github.com/acmestudio/llm-api-benchmark-tool/logger"
|
||||
"github.com/go-echarts/go-echarts/v2/charts"
|
||||
"github.com/go-echarts/go-echarts/v2/components"
|
||||
"github.com/go-echarts/go-echarts/v2/opts"
|
||||
"github.com/montanaflynn/stats"
|
||||
)
|
||||
|
||||
// Metrics 表示性能指标
|
||||
type Metrics struct {
|
||||
TotalRequests int // 总请求数
|
||||
SuccessfulRequests int // 成功请求数
|
||||
FailedRequests int // 失败请求数
|
||||
TimeoutRatio float64 // 超时比率
|
||||
AvgResponseTime time.Duration // 平均响应时间
|
||||
P90ResponseTime time.Duration // P90响应时间
|
||||
P95ResponseTime time.Duration // P95响应时间
|
||||
P99ResponseTime time.Duration // P99响应时间
|
||||
MaxResponseTime time.Duration // 最大响应时间
|
||||
MinResponseTime time.Duration // 最小响应时间
|
||||
AvgQPS float64 // 平均QPS
|
||||
MaxQPS float64 // 最大QPS
|
||||
AvgTokenRate float64 // 平均Token生成速率
|
||||
MaxTokenRate float64 // 最大Token生成速率
|
||||
MaxConcurrency int // 最大有效并发用户数
|
||||
}
|
||||
|
||||
// GenerateReport 生成性能报告
|
||||
func GenerateReport(results *benchmark.BenchmarkResults, cfg *config.Config, outputPath string) error {
|
||||
// 创建输出目录
|
||||
logger.Info("创建报告输出目录: %s", outputPath)
|
||||
if err := os.MkdirAll(outputPath, 0755); err != nil {
|
||||
return fmt.Errorf("创建输出目录失败: %w", err)
|
||||
}
|
||||
|
||||
// 检查结果是否为空
|
||||
if len(results.Results) == 0 {
|
||||
logger.Warn("没有测试结果数据,无法生成详细报告")
|
||||
} else {
|
||||
logger.Debug("共有 %d 条测试结果记录", len(results.Results))
|
||||
}
|
||||
|
||||
// 计算性能指标
|
||||
logger.Info("计算性能指标...")
|
||||
metrics := calculateMetrics(results)
|
||||
|
||||
// 输出主要性能指标
|
||||
logger.Info("性能指标摘要:")
|
||||
logger.Info(" 总请求数: %d (成功: %d, 失败: %d)",
|
||||
metrics.TotalRequests, metrics.SuccessfulRequests, metrics.FailedRequests)
|
||||
logger.Info(" 超时比率: %.2f%%", metrics.TimeoutRatio * 100)
|
||||
logger.Info(" 平均响应时间: %v", metrics.AvgResponseTime)
|
||||
logger.Info(" P90响应时间: %v", metrics.P90ResponseTime)
|
||||
logger.Info(" P95响应时间: %v", metrics.P95ResponseTime)
|
||||
logger.Info(" P99响应时间: %v", metrics.P99ResponseTime)
|
||||
logger.Info(" 平均QPS: %.2f", metrics.AvgQPS)
|
||||
logger.Info(" 最大QPS: %.2f", metrics.MaxQPS)
|
||||
logger.Info(" 平均Token生成速率: %.2f tokens/s", metrics.AvgTokenRate)
|
||||
logger.Info(" 最大Token生成速率: %.2f tokens/s", metrics.MaxTokenRate)
|
||||
logger.Info(" 最大有效并发用户数: %d", metrics.MaxConcurrency)
|
||||
|
||||
// 生成HTML报告
|
||||
logger.Info("生成HTML报告...")
|
||||
if err := generateHTMLReport(results, metrics, cfg, outputPath); err != nil {
|
||||
return fmt.Errorf("生成HTML报告失败: %w", err)
|
||||
}
|
||||
|
||||
// 生成CSV数据
|
||||
logger.Info("生成CSV数据...")
|
||||
if err := generateCSVData(results, outputPath); err != nil {
|
||||
return fmt.Errorf("生成CSV数据失败: %w", err)
|
||||
}
|
||||
|
||||
logger.Info("报告生成完成")
|
||||
return nil
|
||||
}
|
||||
|
||||
// calculateMetrics 计算性能指标
|
||||
func calculateMetrics(results *benchmark.BenchmarkResults) *Metrics {
|
||||
metrics := &Metrics{}
|
||||
|
||||
// 总请求数
|
||||
metrics.TotalRequests = len(results.Results)
|
||||
logger.Debug("计算指标 - 总请求数: %d", metrics.TotalRequests)
|
||||
|
||||
// 统计成功和失败请求
|
||||
var successfulRequests []benchmark.Result
|
||||
for _, result := range results.Results {
|
||||
if result.Error == nil {
|
||||
successfulRequests = append(successfulRequests, result)
|
||||
}
|
||||
}
|
||||
|
||||
metrics.SuccessfulRequests = len(successfulRequests)
|
||||
metrics.FailedRequests = metrics.TotalRequests - metrics.SuccessfulRequests
|
||||
logger.Debug("计算指标 - 成功请求: %d, 失败请求: %d",
|
||||
metrics.SuccessfulRequests, metrics.FailedRequests)
|
||||
|
||||
// 计算超时比率
|
||||
metrics.TimeoutRatio = float64(metrics.FailedRequests) / float64(metrics.TotalRequests)
|
||||
logger.Debug("计算指标 - 超时比率: %.2f%%", metrics.TimeoutRatio * 100)
|
||||
|
||||
// 如果没有成功的请求,返回
|
||||
if len(successfulRequests) == 0 {
|
||||
logger.Warn("没有成功的请求,无法计算详细指标")
|
||||
return metrics
|
||||
}
|
||||
|
||||
// 计算响应时间指标
|
||||
var responseTimes []float64
|
||||
for _, result := range successfulRequests {
|
||||
responseTimes = append(responseTimes, float64(result.ResponseTime.Milliseconds()))
|
||||
}
|
||||
|
||||
// 排序响应时间
|
||||
sort.Float64s(responseTimes)
|
||||
|
||||
// 计算响应时间百分位数
|
||||
p90, _ := stats.Percentile(responseTimes, 90)
|
||||
p95, _ := stats.Percentile(responseTimes, 95)
|
||||
p99, _ := stats.Percentile(responseTimes, 99)
|
||||
avg, _ := stats.Mean(responseTimes)
|
||||
max := responseTimes[len(responseTimes)-1]
|
||||
min := responseTimes[0]
|
||||
|
||||
metrics.AvgResponseTime = time.Duration(avg) * time.Millisecond
|
||||
metrics.P90ResponseTime = time.Duration(p90) * time.Millisecond
|
||||
metrics.P95ResponseTime = time.Duration(p95) * time.Millisecond
|
||||
metrics.P99ResponseTime = time.Duration(p99) * time.Millisecond
|
||||
metrics.MaxResponseTime = time.Duration(max) * time.Millisecond
|
||||
metrics.MinResponseTime = time.Duration(min) * time.Millisecond
|
||||
|
||||
logger.Debug("计算指标 - 响应时间(ms) - 平均: %.2f, P90: %.2f, P95: %.2f, P99: %.2f, 最小: %.2f, 最大: %.2f",
|
||||
avg, p90, p95, p99, min, max)
|
||||
|
||||
// 计算QPS
|
||||
totalDuration := results.EndTime.Sub(results.StartTime).Seconds()
|
||||
metrics.AvgQPS = float64(metrics.SuccessfulRequests) / totalDuration
|
||||
logger.Debug("计算指标 - 平均QPS: %.2f (总持续时间: %.2f秒)", metrics.AvgQPS, totalDuration)
|
||||
|
||||
// 计算每个并发步骤的QPS
|
||||
logger.Debug("计算各并发步骤的QPS...")
|
||||
for concurrency, stepResults := range results.ConcurrencyData {
|
||||
// 找出该步骤的第一个和最后一个请求
|
||||
if len(stepResults) == 0 {
|
||||
logger.Debug(" 并发步骤 %d: 没有请求数据", concurrency)
|
||||
continue
|
||||
}
|
||||
|
||||
// 排序结果,按时间戳
|
||||
sort.Slice(stepResults, func(i, j int) bool {
|
||||
return stepResults[i].Timestamp.Before(stepResults[j].Timestamp)
|
||||
})
|
||||
|
||||
firstRequest := stepResults[0]
|
||||
lastRequest := stepResults[len(stepResults)-1]
|
||||
|
||||
// 计算持续时间
|
||||
stepDuration := lastRequest.Timestamp.Sub(firstRequest.Timestamp).Seconds()
|
||||
if stepDuration <= 0 {
|
||||
logger.Debug(" 并发步骤 %d: 持续时间过短", concurrency)
|
||||
continue
|
||||
}
|
||||
|
||||
// 计算成功请求数
|
||||
var successCount int
|
||||
for _, result := range stepResults {
|
||||
if result.Error == nil {
|
||||
successCount++
|
||||
}
|
||||
}
|
||||
|
||||
// 计算QPS
|
||||
stepQPS := float64(successCount) / stepDuration
|
||||
logger.Debug(" 并发步骤 %d: QPS = %.2f (成功请求: %d, 持续时间: %.2f秒)",
|
||||
concurrency, stepQPS, successCount, stepDuration)
|
||||
|
||||
if stepQPS > metrics.MaxQPS {
|
||||
metrics.MaxQPS = stepQPS
|
||||
logger.Debug(" 更新最大QPS: %.2f (并发步骤: %d)", metrics.MaxQPS, concurrency)
|
||||
}
|
||||
|
||||
// 更新最大并发用户数
|
||||
if concurrency > metrics.MaxConcurrency && stepQPS > 0 {
|
||||
metrics.MaxConcurrency = concurrency
|
||||
logger.Debug(" 更新最大有效并发用户数: %d", metrics.MaxConcurrency)
|
||||
}
|
||||
}
|
||||
|
||||
// 计算Token生成速率
|
||||
var totalTokens int
|
||||
for _, result := range successfulRequests {
|
||||
totalTokens += result.CompletionTokens
|
||||
}
|
||||
|
||||
metrics.AvgTokenRate = float64(totalTokens) / totalDuration
|
||||
logger.Debug("计算指标 - 平均Token生成速率: %.2f tokens/s (总Token: %d)",
|
||||
metrics.AvgTokenRate, totalTokens)
|
||||
|
||||
// 计算每个并发步骤的Token生成速率
|
||||
logger.Debug("计算各并发步骤的Token生成速率...")
|
||||
for concurrency, stepResults := range results.ConcurrencyData {
|
||||
// 找出该步骤的第一个和最后一个请求
|
||||
if len(stepResults) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
// 排序结果,按时间戳
|
||||
sort.Slice(stepResults, func(i, j int) bool {
|
||||
return stepResults[i].Timestamp.Before(stepResults[j].Timestamp)
|
||||
})
|
||||
|
||||
firstRequest := stepResults[0]
|
||||
lastRequest := stepResults[len(stepResults)-1]
|
||||
|
||||
// 计算持续时间
|
||||
stepDuration := lastRequest.Timestamp.Sub(firstRequest.Timestamp).Seconds()
|
||||
if stepDuration <= 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
// 计算总Token数
|
||||
var stepTokens int
|
||||
for _, result := range stepResults {
|
||||
if result.Error == nil {
|
||||
stepTokens += result.CompletionTokens
|
||||
}
|
||||
}
|
||||
|
||||
// 计算Token生成速率
|
||||
stepTokenRate := float64(stepTokens) / stepDuration
|
||||
logger.Debug(" 并发步骤 %d: Token生成速率 = %.2f tokens/s (总Token: %d, 持续时间: %.2f秒)",
|
||||
concurrency, stepTokenRate, stepTokens, stepDuration)
|
||||
|
||||
if stepTokenRate > metrics.MaxTokenRate {
|
||||
metrics.MaxTokenRate = stepTokenRate
|
||||
logger.Debug(" 更新最大Token生成速率: %.2f tokens/s (并发步骤: %d)",
|
||||
metrics.MaxTokenRate, concurrency)
|
||||
}
|
||||
}
|
||||
|
||||
return metrics
|
||||
}
|
||||
|
||||
// generateHTMLReport 生成HTML报告
|
||||
func generateHTMLReport(results *benchmark.BenchmarkResults, metrics *Metrics, cfg *config.Config, outputPath string) error {
|
||||
// 创建页面
|
||||
logger.Debug("创建HTML报告页面...")
|
||||
page := components.NewPage()
|
||||
page.PageTitle = "LLM API 基准测试报告"
|
||||
page.Theme = "white"
|
||||
|
||||
// 添加概述
|
||||
logger.Debug("添加概述图表...")
|
||||
page.AddCharts(createOverviewChart(results, metrics, cfg))
|
||||
|
||||
// 添加响应时间分布图
|
||||
logger.Debug("添加响应时间分布图...")
|
||||
page.AddCharts(createResponseTimeDistributionChart(results))
|
||||
|
||||
// 添加QPS随时间变化图
|
||||
logger.Debug("添加QPS随时间变化图...")
|
||||
page.AddCharts(createQPSOverTimeChart(results))
|
||||
|
||||
// 添加Token生成速率随时间变化图
|
||||
logger.Debug("添加Token生成速率随时间变化图...")
|
||||
page.AddCharts(createTokenRateOverTimeChart(results))
|
||||
|
||||
// 添加并发与响应时间关系图
|
||||
logger.Debug("添加并发与响应时间关系图...")
|
||||
page.AddCharts(createConcurrencyVsResponseTimeChart(results))
|
||||
|
||||
// 保存HTML报告
|
||||
htmlPath := filepath.Join(outputPath, "report.html")
|
||||
logger.Debug("保存HTML报告: %s", htmlPath)
|
||||
f, err := os.Create(htmlPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
return page.Render(f)
|
||||
}
|
||||
|
||||
// createOverviewChart 创建概述图表
|
||||
func createOverviewChart(results *benchmark.BenchmarkResults, metrics *Metrics, cfg *config.Config) *charts.Bar {
|
||||
// 创建图表
|
||||
chart := charts.NewBar()
|
||||
chart.SetGlobalOptions(
|
||||
charts.WithTitleOpts(opts.Title{
|
||||
Title: "性能指标概述",
|
||||
}),
|
||||
)
|
||||
|
||||
// 添加数据
|
||||
chart.SetXAxis([]string{"平均响应时间 (ms)", "P90响应时间 (ms)", "P95响应时间 (ms)", "P99响应时间 (ms)"})
|
||||
chart.AddSeries("响应时间", []opts.BarData{
|
||||
{Value: metrics.AvgResponseTime.Milliseconds()},
|
||||
{Value: metrics.P90ResponseTime.Milliseconds()},
|
||||
{Value: metrics.P95ResponseTime.Milliseconds()},
|
||||
{Value: metrics.P99ResponseTime.Milliseconds()},
|
||||
})
|
||||
|
||||
return chart
|
||||
}
|
||||
|
||||
// createResponseTimeDistributionChart 创建响应时间分布图
|
||||
func createResponseTimeDistributionChart(results *benchmark.BenchmarkResults) *charts.Bar {
|
||||
// 创建图表
|
||||
chart := charts.NewBar()
|
||||
chart.SetGlobalOptions(
|
||||
charts.WithTitleOpts(opts.Title{
|
||||
Title: "响应时间分布",
|
||||
}),
|
||||
)
|
||||
|
||||
// 统计响应时间分布
|
||||
timeRanges := []int{100, 200, 500, 1000, 2000, 5000, 10000}
|
||||
counts := make([]int, len(timeRanges)+1)
|
||||
|
||||
for _, result := range results.Results {
|
||||
if result.Error != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
responseTime := result.ResponseTime.Milliseconds()
|
||||
found := false
|
||||
|
||||
for i, timeRange := range timeRanges {
|
||||
if responseTime <= int64(timeRange) {
|
||||
counts[i]++
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
counts[len(timeRanges)]++
|
||||
}
|
||||
}
|
||||
|
||||
// 构建X轴标签
|
||||
xAxisLabels := make([]string, len(timeRanges)+1)
|
||||
for i, timeRange := range timeRanges {
|
||||
if i == 0 {
|
||||
xAxisLabels[i] = fmt.Sprintf("≤%dms", timeRange)
|
||||
} else {
|
||||
xAxisLabels[i] = fmt.Sprintf("%d-%dms", timeRanges[i-1], timeRange)
|
||||
}
|
||||
}
|
||||
xAxisLabels[len(timeRanges)] = fmt.Sprintf(">%dms", timeRanges[len(timeRanges)-1])
|
||||
|
||||
// 添加数据
|
||||
chart.SetXAxis(xAxisLabels)
|
||||
|
||||
barData := make([]opts.BarData, len(counts))
|
||||
for i, count := range counts {
|
||||
barData[i] = opts.BarData{Value: count}
|
||||
}
|
||||
|
||||
chart.AddSeries("请求数", barData)
|
||||
|
||||
return chart
|
||||
}
|
||||
|
||||
// createQPSOverTimeChart 创建QPS随时间变化图
|
||||
func createQPSOverTimeChart(results *benchmark.BenchmarkResults) *charts.Line {
|
||||
// 创建图表
|
||||
chart := charts.NewLine()
|
||||
chart.SetGlobalOptions(
|
||||
charts.WithTitleOpts(opts.Title{
|
||||
Title: "QPS随时间变化",
|
||||
}),
|
||||
)
|
||||
|
||||
// 按并发步骤分组
|
||||
for concurrency, stepResults := range results.ConcurrencyData {
|
||||
// 按时间窗口统计QPS
|
||||
windowSize := 5 * time.Second
|
||||
|
||||
// 找出该步骤的第一个和最后一个请求
|
||||
if len(stepResults) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
// 排序结果,按时间戳
|
||||
sort.Slice(stepResults, func(i, j int) bool {
|
||||
return stepResults[i].Timestamp.Before(stepResults[j].Timestamp)
|
||||
})
|
||||
|
||||
firstRequest := stepResults[0]
|
||||
lastRequest := stepResults[len(stepResults)-1]
|
||||
|
||||
// 计算时间窗口数
|
||||
duration := lastRequest.Timestamp.Sub(firstRequest.Timestamp)
|
||||
windowCount := int(duration / windowSize) + 1
|
||||
|
||||
// 初始化时间窗口
|
||||
windows := make([]time.Time, windowCount)
|
||||
counts := make([]int, windowCount)
|
||||
|
||||
for i := 0; i < windowCount; i++ {
|
||||
windows[i] = firstRequest.Timestamp.Add(time.Duration(i) * windowSize)
|
||||
}
|
||||
|
||||
// 统计每个时间窗口的请求数
|
||||
for _, result := range stepResults {
|
||||
if result.Error != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
windowIndex := int(result.Timestamp.Sub(firstRequest.Timestamp) / windowSize)
|
||||
if windowIndex >= 0 && windowIndex < windowCount {
|
||||
counts[windowIndex]++
|
||||
}
|
||||
}
|
||||
|
||||
// 计算QPS
|
||||
qpsData := make([]opts.LineData, windowCount)
|
||||
xAxisData := make([]string, windowCount)
|
||||
|
||||
for i := 0; i < windowCount; i++ {
|
||||
qps := float64(counts[i]) / windowSize.Seconds()
|
||||
qpsData[i] = opts.LineData{Value: qps}
|
||||
xAxisData[i] = windows[i].Format("15:04:05")
|
||||
}
|
||||
|
||||
// 添加数据
|
||||
chart.SetXAxis(xAxisData)
|
||||
chart.AddSeries(fmt.Sprintf("并发 %d", concurrency), qpsData)
|
||||
}
|
||||
|
||||
return chart
|
||||
}
|
||||
|
||||
// createTokenRateOverTimeChart 创建Token生成速率随时间变化图
|
||||
func createTokenRateOverTimeChart(results *benchmark.BenchmarkResults) *charts.Line {
|
||||
// 创建图表
|
||||
chart := charts.NewLine()
|
||||
chart.SetGlobalOptions(
|
||||
charts.WithTitleOpts(opts.Title{
|
||||
Title: "Token生成速率随时间变化",
|
||||
}),
|
||||
)
|
||||
|
||||
// 按并发步骤分组
|
||||
for concurrency, stepResults := range results.ConcurrencyData {
|
||||
// 按时间窗口统计Token生成速率
|
||||
windowSize := 5 * time.Second
|
||||
|
||||
// 找出该步骤的第一个和最后一个请求
|
||||
if len(stepResults) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
// 排序结果,按时间戳
|
||||
sort.Slice(stepResults, func(i, j int) bool {
|
||||
return stepResults[i].Timestamp.Before(stepResults[j].Timestamp)
|
||||
})
|
||||
|
||||
firstRequest := stepResults[0]
|
||||
lastRequest := stepResults[len(stepResults)-1]
|
||||
|
||||
// 计算时间窗口数
|
||||
duration := lastRequest.Timestamp.Sub(firstRequest.Timestamp)
|
||||
windowCount := int(duration / windowSize) + 1
|
||||
|
||||
// 初始化时间窗口
|
||||
windows := make([]time.Time, windowCount)
|
||||
tokens := make([]int, windowCount)
|
||||
|
||||
for i := 0; i < windowCount; i++ {
|
||||
windows[i] = firstRequest.Timestamp.Add(time.Duration(i) * windowSize)
|
||||
}
|
||||
|
||||
// 统计每个时间窗口的Token数
|
||||
for _, result := range stepResults {
|
||||
if result.Error != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
windowIndex := int(result.Timestamp.Sub(firstRequest.Timestamp) / windowSize)
|
||||
if windowIndex >= 0 && windowIndex < windowCount {
|
||||
tokens[windowIndex] += result.CompletionTokens
|
||||
}
|
||||
}
|
||||
|
||||
// 计算Token生成速率
|
||||
tokenRateData := make([]opts.LineData, windowCount)
|
||||
xAxisData := make([]string, windowCount)
|
||||
|
||||
for i := 0; i < windowCount; i++ {
|
||||
tokenRate := float64(tokens[i]) / windowSize.Seconds()
|
||||
tokenRateData[i] = opts.LineData{Value: tokenRate}
|
||||
xAxisData[i] = windows[i].Format("15:04:05")
|
||||
}
|
||||
|
||||
// 添加数据
|
||||
chart.SetXAxis(xAxisData)
|
||||
chart.AddSeries(fmt.Sprintf("并发 %d", concurrency), tokenRateData)
|
||||
}
|
||||
|
||||
return chart
|
||||
}
|
||||
|
||||
// createConcurrencyVsResponseTimeChart 创建并发与响应时间关系图
|
||||
func createConcurrencyVsResponseTimeChart(results *benchmark.BenchmarkResults) *charts.Line {
|
||||
// 创建图表
|
||||
chart := charts.NewLine()
|
||||
chart.SetGlobalOptions(
|
||||
charts.WithTitleOpts(opts.Title{
|
||||
Title: "并发与响应时间关系",
|
||||
}),
|
||||
)
|
||||
|
||||
// 准备数据
|
||||
var concurrencies []int
|
||||
var avgResponseTimes []opts.LineData
|
||||
var p90ResponseTimes []opts.LineData
|
||||
var p95ResponseTimes []opts.LineData
|
||||
|
||||
// 按并发步骤排序
|
||||
for concurrency := range results.ConcurrencyData {
|
||||
concurrencies = append(concurrencies, concurrency)
|
||||
}
|
||||
sort.Ints(concurrencies)
|
||||
|
||||
// 计算每个并发步骤的响应时间
|
||||
for _, concurrency := range concurrencies {
|
||||
stepResults := results.ConcurrencyData[concurrency]
|
||||
|
||||
// 收集成功请求的响应时间
|
||||
var responseTimes []float64
|
||||
for _, result := range stepResults {
|
||||
if result.Error == nil {
|
||||
responseTimes = append(responseTimes, float64(result.ResponseTime.Milliseconds()))
|
||||
}
|
||||
}
|
||||
|
||||
// 如果没有成功的请求,跳过
|
||||
if len(responseTimes) == 0 {
|
||||
avgResponseTimes = append(avgResponseTimes, opts.LineData{Value: 0})
|
||||
p90ResponseTimes = append(p90ResponseTimes, opts.LineData{Value: 0})
|
||||
p95ResponseTimes = append(p95ResponseTimes, opts.LineData{Value: 0})
|
||||
continue
|
||||
}
|
||||
|
||||
// 计算响应时间指标
|
||||
avg, _ := stats.Mean(responseTimes)
|
||||
p90, _ := stats.Percentile(responseTimes, 90)
|
||||
p95, _ := stats.Percentile(responseTimes, 95)
|
||||
|
||||
avgResponseTimes = append(avgResponseTimes, opts.LineData{Value: avg})
|
||||
p90ResponseTimes = append(p90ResponseTimes, opts.LineData{Value: p90})
|
||||
p95ResponseTimes = append(p95ResponseTimes, opts.LineData{Value: p95})
|
||||
}
|
||||
|
||||
// 将并发数转换为字符串
|
||||
xAxisData := make([]string, len(concurrencies))
|
||||
for i, concurrency := range concurrencies {
|
||||
xAxisData[i] = fmt.Sprintf("%d", concurrency)
|
||||
}
|
||||
|
||||
// 添加数据
|
||||
chart.SetXAxis(xAxisData)
|
||||
chart.AddSeries("平均响应时间 (ms)", avgResponseTimes)
|
||||
chart.AddSeries("P90响应时间 (ms)", p90ResponseTimes)
|
||||
chart.AddSeries("P95响应时间 (ms)", p95ResponseTimes)
|
||||
|
||||
return chart
|
||||
}
|
||||
|
||||
// generateCSVData 生成CSV数据
|
||||
func generateCSVData(results *benchmark.BenchmarkResults, outputPath string) error {
|
||||
// 创建CSV文件
|
||||
csvPath := filepath.Join(outputPath, "results.csv")
|
||||
logger.Debug("创建CSV文件: %s", csvPath)
|
||||
f, err := os.Create(csvPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
// 写入CSV头
|
||||
logger.Debug("写入CSV头...")
|
||||
_, err = f.WriteString("Timestamp,PromptType,PromptTokens,CompletionTokens,ResponseTime,Concurrency,Error\n")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 检查结果是否为空
|
||||
if len(results.Results) == 0 {
|
||||
logger.Warn("没有测试结果数据,CSV文件将只包含表头")
|
||||
return nil
|
||||
}
|
||||
|
||||
// 写入CSV数据
|
||||
logger.Debug("写入CSV数据,共%d条记录...", len(results.Results))
|
||||
for _, result := range results.Results {
|
||||
// 格式化错误信息
|
||||
errorMsg := ""
|
||||
if result.Error != nil {
|
||||
errorMsg = result.Error.Error()
|
||||
}
|
||||
|
||||
// 写入一行数据
|
||||
line := fmt.Sprintf("%s,%s,%d,%d,%d,%d,%s\n",
|
||||
result.Timestamp.Format(time.RFC3339),
|
||||
result.PromptType,
|
||||
result.PromptTokens,
|
||||
result.CompletionTokens,
|
||||
result.ResponseTime.Milliseconds(),
|
||||
result.Concurrency,
|
||||
errorMsg,
|
||||
)
|
||||
|
||||
_, err = f.WriteString(line)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
logger.Debug("CSV数据写入完成")
|
||||
return nil
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>LLM API 基准测试报告</title>
|
||||
<script src="https://go-echarts.github.io/go-echarts-assets/assets/echarts.min.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
|
||||
|
||||
<style> .container {display: flex;justify-content: center;align-items: center;} .item {margin: auto;} </style>
|
||||
<div class="container">
|
||||
<div class="item" id="LNbBAPYnepJk" style="width:900px;height:500px;"></div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
"use strict";
|
||||
let goecharts_LNbBAPYnepJk = echarts.init(document.getElementById('LNbBAPYnepJk'), "white");
|
||||
let option_LNbBAPYnepJk = {"animation":true,"color":["#5470c6","#91cc75","#fac858","#ee6666","#73c0de","#3ba272","#fc8452","#9a60b4","#ea7ccc"],"legend":{"show":true,"type":""},"series":[{"name":"响应时间","type":"bar","smooth":false,"connectNulls":false,"showSymbol":false,"waveAnimation":false,"renderLabelForZeroData":false,"selectedMode":false,"animation":false,"data":[{"value":40867},{"value":55877},{"value":57093},{"value":59096}]}],"title":{"text":"性能指标概述"},"tooltip":{"show":false},"xAxis":[{"data":["平均响应时间 (ms)","P90响应时间 (ms)","P95响应时间 (ms)","P99响应时间 (ms)"]}],"yAxis":[{}]}
|
||||
;
|
||||
|
||||
let action_LNbBAPYnepJk = {"areas":{},"type":""}
|
||||
;
|
||||
|
||||
goecharts_LNbBAPYnepJk.setOption(option_LNbBAPYnepJk);
|
||||
goecharts_LNbBAPYnepJk.dispatchAction(action_LNbBAPYnepJk);
|
||||
</script>
|
||||
|
||||
<div class="container">
|
||||
<div class="item" id="GOPBARBCnPTU" style="width:900px;height:500px;"></div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
"use strict";
|
||||
let goecharts_GOPBARBCnPTU = echarts.init(document.getElementById('GOPBARBCnPTU'), "white");
|
||||
let option_GOPBARBCnPTU = {"animation":true,"color":["#5470c6","#91cc75","#fac858","#ee6666","#73c0de","#3ba272","#fc8452","#9a60b4","#ea7ccc"],"legend":{"show":true,"type":""},"series":[{"name":"请求数","type":"bar","smooth":false,"connectNulls":false,"showSymbol":false,"waveAnimation":false,"renderLabelForZeroData":false,"selectedMode":false,"animation":false,"data":[{"value":0},{"value":0},{"value":0},{"value":0},{"value":0},{"value":0},{"value":1},{"value":108}]}],"title":{"text":"响应时间分布"},"tooltip":{"show":false},"xAxis":[{"data":["≤100ms","100-200ms","200-500ms","500-1000ms","1000-2000ms","2000-5000ms","5000-10000ms",">10000ms"]}],"yAxis":[{}]}
|
||||
;
|
||||
|
||||
let action_GOPBARBCnPTU = {"areas":{},"type":""}
|
||||
;
|
||||
|
||||
goecharts_GOPBARBCnPTU.setOption(option_GOPBARBCnPTU);
|
||||
goecharts_GOPBARBCnPTU.dispatchAction(action_GOPBARBCnPTU);
|
||||
</script>
|
||||
|
||||
<div class="container">
|
||||
<div class="item" id="XkXZxRAArLPb" style="width:900px;height:500px;"></div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
"use strict";
|
||||
let goecharts_XkXZxRAArLPb = echarts.init(document.getElementById('XkXZxRAArLPb'), "white");
|
||||
let option_XkXZxRAArLPb = {"animation":true,"color":["#5470c6","#91cc75","#fac858","#ee6666","#73c0de","#3ba272","#fc8452","#9a60b4","#ea7ccc"],"legend":{"show":true,"type":""},"series":[{"name":"并发 1","type":"line","smooth":false,"connectNulls":false,"showSymbol":false,"waveAnimation":false,"renderLabelForZeroData":false,"selectedMode":false,"animation":true,"data":[{"value":0.2,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0.2,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0.2,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0.2,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0.2,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0.2,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0.2,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0.2,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0.2,"XAxisIndex":0,"YAxisIndex":0}]},{"name":"并发 5","type":"line","smooth":false,"connectNulls":false,"showSymbol":false,"waveAnimation":false,"renderLabelForZeroData":false,"selectedMode":false,"animation":true,"data":[{"value":0.8,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0.2,"XAxisIndex":0,"YAxisIndex":0},{"value":0.2,"XAxisIndex":0,"YAxisIndex":0},{"value":0.2,"XAxisIndex":0,"YAxisIndex":0},{"value":0.2,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0.2,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0.2,"XAxisIndex":0,"YAxisIndex":0},{"value":0.2,"XAxisIndex":0,"YAxisIndex":0},{"value":0.2,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0.4,"XAxisIndex":0,"YAxisIndex":0},{"value":0.2,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0.2,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0.2,"XAxisIndex":0,"YAxisIndex":0},{"value":0.2,"XAxisIndex":0,"YAxisIndex":0},{"value":0.2,"XAxisIndex":0,"YAxisIndex":0},{"value":0.2,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0.2,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0.2Line truncated
|
||||
;
|
||||
|
||||
let action_XkXZxRAArLPb = {"areas":{},"type":""}
|
||||
;
|
||||
|
||||
goecharts_XkXZxRAArLPb.setOption(option_XkXZxRAArLPb);
|
||||
goecharts_XkXZxRAArLPb.dispatchAction(action_XkXZxRAArLPb);
|
||||
</script>
|
||||
|
||||
<div class="container">
|
||||
<div class="item" id="OFgvWOHKVKpD" style="width:900px;height:500px;"></div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
"use strict";
|
||||
let goecharts_OFgvWOHKVKpD = echarts.init(document.getElementById('OFgvWOHKVKpD'), "white");
|
||||
let option_OFgvWOHKVKpD = {"animation":true,"color":["#5470c6","#91cc75","#fac858","#ee6666","#73c0de","#3ba272","#fc8452","#9a60b4","#ea7ccc"],"legend":{"show":true,"type":""},"series":[{"name":"并发 1","type":"line","smooth":false,"connectNulls":false,"showSymbol":false,"waveAnimation":false,"renderLabelForZeroData":false,"selectedMode":false,"animation":true,"data":[{"value":353.4,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":248,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":316,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":347.2,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":237,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":223.6,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":215,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":338.6,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":289.8,"XAxisIndex":0,"YAxisIndex":0}]},{"name":"并发 5","type":"line","smooth":false,"connectNulls":false,"showSymbol":false,"waveAnimation":false,"renderLabelForZeroData":false,"selectedMode":false,"animation":true,"data":[{"value":1158.8,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":295.8,"XAxisIndex":0,"YAxisIndex":0},{"value":235.4,"XAxisIndex":0,"YAxisIndex":0},{"value":355.6,"XAxisIndex":0,"YAxisIndex":0},{"value":237.8,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":278,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":132.4,"XAxisIndex":0,"YAxisIndex":0},{"value":273.2,"XAxisIndex":0,"YAxisIndex":0},{"value":348.6,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":710.4,"XAxisIndex":0,"YAxisIndex":0},{"value":268.4,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":353.8,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":125,"XAxisIndex":0,"YAxisIndex":0},{"value":298.8,"XAxisIndex":0,"YAxisIndex":0},{"value":306,"XAxisIndex":0,"YAxisIndex":0},{"value":41.2,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":292.6,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxisIndex":0,"YAxisIndex":0},{"value":0,"XAxiLine truncated
|
||||
;
|
||||
|
||||
let action_OFgvWOHKVKpD = {"areas":{},"type":""}
|
||||
;
|
||||
|
||||
goecharts_OFgvWOHKVKpD.setOption(option_OFgvWOHKVKpD);
|
||||
goecharts_OFgvWOHKVKpD.dispatchAction(action_OFgvWOHKVKpD);
|
||||
</script>
|
||||
|
||||
<div class="container">
|
||||
<div class="item" id="PSQeXGkwaeXv" style="width:900px;height:500px;"></div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
"use strict";
|
||||
let goecharts_PSQeXGkwaeXv = echarts.init(document.getElementById('PSQeXGkwaeXv'), "white");
|
||||
let option_PSQeXGkwaeXv = {"animation":true,"color":["#5470c6","#91cc75","#fac858","#ee6666","#73c0de","#3ba272","#fc8452","#9a60b4","#ea7ccc"],"legend":{"show":true,"type":""},"series":[{"name":"平均响应时间 (ms)","type":"line","smooth":false,"connectNulls":false,"showSymbol":false,"waveAnimation":false,"renderLabelForZeroData":false,"selectedMode":false,"animation":true,"data":[{"value":41457,"XAxisIndex":0,"YAxisIndex":0},{"value":40918.05263157895,"XAxisIndex":0,"YAxisIndex":0},{"value":40750.27419354839,"XAxisIndex":0,"YAxisIndex":0}]},{"name":"P90响应时间 (ms)","type":"line","smooth":false,"connectNulls":false,"showSymbol":false,"waveAnimation":false,"renderLabelForZeroData":false,"selectedMode":false,"animation":true,"data":[{"value":50759,"XAxisIndex":0,"YAxisIndex":0},{"value":55646.5,"XAxisIndex":0,"YAxisIndex":0},{"value":55877.5,"XAxisIndex":0,"YAxisIndex":0}]},{"name":"P95响应时间 (ms)","type":"line","smooth":false,"connectNulls":false,"showSymbol":false,"waveAnimation":false,"renderLabelForZeroData":false,"selectedMode":false,"animation":true,"data":[{"value":50759,"XAxisIndex":0,"YAxisIndex":0},{"value":56847.5,"XAxisIndex":0,"YAxisIndex":0},{"value":57093,"XAxisIndex":0,"YAxisIndex":0}]}],"title":{"text":"并发与响应时间关系"},"tooltip":{"show":false},"xAxis":[{"data":["1","5","10"]}],"yAxis":[{}]}
|
||||
;
|
||||
|
||||
let action_PSQeXGkwaeXv = {"areas":{},"type":""}
|
||||
;
|
||||
|
||||
goecharts_PSQeXGkwaeXv.setOption(option_PSQeXGkwaeXv);
|
||||
goecharts_PSQeXGkwaeXv.dispatchAction(action_PSQeXGkwaeXv);
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,125 +0,0 @@
|
||||
Timestamp,PromptType,PromptTokens,ResponseTokens,ResponseTime,ConcurrencyStep,Error
|
||||
2025-04-21T15:29:08+08:00,long,290,1767,50692,1,
|
||||
2025-04-21T15:29:59+08:00,short,32,1240,35591,1,
|
||||
2025-04-21T15:30:35+08:00,long,299,1580,46800,1,
|
||||
2025-04-21T15:31:22+08:00,long,285,1736,50826,1,
|
||||
2025-04-21T15:32:13+08:00,long,294,1185,35257,1,
|
||||
2025-04-21T15:32:48+08:00,long,278,1118,33428,1,
|
||||
2025-04-21T15:33:22+08:00,short,30,1075,31594,1,
|
||||
2025-04-21T15:33:54+08:00,short,35,1693,48817,1,
|
||||
2025-04-21T15:34:43+08:00,short,30,1449,40108,1,
|
||||
2025-04-21T15:35:23+08:00,short,31,1267,39528,5,
|
||||
2025-04-21T15:35:23+08:00,short,34,1331,43050,5,
|
||||
2025-04-21T15:35:23+08:00,long,281,1455,47254,5,
|
||||
2025-04-21T15:35:23+08:00,short,34,1741,54033,5,
|
||||
2025-04-21T15:35:23+08:00,short,0,0,60000,5,发送请求失败: timeout
|
||||
2025-04-21T15:36:07+08:00,short,34,1177,37663,5,
|
||||
2025-04-21T15:36:03+08:00,long,298,1479,47924,5,
|
||||
2025-04-21T15:36:18+08:00,short,36,1189,39376,5,
|
||||
2025-04-21T15:36:11+08:00,long,300,1778,56227,5,
|
||||
2025-04-21T15:36:45+08:00,short,30,662,22887,5,
|
||||
2025-04-21T15:36:23+08:00,long,295,1390,44672,5,
|
||||
2025-04-21T15:36:51+08:00,long,306,1366,44047,5,
|
||||
2025-04-21T15:37:08+08:00,long,298,1342,43062,5,
|
||||
2025-04-21T15:36:57+08:00,long,291,1743,56131,5,
|
||||
2025-04-21T15:37:08+08:00,short,31,1675,52352,5,
|
||||
2025-04-21T15:37:07+08:00,long,294,1877,58539,5,
|
||||
2025-04-21T15:37:52+08:00,short,31,625,19803,5,
|
||||
2025-04-21T15:38:06+08:00,short,33,206,7176,5,
|
||||
2025-04-21T15:37:35+08:00,long,288,1769,55162,5,
|
||||
2025-04-21T15:37:54+08:00,long,296,1494,47829,5,
|
||||
2025-04-21T15:38:01+08:00,long,295,1530,50380,5,
|
||||
2025-04-21T15:38:13+08:00,short,38,1463,45724,5,
|
||||
2025-04-21T15:38:31+08:00,short,34,906,28607,5,
|
||||
2025-04-21T15:38:42+08:00,short,33,691,21916,5,
|
||||
2025-04-21T15:38:12+08:00,long,0,0,60000,5,发送请求失败: timeout
|
||||
2025-04-21T15:38:59+08:00,short,34,676,22665,5,
|
||||
2025-04-21T15:38:51+08:00,short,34,1006,30879,5,
|
||||
2025-04-21T15:38:59+08:00,short,28,1185,36817,5,
|
||||
2025-04-21T15:39:04+08:00,long,281,1688,53184,5,
|
||||
2025-04-21T15:39:22+08:00,short,34,1192,35771,5,
|
||||
2025-04-21T15:39:37+08:00,short,35,922,29691,5,
|
||||
2025-04-21T15:39:12+08:00,long,299,1814,55118,5,
|
||||
2025-04-21T15:39:22+08:00,short,32,1555,46992,5,
|
||||
2025-04-21T15:40:07+08:00,short,33,777,25157,5,
|
||||
2025-04-21T15:39:57+08:00,short,29,1375,41815,5,
|
||||
2025-04-21T15:40:09+08:00,long,292,1278,38409,5,
|
||||
2025-04-21T15:40:06+08:00,long,290,1586,45621,5,
|
||||
2025-04-21T15:39:59+08:00,long,301,1874,57468,5,
|
||||
2025-04-21T15:40:52+08:00,long,287,1565,45984,5,
|
||||
2025-04-21T15:41:39+08:00,short,34,859,25973,5,
|
||||
2025-04-21T15:42:05+08:00,short,33,1031,36665,10,
|
||||
2025-04-21T15:42:05+08:00,short,31,1032,38132,10,
|
||||
2025-04-21T15:42:05+08:00,short,33,1124,41458,10,
|
||||
2025-04-21T15:42:05+08:00,short,31,1209,42973,10,
|
||||
2025-04-21T15:42:05+08:00,short,36,1260,45000,10,
|
||||
2025-04-21T15:42:05+08:00,long,301,1254,45741,10,
|
||||
2025-04-21T15:42:05+08:00,short,0,0,60025,10,发送请求失败: timeout
|
||||
2025-04-21T15:42:05+08:00,long,0,0,60024,10,发送请求失败: timeout
|
||||
2025-04-21T15:42:05+08:00,long,0,0,60024,10,发送请求失败: timeout
|
||||
2025-04-21T15:42:05+08:00,long,0,0,60027,10,发送请求失败: timeout
|
||||
2025-04-21T15:42:43+08:00,short,30,627,24785,10,
|
||||
2025-04-21T15:42:41+08:00,short,33,880,33993,10,
|
||||
2025-04-21T15:42:46+08:00,short,33,763,29495,10,
|
||||
2025-04-21T15:42:48+08:00,short,32,867,34001,10,
|
||||
2025-04-21T15:42:51+08:00,short,32,878,33547,10,
|
||||
2025-04-21T15:43:08+08:00,short,34,959,36283,10,
|
||||
2025-04-21T15:43:05+08:00,short,32,1059,40263,10,
|
||||
2025-04-21T15:42:50+08:00,long,0,0,60001,10,发送请求失败: timeout
|
||||
2025-04-21T15:43:05+08:00,long,302,1515,55759,10,
|
||||
2025-04-21T15:43:05+08:00,short,32,1480,55895,10,
|
||||
2025-04-21T15:43:05+08:00,long,0,0,60025,10,发送请求失败: timeout
|
||||
2025-04-21T15:43:44+08:00,short,34,663,25933,10,
|
||||
2025-04-21T15:43:16+08:00,long,302,1503,55131,10,
|
||||
2025-04-21T15:43:24+08:00,short,34,1385,50030,10,
|
||||
2025-04-21T15:43:16+08:00,long,290,1646,59167,10,
|
||||
2025-04-21T15:43:22+08:00,short,31,1512,56955,10,
|
||||
2025-04-21T15:43:45+08:00,short,28,1248,47396,10,
|
||||
2025-04-21T15:44:05+08:00,short,34,945,35028,10,
|
||||
2025-04-21T15:44:01+08:00,short,35,1134,43283,10,
|
||||
2025-04-21T15:44:15+08:00,short,35,921,32485,10,
|
||||
2025-04-21T15:43:50+08:00,short,34,1628,59025,10,
|
||||
2025-04-21T15:44:11+08:00,short,31,1160,42541,10,
|
||||
2025-04-21T15:44:15+08:00,short,34,1036,41375,10,
|
||||
2025-04-21T15:44:01+08:00,long,286,1507,56831,10,
|
||||
2025-04-21T15:44:48+08:00,short,28,345,13944,10,
|
||||
2025-04-21T15:44:33+08:00,short,28,965,35746,10,
|
||||
2025-04-21T15:44:10+08:00,short,34,1640,59733,10,
|
||||
2025-04-21T15:44:19+08:00,short,31,1563,55769,10,
|
||||
2025-04-21T15:44:54+08:00,short,37,721,27026,10,
|
||||
2025-04-21T15:44:44+08:00,long,291,1268,45194,10,
|
||||
2025-04-21T15:44:58+08:00,short,30,800,31400,10,
|
||||
2025-04-21T15:44:40+08:00,long,287,1422,54009,10,
|
||||
2025-04-21T15:44:49+08:00,short,32,1479,52350,10,
|
||||
2025-04-21T15:45:15+08:00,short,31,728,27863,10,
|
||||
2025-04-21T15:45:09+08:00,short,35,1127,42373,10,
|
||||
2025-04-21T15:44:56+08:00,short,0,0,60001,10,发送请求失败: timeout
|
||||
2025-04-21T15:45:02+08:00,short,34,1491,55425,10,
|
||||
2025-04-21T15:45:10+08:00,short,0,0,60001,10,发送请求失败: timeout
|
||||
2025-04-21T15:45:43+08:00,short,31,814,32256,10,
|
||||
2025-04-21T15:45:21+08:00,long,0,0,60001,10,发送请求失败: timeout
|
||||
2025-04-21T15:45:51+08:00,short,33,808,31357,10,
|
||||
2025-04-21T15:45:30+08:00,long,302,1447,54647,10,
|
||||
2025-04-21T15:45:56+08:00,short,36,761,29637,10,
|
||||
2025-04-21T15:45:42+08:00,short,34,1214,45591,10,
|
||||
2025-04-21T15:45:35+08:00,short,29,1465,54649,10,
|
||||
2025-04-21T15:45:29+08:00,long,0,0,60000,10,发送请求失败: timeout
|
||||
2025-04-21T15:45:58+08:00,short,35,874,34326,10,
|
||||
2025-04-21T15:46:10+08:00,short,27,1111,41640,10,
|
||||
2025-04-21T15:46:21+08:00,short,32,816,32250,10,
|
||||
2025-04-21T15:46:29+08:00,short,32,709,25910,10,
|
||||
2025-04-21T15:46:25+08:00,short,37,863,31820,10,
|
||||
2025-04-21T15:46:32+08:00,short,31,652,24537,10,
|
||||
2025-04-21T15:46:28+08:00,short,30,1034,37449,10,
|
||||
2025-04-21T15:46:15+08:00,long,0,0,60001,10,发送请求失败: timeout
|
||||
2025-04-21T15:46:54+08:00,short,28,607,23222,10,
|
||||
2025-04-21T15:46:26+08:00,long,294,1390,51678,10,
|
||||
2025-04-21T15:46:56+08:00,short,28,705,26915,10,
|
||||
2025-04-21T15:46:23+08:00,long,0,0,60001,10,发送请求失败: timeout
|
||||
2025-04-21T15:46:57+08:00,short,33,818,30689,10,
|
||||
2025-04-21T15:46:30+08:00,short,0,0,60030,10,发送请求失败: timeout
|
||||
2025-04-21T15:46:57+08:00,short,37,1139,40595,10,
|
||||
2025-04-21T15:46:52+08:00,long,293,1659,57231,10,
|
||||
2025-04-21T15:47:30+08:00,short,32,781,24085,10,
|
||||
2025-04-21T15:47:06+08:00,long,300,1785,55860,10,
|
||||
2025-04-21T15:47:49+08:00,long,297,1450,40171,10,
|
||||
|
@@ -1,104 +0,0 @@
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>LLM API 基准测试报告</title>
|
||||
<script src="https://go-echarts.github.io/go-echarts-assets/assets/echarts.min.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
|
||||
|
||||
<style> .container {display: flex;justify-content: center;align-items: center;} .item {margin: auto;} </style>
|
||||
<div class="container">
|
||||
<div class="item" id="EHMZswDJUWqH" style="width:900px;height:500px;"></div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
"use strict";
|
||||
let goecharts_EHMZswDJUWqH = echarts.init(document.getElementById('EHMZswDJUWqH'), "white");
|
||||
let option_EHMZswDJUWqH = {"animation":true,"color":["#5470c6","#91cc75","#fac858","#ee6666","#73c0de","#3ba272","#fc8452","#9a60b4","#ea7ccc"],"legend":{"show":true,"type":""},"series":[{"name":"响应时间","type":"bar","smooth":false,"connectNulls":false,"showSymbol":false,"waveAnimation":false,"renderLabelForZeroData":false,"selectedMode":false,"animation":false,"data":[{"value":0},{"value":0},{"value":0},{"value":0}]}],"title":{"text":"性能指标概述"},"tooltip":{"show":false},"xAxis":[{"data":["平均响应时间 (ms)","P90响应时间 (ms)","P95响应时间 (ms)","P99响应时间 (ms)"]}],"yAxis":[{}]}
|
||||
;
|
||||
|
||||
let action_EHMZswDJUWqH = {"areas":{},"type":""}
|
||||
;
|
||||
|
||||
goecharts_EHMZswDJUWqH.setOption(option_EHMZswDJUWqH);
|
||||
goecharts_EHMZswDJUWqH.dispatchAction(action_EHMZswDJUWqH);
|
||||
</script>
|
||||
|
||||
<div class="container">
|
||||
<div class="item" id="FLqyKjIZgeEc" style="width:900px;height:500px;"></div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
"use strict";
|
||||
let goecharts_FLqyKjIZgeEc = echarts.init(document.getElementById('FLqyKjIZgeEc'), "white");
|
||||
let option_FLqyKjIZgeEc = {"animation":true,"color":["#5470c6","#91cc75","#fac858","#ee6666","#73c0de","#3ba272","#fc8452","#9a60b4","#ea7ccc"],"legend":{"show":true,"type":""},"series":[{"name":"请求数","type":"bar","smooth":false,"connectNulls":false,"showSymbol":false,"waveAnimation":false,"renderLabelForZeroData":false,"selectedMode":false,"animation":false,"data":[{"value":0},{"value":0},{"value":0},{"value":0},{"value":0},{"value":0},{"value":0},{"value":0}]}],"title":{"text":"响应时间分布"},"tooltip":{"show":false},"xAxis":[{"data":["≤100ms","100-200ms","200-500ms","500-1000ms","1000-2000ms","2000-5000ms","5000-10000ms",">10000ms"]}],"yAxis":[{}]}
|
||||
;
|
||||
|
||||
let action_FLqyKjIZgeEc = {"areas":{},"type":""}
|
||||
;
|
||||
|
||||
goecharts_FLqyKjIZgeEc.setOption(option_FLqyKjIZgeEc);
|
||||
goecharts_FLqyKjIZgeEc.dispatchAction(action_FLqyKjIZgeEc);
|
||||
</script>
|
||||
|
||||
<div class="container">
|
||||
<div class="item" id="RXbTCdDVHsPX" style="width:900px;height:500px;"></div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
"use strict";
|
||||
let goecharts_RXbTCdDVHsPX = echarts.init(document.getElementById('RXbTCdDVHsPX'), "white");
|
||||
let option_RXbTCdDVHsPX = {"animation":true,"color":["#5470c6","#91cc75","#fac858","#ee6666","#73c0de","#3ba272","#fc8452","#9a60b4","#ea7ccc"],"legend":{"show":true,"type":""},"series":null,"title":{"text":"QPS随时间变化"},"tooltip":{"show":false},"xAxis":[{}],"yAxis":[{}]}
|
||||
;
|
||||
|
||||
let action_RXbTCdDVHsPX = {"areas":{},"type":""}
|
||||
;
|
||||
|
||||
goecharts_RXbTCdDVHsPX.setOption(option_RXbTCdDVHsPX);
|
||||
goecharts_RXbTCdDVHsPX.dispatchAction(action_RXbTCdDVHsPX);
|
||||
</script>
|
||||
|
||||
<div class="container">
|
||||
<div class="item" id="XNYfcbGGZVDe" style="width:900px;height:500px;"></div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
"use strict";
|
||||
let goecharts_XNYfcbGGZVDe = echarts.init(document.getElementById('XNYfcbGGZVDe'), "white");
|
||||
let option_XNYfcbGGZVDe = {"animation":true,"color":["#5470c6","#91cc75","#fac858","#ee6666","#73c0de","#3ba272","#fc8452","#9a60b4","#ea7ccc"],"legend":{"show":true,"type":""},"series":null,"title":{"text":"Token生成速率随时间变化"},"tooltip":{"show":false},"xAxis":[{}],"yAxis":[{}]}
|
||||
;
|
||||
|
||||
let action_XNYfcbGGZVDe = {"areas":{},"type":""}
|
||||
;
|
||||
|
||||
goecharts_XNYfcbGGZVDe.setOption(option_XNYfcbGGZVDe);
|
||||
goecharts_XNYfcbGGZVDe.dispatchAction(action_XNYfcbGGZVDe);
|
||||
</script>
|
||||
|
||||
<div class="container">
|
||||
<div class="item" id="odZNEMJQVnFD" style="width:900px;height:500px;"></div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
"use strict";
|
||||
let goecharts_odZNEMJQVnFD = echarts.init(document.getElementById('odZNEMJQVnFD'), "white");
|
||||
let option_odZNEMJQVnFD = {"animation":true,"color":["#5470c6","#91cc75","#fac858","#ee6666","#73c0de","#3ba272","#fc8452","#9a60b4","#ea7ccc"],"legend":{"show":true,"type":""},"series":[{"name":"平均响应时间 (ms)","type":"line","smooth":false,"connectNulls":false,"showSymbol":false,"waveAnimation":false,"renderLabelForZeroData":false,"selectedMode":false,"animation":true,"data":null},{"name":"P90响应时间 (ms)","type":"line","smooth":false,"connectNulls":false,"showSymbol":false,"waveAnimation":false,"renderLabelForZeroData":false,"selectedMode":false,"animation":true,"data":null},{"name":"P95响应时间 (ms)","type":"line","smooth":false,"connectNulls":false,"showSymbol":false,"waveAnimation":false,"renderLabelForZeroData":false,"selectedMode":false,"animation":true,"data":null}],"title":{"text":"并发与响应时间关系"},"tooltip":{"show":false},"xAxis":[{"data":[]}],"yAxis":[{}]}
|
||||
;
|
||||
|
||||
let action_odZNEMJQVnFD = {"areas":{},"type":""}
|
||||
;
|
||||
|
||||
goecharts_odZNEMJQVnFD.setOption(option_odZNEMJQVnFD);
|
||||
goecharts_odZNEMJQVnFD.dispatchAction(action_odZNEMJQVnFD);
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1 +0,0 @@
|
||||
Timestamp,PromptType,PromptTokens,CompletionTokens,ResponseTime,Concurrency,Error
|
||||
|
@@ -1,104 +0,0 @@
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>LLM API 基准测试报告</title>
|
||||
<script src="https://go-echarts.github.io/go-echarts-assets/assets/echarts.min.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
|
||||
|
||||
<style> .container {display: flex;justify-content: center;align-items: center;} .item {margin: auto;} </style>
|
||||
<div class="container">
|
||||
<div class="item" id="VtXivSkVGWsI" style="width:900px;height:500px;"></div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
"use strict";
|
||||
let goecharts_VtXivSkVGWsI = echarts.init(document.getElementById('VtXivSkVGWsI'), "white");
|
||||
let option_VtXivSkVGWsI = {"animation":true,"color":["#5470c6","#91cc75","#fac858","#ee6666","#73c0de","#3ba272","#fc8452","#9a60b4","#ea7ccc"],"legend":{"show":true,"type":""},"series":[{"name":"响应时间","type":"bar","smooth":false,"connectNulls":false,"showSymbol":false,"waveAnimation":false,"renderLabelForZeroData":false,"selectedMode":false,"animation":false,"data":[{"value":0},{"value":0},{"value":0},{"value":0}]}],"title":{"text":"性能指标概述"},"tooltip":{"show":false},"xAxis":[{"data":["平均响应时间 (ms)","P90响应时间 (ms)","P95响应时间 (ms)","P99响应时间 (ms)"]}],"yAxis":[{}]}
|
||||
;
|
||||
|
||||
let action_VtXivSkVGWsI = {"areas":{},"type":""}
|
||||
;
|
||||
|
||||
goecharts_VtXivSkVGWsI.setOption(option_VtXivSkVGWsI);
|
||||
goecharts_VtXivSkVGWsI.dispatchAction(action_VtXivSkVGWsI);
|
||||
</script>
|
||||
|
||||
<div class="container">
|
||||
<div class="item" id="vwmlpHKQyHVV" style="width:900px;height:500px;"></div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
"use strict";
|
||||
let goecharts_vwmlpHKQyHVV = echarts.init(document.getElementById('vwmlpHKQyHVV'), "white");
|
||||
let option_vwmlpHKQyHVV = {"animation":true,"color":["#5470c6","#91cc75","#fac858","#ee6666","#73c0de","#3ba272","#fc8452","#9a60b4","#ea7ccc"],"legend":{"show":true,"type":""},"series":[{"name":"请求数","type":"bar","smooth":false,"connectNulls":false,"showSymbol":false,"waveAnimation":false,"renderLabelForZeroData":false,"selectedMode":false,"animation":false,"data":[{"value":0},{"value":0},{"value":0},{"value":0},{"value":0},{"value":0},{"value":0},{"value":0}]}],"title":{"text":"响应时间分布"},"tooltip":{"show":false},"xAxis":[{"data":["≤100ms","100-200ms","200-500ms","500-1000ms","1000-2000ms","2000-5000ms","5000-10000ms",">10000ms"]}],"yAxis":[{}]}
|
||||
;
|
||||
|
||||
let action_vwmlpHKQyHVV = {"areas":{},"type":""}
|
||||
;
|
||||
|
||||
goecharts_vwmlpHKQyHVV.setOption(option_vwmlpHKQyHVV);
|
||||
goecharts_vwmlpHKQyHVV.dispatchAction(action_vwmlpHKQyHVV);
|
||||
</script>
|
||||
|
||||
<div class="container">
|
||||
<div class="item" id="ONXViPrQSJxX" style="width:900px;height:500px;"></div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
"use strict";
|
||||
let goecharts_ONXViPrQSJxX = echarts.init(document.getElementById('ONXViPrQSJxX'), "white");
|
||||
let option_ONXViPrQSJxX = {"animation":true,"color":["#5470c6","#91cc75","#fac858","#ee6666","#73c0de","#3ba272","#fc8452","#9a60b4","#ea7ccc"],"legend":{"show":true,"type":""},"series":null,"title":{"text":"QPS随时间变化"},"tooltip":{"show":false},"xAxis":[{}],"yAxis":[{}]}
|
||||
;
|
||||
|
||||
let action_ONXViPrQSJxX = {"areas":{},"type":""}
|
||||
;
|
||||
|
||||
goecharts_ONXViPrQSJxX.setOption(option_ONXViPrQSJxX);
|
||||
goecharts_ONXViPrQSJxX.dispatchAction(action_ONXViPrQSJxX);
|
||||
</script>
|
||||
|
||||
<div class="container">
|
||||
<div class="item" id="KFGiaxLKrHzO" style="width:900px;height:500px;"></div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
"use strict";
|
||||
let goecharts_KFGiaxLKrHzO = echarts.init(document.getElementById('KFGiaxLKrHzO'), "white");
|
||||
let option_KFGiaxLKrHzO = {"animation":true,"color":["#5470c6","#91cc75","#fac858","#ee6666","#73c0de","#3ba272","#fc8452","#9a60b4","#ea7ccc"],"legend":{"show":true,"type":""},"series":null,"title":{"text":"Token生成速率随时间变化"},"tooltip":{"show":false},"xAxis":[{}],"yAxis":[{}]}
|
||||
;
|
||||
|
||||
let action_KFGiaxLKrHzO = {"areas":{},"type":""}
|
||||
;
|
||||
|
||||
goecharts_KFGiaxLKrHzO.setOption(option_KFGiaxLKrHzO);
|
||||
goecharts_KFGiaxLKrHzO.dispatchAction(action_KFGiaxLKrHzO);
|
||||
</script>
|
||||
|
||||
<div class="container">
|
||||
<div class="item" id="eUNIZaAWZYZJ" style="width:900px;height:500px;"></div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
"use strict";
|
||||
let goecharts_eUNIZaAWZYZJ = echarts.init(document.getElementById('eUNIZaAWZYZJ'), "white");
|
||||
let option_eUNIZaAWZYZJ = {"animation":true,"color":["#5470c6","#91cc75","#fac858","#ee6666","#73c0de","#3ba272","#fc8452","#9a60b4","#ea7ccc"],"legend":{"show":true,"type":""},"series":[{"name":"平均响应时间 (ms)","type":"line","smooth":false,"connectNulls":false,"showSymbol":false,"waveAnimation":false,"renderLabelForZeroData":false,"selectedMode":false,"animation":true,"data":null},{"name":"P90响应时间 (ms)","type":"line","smooth":false,"connectNulls":false,"showSymbol":false,"waveAnimation":false,"renderLabelForZeroData":false,"selectedMode":false,"animation":true,"data":null},{"name":"P95响应时间 (ms)","type":"line","smooth":false,"connectNulls":false,"showSymbol":false,"waveAnimation":false,"renderLabelForZeroData":false,"selectedMode":false,"animation":true,"data":null}],"title":{"text":"并发与响应时间关系"},"tooltip":{"show":false},"xAxis":[{"data":[]}],"yAxis":[{}]}
|
||||
;
|
||||
|
||||
let action_eUNIZaAWZYZJ = {"areas":{},"type":""}
|
||||
;
|
||||
|
||||
goecharts_eUNIZaAWZYZJ.setOption(option_eUNIZaAWZYZJ);
|
||||
goecharts_eUNIZaAWZYZJ.dispatchAction(action_eUNIZaAWZYZJ);
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1 +0,0 @@
|
||||
Timestamp,PromptType,PromptTokens,CompletionTokens,ResponseTime,Concurrency,Error
|
||||
|
Reference in new issue
Block a user