gpt4 book ai didi

java - Dropwizard 线程等待计数增加,服务器停止响应所有资源请求

转载 作者:行者123 更新时间:2023-11-30 08:17:58 26 4
gpt4 key购买 nike

我使用 DropWizard 框架创建了一个 RestFul 应用程序,在处理了大约 20 个请求后应用程序就停止响应了。在日志文件中未发现错误/异常条目。

通过管理员控制分析统计,我发现jvm.threads.waiting.count =47 随着每个新请求的增加而不断增加。

应用程序没有在其中实现多线程,因此应用程序没有机会进入等待状态。

此外,如果我重新启动应用程序,它工作正常。

下面是未收到响应的请求之一的 header

*152226 INFO  c.s.j.a.c.filter.LoggingFilter - 22 * Server in-bound request*
*22 > POST http://text.com/quotes*
*22 > Accept-Language: en-US,en;q=0.5*
*22 > Host: localhost:8080*
*22 > Content-Length: 1041*
*22 > Accept-Encoding: gzip, deflate*
*22 > User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:34.0) *Gecko/20100101Firefox/34.0*
*22 > Trace-Id: kiki-12345*
*22 > Connection: keep-alive*

请求数据没有被有意共享。

连netstat都查不出原因

我想知道这是应用程序级别的问题还是由于 DropWizard 应用程序配置不正确造成的?

管理部分的完整统计数据如下,另外我有兴趣了解下面的每一项数据,并请求分享一个解释这些字段的链接。

===========================

{
"version": "3.0.0",
"gauges": {
"jvm.buffers.direct.capacity": {
"value": 1466889
},
"jvm.buffers.direct.count": {
"value": 116
},
"jvm.buffers.direct.used": {
"value": 1466990
},
"jvm.buffers.mapped.capacity": {
"value": 0
},
"jvm.buffers.mapped.count": {
"value": 0
},
"jvm.buffers.mapped.used": {
"value": 0
},
"jvm.gc.PS-MarkSweep.count": {
"value": 16
},
"jvm.gc.PS-MarkSweep.time": {
"value": 1354
},
"jvm.gc.PS-Scavenge.count": {
"value": 21
},
"jvm.gc.PS-Scavenge.time": {
"value": 153
},
"jvm.memory.heap.committed": {
"value": 177733632
},
"jvm.memory.heap.init": {
"value": 64984960
},
"jvm.memory.heap.max": {
"value": 924844032
},
"jvm.memory.heap.usage": {
"value": 0.02400968728962939
},
"jvm.memory.heap.used": {
"value": 22205216
},
"jvm.memory.non-heap.committed": {
"value": 50266112
},
"jvm.memory.non-heap.init": {
"value": 24576000
},
"jvm.memory.non-heap.max": {
"value": 136314880
},
"jvm.memory.non-heap.usage": {
"value": 0.30244334294245795
},
"jvm.memory.non-heap.used": {
"value": 41227528
},
"jvm.memory.pools.Code-Cache.usage": {
"value": 0.03484217325846354
},
"jvm.memory.pools.PS-Eden-Space.usage": {
"value": 0.027302608311733353
},
"jvm.memory.pools.PS-Old-Gen.usage": {
"value": 0.018778225297105475
},
"jvm.memory.pools.PS-Perm-Gen.usage": {
"value": 0.45908793007455223
},
"jvm.memory.pools.PS-Survivor-Space.usage": {
"value": 0
},
"jvm.memory.total.committed": {
"value": 227999744
},
"jvm.memory.total.init": {
"value": 89560960
},
"jvm.memory.total.max": {
"value": 1061158912
},
"jvm.memory.total.used": {
"value": 63434984
},
"jvm.threads.blocked.count": {
"value": 0
},
"jvm.threads.count": {
"value": 78
},
"jvm.threads.daemon.count": {
"value": 8
},
"jvm.threads.deadlocks": {
"value": [ ]
},
"jvm.threads.new.count": {
"value": 0
},
"jvm.threads.runnable.count": {
"value": 23
},
"jvm.threads.terminated.count": {
"value": 0
},
"jvm.threads.timed_waiting.count": {
"value": 8
},
"jvm.threads.waiting.count": {
"value": 47
},
"org.eclipse.jetty.util.thread.QueuedThreadPool.dw.jobs": {
"value": 0
},
"org.eclipse.jetty.util.thread.QueuedThreadPool.dw.size": {
"value": 33
},
"org.eclipse.jetty.util.thread.QueuedThreadPool.dw.utilization": {
"value": 0.9696969696969697
}
},
"counters": {
"io.dropwizard.jetty.MutableServletContextHandler.active-dispatches": {
"count": 28
},
"io.dropwizard.jetty.MutableServletContextHandler.active-requests": {
"count": 28
},
"io.dropwizard.jetty.MutableServletContextHandler.active-suspended": {
"count": 0
}
},
"histograms": { },
"meters": {
"ch.qos.logback.core.Appender.all": {
"count": 1,
"m15_rate": 7.747995257374595e-22,
"m1_rate": 0.008714462773784218,
"m5_rate": 0.000016544813111326462,
"mean_rate": 0.00035368404453324113,
"units": "events/second"
},
"ch.qos.logback.core.Appender.debug": {
"count": 0,
"m15_rate": 0,
"m1_rate": 0,
"m5_rate": 0,
"mean_rate": 0,
"units": "events/second"
},
"ch.qos.logback.core.Appender.error": {
"count": 0,
"m15_rate": 0,
"m1_rate": 0,
"m5_rate": 0,
"mean_rate": 0,
"units": "events/second"
},
"ch.qos.logback.core.Appender.info": {
"count": 1,
"m15_rate": 7.747995257374595e-22,
"m1_rate": 0.008714462773784218,
"m5_rate": 0.000016544813111326462,
"mean_rate": 0.00035368403287775683,
"units": "events/second"
},
"ch.qos.logback.core.Appender.trace": {
"count": 0,
"m15_rate": 0,
"m1_rate": 0,
"m5_rate": 0,
"mean_rate": 0,
"units": "events/second"
},
"ch.qos.logback.core.Appender.warn": {
"count": 0,
"m15_rate": 0,
"m1_rate": 0,
"m5_rate": 0,
"mean_rate": 0,
"units": "events/second"
},
"io.dropwizard.jetty.MutableServletContextHandler.1xx-responses": {
"count": 0,
"m15_rate": 0,
"m1_rate": 0,
"m5_rate": 0,
"mean_rate": 0,
"units": "events/second"
},
"io.dropwizard.jetty.MutableServletContextHandler.2xx-responses": {
"count": 13,
"m15_rate": 4.94961760464336e-10,
"m1_rate": 0.0034421634791656336,
"m5_rate": 0.000711983613661116,
"mean_rate": 0.004598973132381405,
"units": "events/second"
},
"io.dropwizard.jetty.MutableServletContextHandler.3xx-responses": {
"count": 0,
"m15_rate": 0,
"m1_rate": 0,
"m5_rate": 0,
"mean_rate": 0,
"units": "events/second"
},
"io.dropwizard.jetty.MutableServletContextHandler.4xx-responses": {
"count": 3,
"m15_rate": 2.5736064313211317e-20,
"m1_rate": 0.00018660583536242524,
"m5_rate": 0.0000018719139194908126,
"mean_rate": 0.0010613014574099948,
"units": "events/second"
},
"io.dropwizard.jetty.MutableServletContextHandler.5xx-responses": {
"count": 3,
"m15_rate": 1.3432085553605237e-10,
"m1_rate": 0.0008942559715277348,
"m5_rate": 0.00019309079729952434,
"mean_rate": 0.001061301432161492,
"units": "events/second"
},
"io.dropwizard.jetty.MutableServletContextHandler.async-dispatches": {
"count": 0,
"m15_rate": 0,
"m1_rate": 0,
"m5_rate": 0,
"mean_rate": 0,
"units": "events/second"
},
"io.dropwizard.jetty.MutableServletContextHandler.async-timeouts": {
"count": 0,
"m15_rate": 0,
"m1_rate": 0,
"m5_rate": 0,
"mean_rate": 0,
"units": "events/second"
}
},
"timers": {
"com.flightnetwork.insurance.resource.Book.book": {
"count": 0,
"max": 0,
"mean": 0,
"min": 0,
"p50": 0,
"p75": 0,
"p95": 0,
"p98": 0,
"p99": 0,
"p999": 0,
"stddev": 0,
"m15_rate": 0,
"m1_rate": 0,
"m5_rate": 0,
"mean_rate": 0,
"duration_units": "seconds",
"rate_units": "calls/second"
},
"com.flightnetwork.insurance.resource.Policies.doSearch": {
"count": 0,
"max": 0,
"mean": 0,
"min": 0,
"p50": 0,
"p75": 0,
"p95": 0,
"p98": 0,
"p99": 0,
"p999": 0,
"stddev": 0,
"m15_rate": 0,
"m1_rate": 0,
"m5_rate": 0,
"mean_rate": 0,
"duration_units": "seconds",
"rate_units": "calls/second"
},
"com.flightnetwork.insurance.resource.Quote.getQuote": {
"count": 16,
"max": 2.218201954,
"mean": 0.5852605546875,
"min": 0.36994936300000003,
"p50": 0.468106361,
"p75": 0.533698946,
"p95": 2.218201954,
"p98": 2.218201954,
"p99": 2.218201954,
"p999": 2.218201954,
"stddev": 0.4414850207038381,
"m15_rate": 6.29282616000388e-10,
"m1_rate": 0.004336419450693371,
"m5_rate": 0.0009050744109606403,
"mean_rate": 0.005660256743426155,
"duration_units": "seconds",
"rate_units": "calls/second"
},
"com.flightnetwork.insurance.resource.Refund.doRefund": {
"count": 0,
"max": 0,
"mean": 0,
"min": 0,
"p50": 0,
"p75": 0,
"p95": 0,
"p98": 0,
"p99": 0,
"p999": 0,
"stddev": 0,
"m15_rate": 0,
"m1_rate": 0,
"m5_rate": 0,
"mean_rate": 0,
"duration_units": "seconds",
"rate_units": "calls/second"
},
"io.dropwizard.jetty.MutableServletContextHandler.connect-requests": {
"count": 0,
"max": 0,
"mean": 0,
"min": 0,
"p50": 0,
"p75": 0,
"p95": 0,
"p98": 0,
"p99": 0,
"p999": 0,
"stddev": 0,
"m15_rate": 0,
"m1_rate": 0,
"m5_rate": 0,
"mean_rate": 0,
"duration_units": "seconds",
"rate_units": "calls/second"
},
"io.dropwizard.jetty.MutableServletContextHandler.delete-requests": {
"count": 0,
"max": 0,
"mean": 0,
"min": 0,
"p50": 0,
"p75": 0,
"p95": 0,
"p98": 0,
"p99": 0,
"p999": 0,
"stddev": 0,
"m15_rate": 0,
"m1_rate": 0,
"m5_rate": 0,
"mean_rate": 0,
"duration_units": "seconds",
"rate_units": "calls/second"
},
"io.dropwizard.jetty.MutableServletContextHandler.dispatches": {
"count": 19,
"max": 2.2550000000000003,
"mean": 0.5016315789473684,
"min": 0.001,
"p50": 0.46,
"p75": 0.528,
"p95": 2.2550000000000003,
"p98": 2.2550000000000003,
"p99": 2.2550000000000003,
"p999": 2.2550000000000003,
"stddev": 0.463604622080103,
"m15_rate": 6.292826160261246e-10,
"m1_rate": 0.004523025286055793,
"m5_rate": 0.0009069463248801308,
"mean_rate": 0.006721571867253656,
"duration_units": "seconds",
"rate_units": "calls/second"
},
"io.dropwizard.jetty.MutableServletContextHandler.get-requests": {
"count": 3,
"max": 0.05,
"mean": 0.017666666666666667,
"min": 0.001,
"p50": 0.002,
"p75": 0.05,
"p95": 0.05,
"p98": 0.05,
"p99": 0.05,
"p999": 0.05,
"stddev": 0.028005951748393293,
"m15_rate": 2.5736064313211317e-20,
"m1_rate": 0.00018660583536242524,
"m5_rate": 0.0000018719139194908126,
"mean_rate": 0.001061300945529201,
"duration_units": "seconds",
"rate_units": "calls/second"
},
"io.dropwizard.jetty.MutableServletContextHandler.head-requests": {
"count": 0,
"max": 0,
"mean": 0,
"min": 0,
"p50": 0,
"p75": 0,
"p95": 0,
"p98": 0,
"p99": 0,
"p999": 0,
"stddev": 0,
"m15_rate": 0,
"m1_rate": 0,
"m5_rate": 0,
"mean_rate": 0,
"duration_units": "seconds",
"rate_units": "calls/second"
},
"io.dropwizard.jetty.MutableServletContextHandler.move-requests": {
"count": 0,
"max": 0,
"mean": 0,
"min": 0,
"p50": 0,
"p75": 0,
"p95": 0,
"p98": 0,
"p99": 0,
"p999": 0,
"stddev": 0,
"m15_rate": 0,
"m1_rate": 0,
"m5_rate": 0,
"mean_rate": 0,
"duration_units": "seconds",
"rate_units": "calls/second"
},
"io.dropwizard.jetty.MutableServletContextHandler.options-requests": {
"count": 0,
"max": 0,
"mean": 0,
"min": 0,
"p50": 0,
"p75": 0,
"p95": 0,
"p98": 0,
"p99": 0,
"p999": 0,
"stddev": 0,
"m15_rate": 0,
"m1_rate": 0,
"m5_rate": 0,
"mean_rate": 0,
"duration_units": "seconds",
"rate_units": "calls/second"
},
"io.dropwizard.jetty.MutableServletContextHandler.other-requests": {
"count": 0,
"max": 0,
"mean": 0,
"min": 0,
"p50": 0,
"p75": 0,
"p95": 0,
"p98": 0,
"p99": 0,
"p999": 0,
"stddev": 0,
"m15_rate": 0,
"m1_rate": 0,
"m5_rate": 0,
"mean_rate": 0,
"duration_units": "seconds",
"rate_units": "calls/second"
},
"io.dropwizard.jetty.MutableServletContextHandler.post-requests": {
"count": 16,
"max": 2.2560000000000002,
"mean": 0.5925625,
"min": 0.372,
"p50": 0.47200000000000003,
"p75": 0.5355000000000001,
"p95": 2.2560000000000002,
"p98": 2.2560000000000002,
"p99": 2.2560000000000002,
"p999": 2.2560000000000002,
"stddev": 0.4497823130878611,
"m15_rate": 6.29282616000388e-10,
"m1_rate": 0.004336419450693371,
"m5_rate": 0.0009050744109606403,
"mean_rate": 0.005660270596836139,
"duration_units": "seconds",
"rate_units": "calls/second"
},
"io.dropwizard.jetty.MutableServletContextHandler.put-requests": {
"count": 0,
"max": 0,
"mean": 0,
"min": 0,
"p50": 0,
"p75": 0,
"p95": 0,
"p98": 0,
"p99": 0,
"p999": 0,
"stddev": 0,
"m15_rate": 0,
"m1_rate": 0,
"m5_rate": 0,
"mean_rate": 0,
"duration_units": "seconds",
"rate_units": "calls/second"
},
"io.dropwizard.jetty.MutableServletContextHandler.requests": {
"count": 38,
"max": 2.2560000000000002,
"mean": 0.5017105263157895,
"min": 0.001,
"p50": 0.46,
"p75": 0.528,
"p95": 2.25505,
"p98": 2.2560000000000002,
"p99": 2.2560000000000002,
"p999": 2.2560000000000002,
"stddev": 0.4573666639487485,
"m15_rate": 1.2585652320522491e-9,
"m1_rate": 0.009046050572111585,
"m5_rate": 0.0018138926497602615,
"mean_rate": 0.013443138586906005,
"duration_units": "seconds",
"rate_units": "calls/second"
},
"io.dropwizard.jetty.MutableServletContextHandler.trace-requests": {
"count": 0,
"max": 0,
"mean": 0,
"min": 0,
"p50": 0,
"p75": 0,
"p95": 0,
"p98": 0,
"p99": 0,
"p999": 0,
"stddev": 0,
"m15_rate": 0,
"m1_rate": 0,
"m5_rate": 0,
"mean_rate": 0,
"duration_units": "seconds",
"rate_units": "calls/second"
},
"org.eclipse.jetty.server.HttpConnectionFactory.80.connections": {
"count": 37,
"max": 116.233045153,
"mean": 18.87723851451351,
"min": 0.078290967,
"p50": 0.570973454,
"p75": 33.0824538595,
"p95": 87.55158713740005,
"p98": 116.233045153,
"p99": 116.233045153,
"p999": 116.233045153,
"stddev": 32.65398107624642,
"m15_rate": 0.006718640480106826,
"m1_rate": 0.018519557829824465,
"m5_rate": 0.024412722112445752,
"mean_rate": 0.013086852776973062,
"duration_units": "seconds",
"rate_units": "calls/second"
}
}

}

========================

最佳答案

此问题有 2 个潜在原因:

1) 没有正确结束你的回复

更多信息来自 this blog post .

您可以使用 netstat -a | grep CLOSE_WAIT | wc -l获取线程数。

您可以通过运行获取线程转储:

jps然后查看您的应用程序的进程 ID,并将其传递给此命令:要使用 jstack 获取线程转储,请运行以下命令:

jstack <pid>

每隔一段时间运行相同的命令并追加到同一个文件。您需要多个转储,并及时间隔开以检测长时间运行的线程

jstack <pid> >> threaddumps.log

然后使用 thread dump analyzer比较你的第一个转储和第二个转储,通过选择多个转储来查看哪些线程运行时间长,右键单击并选择“查找长时间运行的线程”

您可能需要确保关闭一个 ClientResponse,就像这里所做的那样:

public boolean isSessionActive(HttpServletRequest httpRequest) {
ClientResponse response = null;
try{
response = jerseyClient
.resource(url)
.type(APPLICATION_JSON_TYPE)
.header("Cookie", httpRequest.getHeader("Cookie"))
.get(ClientResponse.class);
return response.getStatus() == SC_OK;
}
finally {
if (response != null){
// #############################################
// This next line is the fix you're looking for!
// #############################################
response.close();
}
}
}

2) 没有分配足够的并发线程

MultiThreadedHttpConnectionManager 的默认配置只允许每个主机有 2 个并发请求!因此,如果您不断地使用不同的请求数据访问同一台服务器,您可能一次被限制为 2 个 Activity 请求。如果碰巧这 2 个请求需要很长时间才能完成,那么您就没有可用的连接,并且会等待。

这怎么会发生?对于我们来说,我们使用 ApacheHttpClient 和 DropWizard 0.6.2,它在幕后创建了一个具有默认配置的 MultiThreadedHttpConnectionManager - 并且 default configuration一次只允许 2 个并发 http 连接)

我们以为我们正在传递配置来提高这个#,但实际上它没有被使用,我们的服务器一次只处理 2 个请求;-)

因此请检查以下内容以确保它们是您期望的值!

  MultiThreadedHttpConnectionManager connectionManager = ...;
connectionManager.getParams().getDefaultMaxConnectionsPerHost();
connectionManager.getParams().getMaxTotalConnections();

关于java - Dropwizard 线程等待计数增加,服务器停止响应所有资源请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27874894/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com