Go 负载测试dropwizard端点

Go 负载测试dropwizard端点,go,load-testing,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 mini

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

}

我所能达到的最大吞吐量是300转/秒

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

内存:16 GB 1600 MHz DDR3 处理器:2.2 GHz Intel Core i7

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


如何在本地mac计算机上实现更高的RPS。如何解决:通过对等方重置连接的问题

在Dropwizard级别,Well可以在不改变任何内容的情况下达到15000转/秒。但是重写了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
    }
}

const(
numJobs int=5000000
numWorkers int=150
)

func-worker(id-int,jobsWell可以在Dropwizard级别实现15000转/秒,而无需更改任何内容。但是重写了go代码。这次我使用了一个worker池

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
    }
}

const(
numJobs int=5000000
numWorkers int=150
)

func工人(id int,jobs这可能是由多种原因造成的;这似乎是服务器在负载过大时的故障模式。但是,值得注意的是,此测试告诉您的信息很少,因为负载源和服务器运行在同一台机器上,共享资源。有效的负载测试必须将两者分开。可能是cau被许多事情所困扰;这似乎是服务器在过度负载下的故障模式。但是,值得注意的是,此测试告诉您的信息很少,因为负载源和服务器运行在同一台机器上,共享资源。有效的负载测试必须将两者分开。