简体   繁体   English

无法连接到 ec2 实例上的 Tomcat 服务器

[英]Failed to connect to Tomcat server on ec2 instance

UPDATE :更新

  1. My goal is to learn what factors could overwhelm my little tomcat server.我的目标是了解哪些因素会使我的小型 tomcat 服务器不堪重负。 And when some exception happens, what I could do to resolve or remediate it without switching my server to a better machine.当发生一些异常时,我可以做些什么来解决或修复它,而无需将我的服务器切换到更好的机器。 This is not a real app in a production environment but just my own experiment (Besides some changes on the server-side, I may also do something on my client-side)这不是生产环境中的真正应用程序,而只是我自己的实验(除了服务器端的一些更改之外,我还可能在客户端做一些事情)

  2. Both of my client and server are very simple: the server only checks the URL format and send 201 code if it is correct.我的客户端和服务器都非常简单:服务器只检查 URL 格式,如果正确则发送 201 代码。 Each request sent from my client only includes an easy JSON body.从我的客户发送的每个请求仅包含一个简单的 JSON 主体。 There is no database involved.不涉及数据库。 The two machines (t2-micro) only run client and server respectively.两台机器(t2-micro)只分别运行客户端和服务器。

  3. My client is OkHttpClient() .我的客户是OkHttpClient() To avoid timeout exceptions, I already set timeout 1,000,000 milli secs via setConnectTimeout , setReadTimeout , and setWriteTimeout .为了避免超时异常,我已经通过setConnectTimeoutsetReadTimeoutsetWriteTimeout设置了超时 1,000,000 毫秒。 I also go to $CATALINA/conf/server.xml on my server and set connectionTimeout = "-1" (infinite)我还在我的服务器上将 go 设置为$CATALINA/conf/server.xml并设置connectionTimeout = "-1" (无限)

ORIGINAL POST:原帖:

I'm trying to stress out my server by having a client launching 3000+ threads sending HTTP requests to my server.我试图通过让客户端启动 3000 多个线程向我的服务器发送 HTTP 请求来给我的服务器施加压力。 Both of my client and server reside on different ec2 instances.我的客户端和服务器都驻留在不同的 ec2 实例上。

Initially, I encountered some timeout issues, but after I set the connection, read and write timeout to a bigger value, this exception has been resolved.最初,我遇到了一些超时问题,但是在我将连接、读写超时设置为更大的值后,此异常已得到解决。 However, with the same specification, I'm getting java.net.ConnectException: Failed to connect to my_host_ip:8080 exception.但是,使用相同的规范,我得到java.net.ConnectException: Failed to connect to my_host_ip:8080异常。 And I do not know its root cause.我不知道它的根本原因。 I'm new to multithreading and distributed system, can anyone please give me some insights of this exception?我是多线程和分布式系统的新手,谁能给我一些关于这个异常的见解?

Below is some screenshot of from my ec2:下面是我的 ec2 的一些截图:

1. Client: 1. 客户:

在此处输入图像描述 在此处输入图像描述

2. Server: 2. 服务器:

在此处输入图像描述

在此处输入图像描述

Having gone through similar exercise in past I can say that there is no definitive answer to the problem of scaling.在过去经历过类似的练习后,我可以说对于缩放问题没有明确的答案。

Here are some general trouble shooting steps that may lead to more specific information.以下是一些可能导致更具体信息的一般故障排除步骤。 I would suggest trying out tests by tweaking a few parameters in each test and measure the changes in Cpu, logs etc.我建议通过调整每个测试中的一些参数来尝试测试,并测量 Cpu、日志等的变化。

  1. Please provide what value you have put for the timeout.请提供您为超时设置的值。 Increasing timeout could cause your server (or client) to run out of threads quickly (cause each thread can process for longer).增加超时可能会导致您的服务器(或客户端)快速耗尽线程(因为每个线程可以处理更长的时间)。 Question the need for increasing timeout.质疑增加超时的必要性。 Is there any processing that slows your server?是否有任何处理会减慢您的服务器?

  2. Check application logs, JVM usage, memory usage on the client and Server.检查客户端和服务器上的应用程序日志、JVM 使用情况、memory 使用情况。 There will be some hints there.那里会有一些提示。

  3. Your client seems to be hitting 99%+ and then come down.您的客户似乎达到了 99% 以上,然后下降了。 This implies that there could be a problem at the client side in that it maxes out during the test.这意味着客户端可能存在问题,因为它在测试期间达到最大值。 Your might want to resize your client to be able to do more.您可能希望调整客户端的大小以便能够做更多事情。

  4. Look at open file handles.查看打开的文件句柄。 The number should be sufficiently high.数量应该足够高。

  5. Tomcat has some limit on thread count to handle load. Tomcat 对处理负载的线程数有一些限制。 You can check this in server.xml and if required change it to handle more.您可以在 server.xml 中检查这一点,如果需要,可以更改它以处理更多。 Although cpu doesn't actually max out on server side so unlikely that this is the problem.尽管 cpu 实际上并没有在服务器端达到最大值,所以这不太可能是问题所在。

  6. If you a database then check the performance of the database.如果你是一个数据库然后检查数据库的性能。 Also check jdbc connect settings.还要检查 jdbc 连接设置。 There is thread and timeout config at jdbc level as well. jdbc 级别也有线程和超时配置。

  7. Is response compression set up on the Tomcat? Tomcat 上是否设置了响应压缩? It will give much better throughout on server especially if the data being sent back by each request is more than a few kbs.它会在服务器上提供更好的整体效果,特别是如果每个请求发回的数据超过几 kbs。

--------Update---------- - - - - 更新 - - - - -

Based on update on question few more thoughts.基于问题的更新,还有更多的想法。

Since the application is fairly simple, the path in terms of stressing the server should be to start low and increase load in increments whilst monitoring various things (cpu, memory, JVM usage, file handle count, network i/o).由于应用程序相当简单,因此强调服务器的路径应该是从低开始并逐步增加负载,同时监控各种事物(cpu、memory、JVM 使用情况、文件句柄计数、网络 i/o)。

The increments of load should be spread over several runs.负载的增量应分布在多次运行中。 Start with something as low as 100 parallel threads.从低至 100 个并行线程开始。

Record as much information as you can after each run and if the server holds up well, increase load.每次运行后尽可能多地记录信息,如果服务器运行良好,则增加负载。

Suggested increments 100, 200, 500, 1000, 1500, 2000, 2500, 3000.建议的增量为 100、200、500、1000、1500、2000、2500、3000。

At some level you will see that the server can no longer take it.在某种程度上,您会看到服务器无法再接受它。 That would be your breaking point.那将是你的突破点。

As you increase load and monitor you will likely discover patterns that suggest tuning of specific parameters.随着您增加负载和监控,您可能会发现建议调整特定参数的模式。 Each tuning attempt should then be tested again the same level of multi threading.然后应该再次测试每次调整尝试的相同级别的多线程。 The improvement of available will be obvious from the monitoring.从监控来看,可用度的提高是显而易见的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM