在EC2实例中运行的docker容器中运行的Web服务器响应非常缓慢 [英] web server running inside a docker container running inside an EC2 instance responses very slowly

查看:513
本文介绍了在EC2实例中运行的docker容器中运行的Web服务器响应非常缓慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web服务器在AWS EC2 Ubuntu实例的docker容器中运行。将请求发送到Web服务器时,响应速度非常慢(大多数情况下,响应时间会有所变化,但大多数情况下为20秒以上)。 虽然不超时。 Web服务器非常轻巧。只是测试,所以几乎什么也没做。

I have a web server running inside a docker container in AWS EC2 Ubuntu instance. When I send requests to the web server, I get the response very slowly (20+ seconds most of the times, although the response time varies). It does not time-out though. The web server is a very lightweight. It is only to test, so almost does not do anything.

docker version 17.03.0-ce

docker-compose version 1.12.0-rc1



到目前为止我的调试方式



How I debugged so far


  1. 在EC2实例中从向运行在Docker容器中的docker服务器发送请求时(url ='http: // localhost:xxxx / api')仍然很慢。所以应该与从外部发送请求无关。

  1. When sending requests to the web server running in the docker container from within the EC2 instance (url = ' http:// localhost:xxxx/api ') it is still very slow. So should not be related to sending requests from outside.

我直接在EC2内部运行另一个Web服务器 (不在docker中)容器),而它 。它的响应速度非常快。

I run another web server inside the EC2 directly (not in a docker container), and it is not slow. It responses very fastly.

我在EC2中的另一个Docker容器中运行了另一个Web服务器 ,并且慢!

I run another web server inside another docker container in EC2, and it is also very slow!

当我将请求从docker容器内部的发送到其中运行的Web服务器时, (在其本地主机上),它也非常慢

When I send the request from inside the docker container to the web server that is running in it (at its localhost), it is also very slow!

我在同一容器上使用同一命令运行容器Mac计算机,并且获取响应并不慢!

I run the containers with the same command on my mac computer and the get response is not slow!

这里是容器统计信息之一:

Here is one of the containers stats:

CPU %: 0.28%

MEM USAGE / LIMIT: 27.49 MiB / 992.5 MiB

MEM %: 2.77%

NET I/O: 53.7 kB / 30.5 kB

BLOCK I/O: 2.24 MB / 0 B

我知道可能很难知道这个问题。我的问题是调试原因并最终找到解决方案的步骤。感谢您能详细解释您的方法。

I understand it might be very hard to know the issue. My question is the steps to debug the cause and finally find the solution. I appreciate if you could explain your approach in detail.

推荐答案

这听起来像是名称解析问题。
要调试此功能,您可以执行其他操作。

This sounds like a name resolution problem. To debug this, you can do different things.


  • 您可以先使用<$启动一个简单的tcp服务器c $ c> nc -l -p 8000 在docker容器(以 -p 8000:8000 开始)中,并且在主机上启动: nc 127.0.0.1 8000 ,键入一些字符,看看TCP通信是否正常,它们应该出现在容器中。

  • You can first start a simple tcp server with nc -l -p 8000 within the docker container (which is started -p 8000:8000), and the on the host launch: nc 127.0.0.1 8000, type some charachter, see if the TCP communication works, they should appear within the container.

接下来,您可以执行与以前相同的操作,但是使用 localhost代替 127.0.0.1

Next, you can do the same as before but using "localhost" instead of 127.0.0.1

此后,您可以执行相同的HTTP请求,但是使用 127.0.0.1 而不是 localhost (这会将请求的 Host:标头设置为相同的值,网络服务器可能不会检查该值,或者可能更容易解决)。

After this, you can do the same HTTP request you did, but using 127.0.0.1 instead of localhost (this will set the request's Host: header to the same value, which the webserver might not check , or might resolve more easily).

您还可以查看生成的 / etc / hosts 和容器中的 /etc/resolv.conf

You can also have have a look at the generated /etc/hosts and /etc/resolv.conf within the container. Maybe they do not make sense in the network context of your container.

此外,如果请求的时间恰好接近一秒钟,那么您可以精确地测量请求的时间,这听起来又像是DNS超时(如果是5.003、10.200、20.030秒,则就像X秒超时,加上响应所需的实时时间)。

Also, you can precisely measure the time needed for your requests, if they are near a precise second, this sounds once more like a DNS timeout (if it's 5.003, 10.200, 20.030 seconds, it's like a X seconds timeout, plus the real time needed to respond).

这篇关于在EC2实例中运行的docker容器中运行的Web服务器响应非常缓慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆