英文:
Are there any performance issues when running Golang apps on elastic beanstalk?
问题
我正在尝试对一个简单的"go" HTTP服务器进行基准测试。
我进行了两个测试:
- 使用亚马逊EC2 - m3.medium实例
- 使用亚马逊弹性Beanstalk - 同样是m3.medium单实例
在第一个设置中,我可以达到每秒18,000个请求。
在第二个设置中,只有每秒1,600个请求。
源代码:(来自: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)
}
对于这样巨大的性能差异是否有任何解释?
PS:
基准测试工具:https://github.com/wg/wrk
另外,一个重要的事情是:弹性Beanstalk始终将nginx作为其应用程序的反向代理(对于Go应用程序,我无法将其删除)
在第一个设置中,根本没有nginx。
英文:
I'm trying to benchmark a simple 'hello world' HTTP server in go
.
I've made 2 tests:
- Using amazon ec2 - m3.medium instance
- 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 <br>
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
得分: 2
简短回答:你测量的不是同一样东西。在你自己的实例上,你测量的是原生的Go Web服务器,而在Beanstalk上,你测量的是Nginx后面的原生Go Web服务器。
详细回答:
如果你在AWS Elastic Beanstalk中使用单实例配置,你会得到与使用EC2相同的实例。
在单实例Beanstalk环境中,你不会得到一个Elastic Load Balancer。
如果你使用Beanstalk,你会得到一个预先部署的nginx(正如你已经提到的)。
Nginx对性能有很大影响,特别是在单CPU配置下,比如m3.medium实例。
你测量到的性能影响绝不是由Beanstalk直接引起的,而是由你的部署配置引起的。
为了避免性能下降,你可以选择使用原生的Go Web服务器。
为了支持我的观点,我进行了一些测试来展示性能。
以下数字是在与工作负载位于同一数据中心的EC2 m3.medium实例上运行wrk生成的。
我在Beanstalk上安装了与原生EC2实例上相同的Go应用程序,并安装了与Beanstalk使用相同配置的NGINX服务器。
./wrk http://<server>/ --duration 20s --connections 300
Beanstalk m3.medium实例直接访问:9230.52请求/秒
Beanstalk m3.medium实例NGINX:1502.14请求/秒
EC2 m3.medium实例直接访问:13649.46请求/秒
EC2 m3.medium实例NGINX:2489.78请求/秒
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论