Repository navigation
Expand file tree
/
Copy pathload-test.go
More file actions
108 lines (88 loc) · 2.2 KB
/
Copy pathload-test.go
File metadata and controls
108 lines (88 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"sync"
"time"
)
const (
apiURL = "http://<NODE-IP>:30081/v1/chat/completions"
concurrency = 5
totalRequests = 20
)
type ChatMessage struct {
Role string `json:"role"`
Content string `json:"content"`
}
type ChatRequest struct {
Model string `json:"model"`
Messages []ChatMessage `json:"messages"`
}
type ChatResponse struct {
Choices []struct {
Message ChatMessage `json:"message"`
} `json:"choices"`
Usage struct {
PromptTokens int `json:"prompt_tokens"`
CompletionTokens int `json:"completion_tokens"`
TotalTokens int `json:"total_tokens"`
} `json:"usage"`
}
func sendRequest() (int, time.Duration) {
reqBody := ChatRequest{
Model: "qwen/qwen3-32B",
Messages: []ChatMessage{
{Role: "user", Content: "Write a short poem about the ocean."},
},
}
jsonData, _ := json.Marshal(reqBody)
start := time.Now()
resp, err := http.Post(apiURL, "application/json", bytes.NewBuffer(jsonData))
if err != nil {
log.Printf("Request error: %v", err)
return 0, 0
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
var chatResp ChatResponse
_ = json.Unmarshal(body, &chatResp)
duration := time.Since(start)
return chatResp.Usage.CompletionTokens, duration
}
func main() {
var wg sync.WaitGroup
reqChan := make(chan struct{}, concurrency)
var totalTokens int
var totalTime time.Duration
var mu sync.Mutex
startTest := time.Now()
for i := 0; i < totalRequests; i++ {
wg.Add(1)
reqChan <- struct{}{} // concurrency limit
go func() {
defer wg.Done()
tokens, duration := sendRequest()
mu.Lock()
totalTokens += tokens
totalTime += duration
mu.Unlock()
<-reqChan
}()
}
wg.Wait()
elapsed := time.Since(startTest)
tps := float64(totalTokens) / elapsed.Seconds()
fmt.Println("```markdown")
fmt.Println("## vLLM Load Test Results\n")
fmt.Println("| Metric | Value |")
fmt.Println("|--------|-------|")
fmt.Printf("| Total Requests | %d |\n", totalRequests)
fmt.Printf("| Total Tokens | %d |\n", totalTokens)
fmt.Printf("| Total Time (s) | %.2f |\n", elapsed.Seconds())
fmt.Printf("| Tokens per Second | %.2f |\n", tps)
fmt.Println("```")
}