【发布时间】:2020-05-05 14:15:15
【问题描述】:
我的 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 Intel Core i7
获取http://127.0.0.1:8080/helloWorld:读取tcp 127.0.0.1:53567->127.0.0.1:8080:读取:对等方重置连接
如何在本地 mac 机器上获得更高的 RPS。我该如何解决:connection reset by peer 问题。
【问题讨论】:
-
这可能是由多种原因引起的;这似乎是服务器在负载过大时的故障模式。但是,值得注意的是,这个测试告诉你的很少,因为负载源和服务器运行在同一台机器上,共享资源。有效的负载测试必须将两者分开。
标签: go load-testing dropwizard