修改秒杀

This commit is contained in:
JACKYMYPERSON
2025-09-14 21:12:37 +08:00
parent db98ed80e2
commit 2ab7614ea0
8 changed files with 314 additions and 257 deletions

View File

@@ -20,7 +20,7 @@ type Response struct {
}
func main() {
const totalBatches = 5 // 固定发送5批请求
const totalBatches = 1 // 固定发送5批请求
const batchSize = 150 // 每批固定150个请求
const interval = 5 * time.Second // 每批请求的时间间隔(可按需调整)
var wg sync.WaitGroup
@@ -30,7 +30,7 @@ func main() {
// 循环发送5批请求每批对应不同的商品orderstock10000 ~ stock10004
for batch := 1; batch <= totalBatches; batch++ {
// 计算当前批次的目标商品order第1批→stock10000第2批→stock10001...第5批→stock10004
targetOrder := fmt.Sprintf("stock1000%d", batch-1)
targetOrder := fmt.Sprintf("stock:1000%d", batch-1)
fmt.Printf("=== 开始第 %d 批请求 ===\n", batch)
fmt.Printf("当前批次目标商品: %s | 请求数量: %d 个 | 开始时间: %v\n",
targetOrder, batchSize, time.Now().Format("15:04:05"))
@@ -72,11 +72,6 @@ func main() {
fmt.Println("🎉 所有5批请求已全部完成")
}
type UserRequest1 struct {
UserID int `json:"user_id"`
Order string `json:"userorder"` // 对应商品标识stock10000 ~ stock10004
}
// 发送POST请求接收用户ID和商品order构造请求体
func sendPostRequest(userID int, order string) (*Response, error) {
// 目标接口地址(根据实际部署调整)