Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qps problem #32

Closed
chua4380 opened this issue Sep 9, 2020 · 4 comments
Closed

qps problem #32

chua4380 opened this issue Sep 9, 2020 · 4 comments

Comments

@chua4380
Copy link

chua4380 commented Sep 9, 2020

如果单测http请求,最大能达到多大的qps呢?

@link1st
Copy link
Owner

link1st commented Sep 11, 2020

单台机器 4核,压测工具分配一核,http server 分配一核
压测结果是 接近2W QPS

---------------- 2020年 9月13日 星期日 11时14分48秒 CST 补充--------------
单台机器8核机器,压测结果是 4W QPS

@link1st
Copy link
Owner

link1st commented Sep 12, 2020

我刚在阿里云申请机器(4核4G内存 硬盘是SSD的),压测了一下,QPS都是1.1万以上(go-stress-testing 单核cpu)

这里有压测示例,可以参考一下:

压测示例

  • 简单的修改一下,然后QPS可以达到1.8W, (go-stress-testing 双核cpu),机器性能更高这个数值会更高

  • 这里需要让出双核给go-stress-testing使用
    代码修改处

        # 这里默认设置1,因为设置为1已经可以达到1W多QPS了,一般的环境压测已经够用了
	runtime.GOMAXPROCS(2)
  • webSevers 使用两核
package main

import (
    "log"
    "net/http"
    "runtime"
)

const (
    httpPort = "8088"
)

func main() {

    runtime.GOMAXPROCS(runtime.NumCPU() - 2)
    hello := func(w http.ResponseWriter, req *http.Request) {
        data := "Hello, go-stress-testing! \n"

        w.Header().Add("Server", "golang")
        w.Write([]byte(data))

        return
    }

    http.HandleFunc("/", hello)
    err := http.ListenAndServe(":"+httpPort, nil)

    if err != nil {
        log.Fatal("ListenAndServe: ", err)
    }
}
  • 压测结果
─────┬───────┬───────┬───────┬────────┬────────┬────────┬────────┬────────
 耗时│ 并发数│ 成功数│ 失败数│   qps  │最长耗时│最短耗时│平均耗时│ 错误码
─────┼───────┼───────┼───────┼────────┼────────┼────────┼────────┼────────
   1s│     50│  14914│      0│18934.49│    9.23│    0.14│    0.05│200:14914
   2s│     50│  29782│      0│18858.30│    9.23│    0.13│    0.05│200:29782
   3s│     50│  44707│      0│18896.09│    9.23│    0.13│    0.05│200:44707
   4s│     50│  59431│      0│18855.79│    9.23│    0.13│    0.05│200:59438
   5s│     50│  74158│      0│18808.65│    9.88│    0.11│    0.05│200:74158
   6s│     50│  89118│      0│18819.66│    9.88│    0.11│    0.05│200:89118
   7s│     50│ 103870│      0│18817.46│    9.88│    0.11│    0.05│200:103870
   8s│     50│ 118742│      0│18813.89│    9.88│    0.11│    0.05│200:118742
   9s│     50│ 133466│      0│18789.33│    9.88│    0.11│    0.05│200:133466
  10s│     50│ 148417│      0│18792.07│    9.88│    0.11│    0.05│200:148417
  11s│     50│ 163218│      0│18784.73│    9.88│    0.11│    0.05│200:163218
  12s│     50│ 178074│      0│18776.90│    9.88│    0.11│    0.05│200:178074
  13s│     50│ 193088│      0│18789.44│   10.00│    0.11│    0.05│200:193088
  14s│     50│ 208040│      0│18792.23│   10.00│    0.11│    0.05│200:208040
  15s│     50│ 222913│      0│18793.01│   10.00│    0.11│    0.05│200:222913
  16s│     50│ 237838│      0│18797.81│   10.00│    0.11│    0.05│200:237838
  17s│     50│ 252754│      0│18800.27│   10.00│    0.11│    0.05│200:252754
  18s│     50│ 267747│      0│18806.46│   10.00│    0.11│    0.05│200:267747
  19s│     50│ 282767│      0│18810.77│   10.00│    0.11│    0.05│200:282767
  20s│     50│ 297592│      0│18794.86│   10.00│    0.11│    0.05│200:297592
  21s│     50│ 312306│      0│18783.67│   10.00│    0.11│    0.05│200:312306
  22s│     50│ 327172│      0│18787.24│   10.00│    0.11│    0.05│200:327172
  23s│     50│ 341958│      0│18777.17│   10.00│    0.11│    0.05│200:341958
  24s│     50│ 356835│      0│18777.52│   10.00│    0.11│    0.05│200:356835
  25s│     50│ 371560│      0│18768.69│   10.23│    0.11│    0.05│200:371560
  26s│     50│ 386398│      0│18775.99│   10.23│    0.11│    0.05│200:386398
  27s│     50│ 401230│      0│18768.21│   10.23│    0.11│    0.05│200:401230
  28s│     50│ 416096│      0│18759.15│   10.23│    0.11│    0.05│200:416096
  29s│     50│ 430992│      0│18757.52│   10.23│    0.11│    0.05│200:430992
  30s│     50│ 445942│      0│18753.45│   10.23│    0.11│    0.05│200:445942
  31s│     50│ 460944│      0│18763.31│   10.23│    0.11│    0.05│200:460944
  32s│     50│ 475966│      0│18765.11│   10.23│    0.11│    0.05│200:475966
  33s│     50│ 490832│      0│18767.78│   10.23│    0.11│    0.05│200:490832
  34s│     50│ 500000│      0│18818.59│   10.23│    0.11│    0.05│200:500000
  • top 结果
Tasks: 121 total,   2 running, 119 sleeping,   0 stopped,   0 zombie
%Cpu(s): 43.9 us, 25.8 sy,  0.0 ni, 20.5 id,  0.0 wa,  1.1 hi,  8.7 si,  0.0 st
MiB Mem :   3777.8 total,   2297.2 free,    265.3 used,   1215.3 buff/cache
MiB Swap:      0.0 total,      0.0 free,      0.0 used.   3285.5 avail Mem

    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
   4354 root      20   0 1084396  19836   5624 R 170.0   0.5   0:26.91 go-stre+
   4239 root      20   0 1157404  18832   5168 S 114.3   0.5   1:48.64 server

@link1st link1st closed this as completed Sep 17, 2020
@ccrzzu
Copy link

ccrzzu commented Feb 19, 2024

// 平均 QPS 成功数总协程数/总耗时 (每秒)
if processingTime != 0 {
qps = float64(successNum
concurrent) * (1e9 / float64(processingTime))
}
代码中QPS的计算逻辑可以解释一下吗?

@link1st
Copy link
Owner

link1st commented Feb 20, 2024

@ccrzzu 计算公式可以查看这个 issue #26

// 平均 QPS 成功数_总协程数/总耗时 (每秒) if processingTime != 0 { qps = float64(successNum_concurrent) * (1e9 / float64(processingTime)) } 代码中QPS的计算逻辑可以解释一下吗?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants