go - 负载测试 dropwizard 端点

标签 go load-testing dropwizard

我的 Dropwizard 配置如下:

server:
  applicationConnectors:
    - type: http
      port: 8080
  adminConnectors:
    - type: http
      port: 8081
  minThreads: 50
  type: default
  maxThreads: 1024
  maxQueuedRequests: 1024
  gzip:
    enabled: true
    minimumEntitySize: 128B
    bufferSize: 8KB
    deflateCompressionLevel: 9
    includedMethods: [POST, GET]

我编写了一个简单的 go 代码来对这个端点进行负载测试,以找出它可以维持的最大 RPS。
func init() {
    // Customize the Transport to have larger connection pool
    defaultRoundTripper := http.DefaultTransport
    defaultTransportPointer, ok := defaultRoundTripper.(*http.Transport)
    if !ok {
        panic(fmt.Sprintf("defaultRoundTripper not an *http.Transport"))
    }
    defaultTransport := *defaultTransportPointer // dereference it to get a copy of the struct that the pointer points to
    defaultTransport.MaxIdleConns = 500
    defaultTransport.MaxIdleConnsPerHost = 450

    myClient = &http.Client{Transport: &defaultTransport}
}

//HitHelloWorldService ...
func HitHelloWorldService() {
    fmt.Println("Hitting the Hello World Service")
    resp, err := myClient.Get(helloWorldEndpoint)

    if err != nil {
        fmt.Printf("Error while hitting endpoint : %v\n", err)
        return
    }
    io.Copy(ioutil.Discard, resp.Body)
    defer resp.Body.Close()
}

我已将 prometheus 与 dropwizard 集成,并使用 grafana 绘制 RPS。要非常确定RPS。

现在的问题是,使用以下 go 代码调用上述函数。
func main() {
    fmt.Println("Hello !! Starting with go-client to benchmark dropwizard endpoints")

    var wg sync.WaitGroup
    for i := 0; i < 400; i++ {
        wg.Add(1)
        go httpclients.HitHelloWorldService()
    }

    wg.Wait()

}


我收到以下错误。
Get http://127.0.0.1:8080/helloWorld: read tcp 127.0.0.1:53576->127.0.0.1:8080: read: connection reset by peer

我能够达到的最大吞吐量是 300 RPS。

注意:我在本地 mac 机器上运行此代码。配置如下:

内存:16 GB 1600 MHz DDR3
处理器:2.2 GHz 英特尔酷睿 i7

获取 http://127.0.0.1:8080/helloWorld :读取 tcp 127.0.0.1:53567->127.0.0.1:8080:读取:对等方重置连接

如何在本地 Mac 机器上获得更高的 RPS。我该如何解决:对等方重置连接问题。

最佳答案

在 Dropwizard 级别无需更改任何内容即可达到 15000 RPS。但是重写了 go 代码。这次我使用了一个工作池。

const (
    numJobs    int = 5000000
    numWorkers int = 150
)

func worker(id int, jobs <-chan int, results chan<- bool) {
    for j := range jobs {
        fmt.Printf("Processing Job No : %v\n", j)
        httpclients.HitHelloWorldService()
        results <- true
    }
}

func main() {
    fmt.Println("Hello !! Starting with go-client to benchmark dropwizard endpoints")

    jobs := make(chan int, numJobs)
    results := make(chan bool, numJobs)

    for w := 1; w < numWorkers; w++ {
        go worker(w, jobs, results)
    }

    for j := 1; j <= numJobs; j++ {
        jobs <- j
    }

    close(jobs)
    for a := 1; a <= numJobs; a++ {
        <-results
    }
}


Grafana graph capturing the RPS and ResponseTime of the endpoint

这确实绕过了问题,但仍然不确定为什么 对等问题重置连接 第一次来。

关于go - 负载测试 dropwizard 端点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61615219/

相关文章:

jmeter - 如何配置JMeter线程组在10秒内处理100万个请求?

visual-studio - 在 Azure 中使用 Visual Studio Online 加载测试性能计数器

java - 如何在过滤器方法中使用 ContainerRequestContext 获取 REST api 的有效负载

java - 我的应用程序没有响应前端给出的请求并抛出 CORS 异常

java - Spring - 以编程方式生成一组 bean

go - 在golang中 `something`是什么意思

go - 并行表驱动的go测试失败

go - 在 Golang 项目中正确包含 C 库(按源代码)

go - exec.Command 设置输出流未获取所有数据

testing - JMeter 没有从正则表达式提取器中替换引用变量