AWS ELB(弹性负载平衡器)有时会立即返回504(网关超时)

问题描述:

我目前正在将应用程序切换到亚马逊,但是我注意到有时收到的响应是504.我们的系统设置为在ELB前面有一个LB,然后直接转到雄猫

I am currently switching over an application to amazon but I'm noticing that sometimes the response I receive is a 504. Our system is setup in a way where we have a LB in front of our ELB and then it goes straight to tomcat.

我们当前正在对服务中的所有请求进行计时,并在Servlet过滤器中记录响应时间,这些请求始终小于1秒.然后,我们查看LB日志并看到504,看来ELB不知何故正在超时并返回504.

We are currently timing all our requests in our service and in the servlet filter logging the response time and they are always less than 1s. We then look at the LB logs and are seeing a 504 and it appears that somehow the ELB is timing out and returning the 504.

有人知道为什么会这样吗? 谢谢

Does anyone know why this could happen? Thanks

不确定是否重要,但是目前我们只有1个实例,并且可以扩展到3个实例.

Not sure if it matters but currently we only have 1 instance and it can scale to 3 instances.

众所周知,亚马逊的ELB无法很好地处理突发请求,因为在它们的下面只是运行某些代理解决方案的一组自动缩放实例( HAProxy,我猜).因此,它会随着负载的增加而扩展,就像用户定义的自动扩展组所做的那样,然后,当您爆发时,您可能会在启动其他实例时错过一些请求. 当您希望为特定事件承担此类工作量时,可以请求ELB热身支持,但不能将其作为永久配置.他们会询问您确切的安排时间,并在结束后恢复正常行为.

Amazon's ELB is known to not to handle very well sudden bursts of requests, because underneath they're just an auto-scaling group of instances running some proxy solution (HAProxy, I guess). So, it scales out as the load increases, just like an user-defined auto-scaling group would do, then, when you get bursts, you will probably miss some requests while it is launching additional instances. When you expect to have such a kind of workload for a specific event, you can request an ELB warm-up to the support, but you can't have it as a permanent configuration. They will ask you an exact scheduled for it, and resume to the normal behavior after the end of it.

因此,对于某些应用程序和用例,Amazon的ELB并不是最佳解决方案.我不知道这是否是您的情况,但这还是要考虑的一点.

So, for some applications and use-cases, Amazon's ELB is not the best solution. I don't know if this is your case, but it's a point to consider, anyway.