负载测试dropwizard端点

问题描述 投票:0回答:1

我的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()
}

我将普罗米修斯与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 Intel Core i7

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

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

go load-testing dropwizard
1个回答
0
投票

如果在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

这确实解决了问题,但是仍然不确定为什么由对等问题重置连接第一次出现。

© www.soinside.com 2019 - 2024. All rights reserved.