dtng25909 2017-02-14 17:50
浏览 18

在弹性beantalk上运行Golang应用程序时是否存在任何性能问题?

I'm trying to benchmark a simple 'hello world' HTTP server in go. I've made 2 tests:

  1. Using amazon ec2 - m3.medium instance
  2. Using amazon elastic beanstalk - also with m3.medium single instance

On the first setup, I could get up to 18k req/sec. On the second, 1.6k req/sec.

Source code:(from: https://golang.org/doc/articles/wiki/)

package main

import (
    "fmt"
    "net/http"
)

func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:])
}

func main() {
    http.HandleFunc("/", handler)
    http.ListenAndServe(":8080", nil)
}

Is there any explanation for such a huge performance difference?

PS: benchmark tool: https://github.com/wg/wrk
Also, one important thing is: Elastic beanstalk always adds nginx as a reverse proxy for it's applications(and for Go apps I was not able to remove it) On the first setup, there was no nginx at all.

  • 写回答

1条回答 默认 最新

  • dongme8388 2017-02-14 21:30
    关注

    The short answer: You were not measuring the same thing. On your own instance, you measured the native Go Webserver whereas on Beanstalk you measured Nginx with a native Go Web server behind.

    The long answer:

    If you are using AWS Elastic Beanstalk in a Single Instance Configuration, you receive the exact same instance as if you are using EC2. You do not receive an Elastic Load Balancer in front of a single instance Beanstalk environment.

    If you are using the Beanstalk, you will get a predeployed nginx (as you already stated). Nginx has a significant impact on the performance, especially in a single CPU configuration as with the m3.medium instance.

    The performance impact you measured were by no means caused directly by Beanstalk, but by your deployment configuration. To avoid this decrease in performance, you may choose to use the native Go Web server.


    To support my reasoning I run some tests to demonstrate the performance. The following numbers were generated by running wrk on an EC2 m3.medium instance in the same datacenter as the workload was located.

    I installed the same Go application on Beanstalk as on the native EC2 instance, and I installed a NGINX server with the same configuration as Beanstalk is using.

    ./wrk http://<server>/ --duration 20s --connections 300
    
    Beanstalk m3.medium instance DIRECT:  9230.52 Requests / sec
    Beanstalk m3.medium instance NGINX:   1502.14 Requests / sec
    EC2 m3.medium instance DIRECT:       13649.46 Requests / sec
    EC2 m3.medium instance NGINX:         2489.78 Requests / sec
    
    评论

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line