gpt4 book ai didi

java - 垃圾收集器在没有用户代码运行的情况下在 Tomcat Web 应用程序中频繁运行

转载 作者:行者123 更新时间:2023-11-28 22:23:52 31 4
gpt4 key购买 nike

我已经实现了一个 Web 应用程序,其中包括 Web 服务和一些后台进程(线程),其中一个由 Spring TaskScheduler 启动(仅启动一次但不断运行..检查其他从属进程是否开始主要处理事情通过数据库)。从功能上讲,一切都运行良好,但我正在调整过程中,我看到相关 JRE 上的 CPU 消耗 Not Acceptable 且周期性。 Tomcat 版本 8.5.29 JVM/JRE (jdk_1.8.0_171)。

怀疑我的代码效率低下并导致 GC 不必要地运行(或者只是在任何情况下正确调整 GC),我已经实现了另一个线程的建议(他们相当积极地让我退出并处于糟糕的状态) 跟踪 GC Activity ,并仔细查看了相关文档。

完成后,我收到了许多与 GC 相关的消息,这让我进入了下一步。当我调试用户代码时,我无法理解(或与我的用户代码 Activity 相关联)大量的 GC 调用。因此,在 Debug模式下,我在所有正在执行的用户代码中放置了一些断点,有效地瘫痪了所有与用户代码相关的执行,并且循环的 GC 消息继续按照用户代码运行时的节奏进行。结果是(独立于用户代码是否正在运行)每隔 10-11 秒调用一次 GC 并运行大约。 11-12 秒。

请记住,用户代码完全被阻止..这是一个示例输出..

2019-10-28T13:12:07.358+0100: 6206.987: [GC (Allocation Failure) [PSYoungGen: 41216K->256K(41472K)] 201649K->160689K(264704K), 0.0019574 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
2019-10-28T13:12:17.675+0100: 6217.304: [GC (Allocation Failure) [PSYoungGen: 41216K->320K(41472K)] 201649K->160761K(264704K), 0.0019036 secs] [Times: user=0.06 sys=0.00, real=0.00 secs]
2019-10-28T13:12:17.899+0100: 6217.527: [GC (Allocation Failure) [PSYoungGen: 41280K->256K(41472K)] 201721K->160809K(264704K), 0.0019992 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:18.128+0100: 6217.756: [GC (Allocation Failure) [PSYoungGen: 41216K->224K(41472K)] 201769K->160785K(264704K), 0.0022651 secs] [Times: user=0.02 sys=0.00, real=0.00 secs]
2019-10-28T13:12:18.352+0100: 6217.981: [GC (Allocation Failure) [PSYoungGen: 41184K->288K(41472K)] 201745K->160873K(264704K), 0.0020136 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:18.575+0100: 6218.203: [GC (Allocation Failure) [PSYoungGen: 41248K->256K(41472K)] 201833K->160865K(264704K), 0.0019503 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:18.793+0100: 6218.422: [GC (Allocation Failure) [PSYoungGen: 41216K->256K(41472K)] 201825K->160889K(264704K), 0.0019472 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:19.012+0100: 6218.641: [GC (Allocation Failure) [PSYoungGen: 41216K->256K(41472K)] 201849K->160913K(264704K), 0.0019231 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:19.241+0100: 6218.870: [GC (Allocation Failure) [PSYoungGen: 41216K->224K(41472K)] 201873K->160897K(264704K), 0.0022029 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:19.459+0100: 6219.088: [GC (Allocation Failure) [PSYoungGen: 41184K->224K(41472K)] 201857K->160905K(264704K), 0.0024031 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:19.685+0100: 6219.313: [GC (Allocation Failure) [PSYoungGen: 41184K->256K(41472K)] 201865K->160945K(264704K), 0.0018694 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:19.902+0100: 6219.531: [GC (Allocation Failure) [PSYoungGen: 41216K->288K(41472K)] 201905K->160985K(264704K), 0.0019840 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:20.123+0100: 6219.752: [GC (Allocation Failure) [PSYoungGen: 41248K->224K(41472K)] 201945K->160929K(264704K), 0.0021776 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:20.338+0100: 6219.967: [GC (Allocation Failure) [PSYoungGen: 41184K->224K(41472K)] 201889K->160929K(264704K), 0.0018897 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:20.555+0100: 6220.183: [GC (Allocation Failure) [PSYoungGen: 41184K->256K(41472K)] 201889K->160977K(264704K), 0.0019590 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:20.771+0100: 6220.399: [GC (Allocation Failure) [PSYoungGen: 41216K->224K(41472K)] 201937K->160953K(264704K), 0.0022302 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:20.991+0100: 6220.619: [GC (Allocation Failure) [PSYoungGen: 41184K->256K(41472K)] 201913K->161001K(264704K), 0.0020969 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:21.229+0100: 6220.858: [GC (Allocation Failure) [PSYoungGen: 41216K->288K(41472K)] 201961K->161041K(264704K), 0.0018507 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:21.445+0100: 6221.074: [GC (Allocation Failure) [PSYoungGen: 41248K->224K(41472K)] 202001K->160985K(264704K), 0.0023642 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:21.659+0100: 6221.288: [GC (Allocation Failure) [PSYoungGen: 41184K->256K(41472K)] 201945K->161017K(264704K), 0.0019729 secs] [Times: user=0.02 sys=0.00, real=0.00 secs]
2019-10-28T13:12:21.875+0100: 6221.504: [GC (Allocation Failure) [PSYoungGen: 41216K->256K(41472K)] 201977K->161025K(264704K), 0.0019721 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:22.109+0100: 6221.738: [GC (Allocation Failure) [PSYoungGen: 41216K->256K(41472K)] 201985K->161033K(264704K), 0.0021257 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:22.338+0100: 6221.966: [GC (Allocation Failure) [PSYoungGen: 41216K->256K(41472K)] 201993K->161041K(264704K), 0.0018824 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:22.565+0100: 6222.194: [GC (Allocation Failure) [PSYoungGen: 41216K->224K(41472K)] 202001K->161017K(264704K), 0.0019543 secs] [Times: user=0.02 sys=0.00, real=0.00 secs]
2019-10-28T13:12:22.785+0100: 6222.414: [GC (Allocation Failure) [PSYoungGen: 41184K->256K(41472K)] 201977K->161049K(264704K), 0.0019685 secs] [Times: user=0.06 sys=0.00, real=0.00 secs]
2019-10-28T13:12:23.002+0100: 6222.630: [GC (Allocation Failure) [PSYoungGen: 41216K->256K(41472K)] 202009K->161049K(264704K), 0.0018725 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:23.240+0100: 6222.869: [GC (Allocation Failure) [PSYoungGen: 41216K->224K(41472K)] 202009K->161025K(264704K), 0.0021566 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:23.451+0100: 6223.080: [GC (Allocation Failure) [PSYoungGen: 41184K->224K(41472K)] 201985K->161025K(264704K), 0.0020730 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:23.682+0100: 6223.311: [GC (Allocation Failure) [PSYoungGen: 41184K->256K(41472K)] 201985K->161057K(264704K), 0.0019011 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:23.933+0100: 6223.561: [GC (Allocation Failure) [PSYoungGen: 41216K->224K(41472K)] 202017K->161025K(264704K), 0.0018953 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:24.185+0100: 6223.813: [GC (Allocation Failure) [PSYoungGen: 41184K->256K(41472K)] 201985K->161065K(264704K), 0.0019484 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:24.419+0100: 6224.048: [GC (Allocation Failure) [PSYoungGen: 41216K->288K(41472K)] 202025K->161097K(264704K), 0.0019002 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:24.644+0100: 6224.272: [GC (Allocation Failure) [PSYoungGen: 41248K->256K(41472K)] 202057K->161081K(264704K), 0.0018661 secs] [Times: user=0.06 sys=0.00, real=0.00 secs]
2019-10-28T13:12:24.872+0100: 6224.501: [GC (Allocation Failure) [PSYoungGen: 41216K->256K(41472K)] 202041K->161081K(264704K), 0.0019496 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:25.092+0100: 6224.721: [GC (Allocation Failure) [PSYoungGen: 41216K->224K(41472K)] 202041K->161049K(264704K), 0.0022255 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:25.319+0100: 6224.948: [GC (Allocation Failure) [PSYoungGen: 41184K->256K(41472K)] 202009K->161081K(264704K), 0.0020412 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:25.537+0100: 6225.165: [GC (Allocation Failure) [PSYoungGen: 41216K->256K(41472K)] 202041K->161081K(264704K), 0.0019278 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:25.762+0100: 6225.391: [GC (Allocation Failure) [PSYoungGen: 41216K->224K(41472K)] 202041K->161057K(264704K), 0.0020179 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:25.979+0100: 6225.608: [GC (Allocation Failure) [PSYoungGen: 41184K->256K(41472K)] 202017K->161089K(264704K), 0.0018991 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:26.252+0100: 6225.880: [GC (Allocation Failure) [PSYoungGen: 41216K->224K(41472K)] 202049K->161057K(264704K), 0.0018755 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:26.484+0100: 6226.112: [GC (Allocation Failure) [PSYoungGen: 41184K->256K(41472K)] 202017K->161089K(264704K), 0.0019254 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:26.695+0100: 6226.324: [GC (Allocation Failure) [PSYoungGen: 41216K->256K(41472K)] 202049K->161089K(264704K), 0.0019129 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:26.918+0100: 6226.547: [GC (Allocation Failure) [PSYoungGen: 41216K->288K(41472K)] 202049K->161121K(264704K), 0.0018535 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:27.156+0100: 6226.785: [GC (Allocation Failure) [PSYoungGen: 41248K->256K(41472K)] 202081K->161097K(264704K), 0.0019399 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:27.387+0100: 6227.016: [GC (Allocation Failure) [PSYoungGen: 41216K->256K(41472K)] 202057K->161097K(264704K), 0.0020594 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:27.615+0100: 6227.244: [GC (Allocation Failure) [PSYoungGen: 41216K->256K(41472K)] 202057K->161097K(264704K), 0.0021954 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:27.832+0100: 6227.461: [GC (Allocation Failure) [PSYoungGen: 41216K->256K(41472K)] 202057K->161097K(264704K), 0.0020552 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:28.047+0100: 6227.676: [GC (Allocation Failure) [PSYoungGen: 41216K->256K(41472K)] 202057K->161097K(264704K), 0.0021104 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:28.266+0100: 6227.895: [GC (Allocation Failure) [PSYoungGen: 41216K->224K(41472K)] 202057K->161073K(264704K), 0.0019352 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:28.474+0100: 6228.103: [GC (Allocation Failure) [PSYoungGen: 41184K->224K(41472K)] 202033K->161073K(264704K), 0.0020573 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2019-10-28T13:12:28.690+0100: 6228.319: [GC (Allocation Failure) [PSYoungGen: 41184K->256K(41472K)] 202033K->161105K(264704K), 0.0023471 secs] [Times: user=0.06 sys=0.00, real=0.00 secs]
2019-10-28T13:12:39.012+0100: 6238.641: [GC (Allocation Failure) [PSYoungGen: 41216K->288K(41472K)] 202065K->161137K(264704K), 0.0020514 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]

如果您查看时间戳,您可以推断出我所说的周期性的意思。我可以提供更多的输出,但它总是相同的(至少在我监视它的 1-2 小时内)。

所以我的问题是……(1) 什么会导致这些 GC 调用,(2) 为什么这么多,当然,(3) 如何控制和/或避免这种情况……它确实占用了烦人的 CPU 数量。

最佳答案

好的,我找到了第一个问题的答案。通过暂停/恢复环境中运行的各种线程,罪魁祸首是 ContainerBackgroundProcessor Daemon 线程。当我暂停此线程时,所有 GC 调用都会停止,一切似乎都运行良好(包括 Web 服务请求)。恢复线程,GC 以相同的循环频率再次开始非常努力地工作。暂停它,GC 调用停止......等等。

我想此时第二个问题无关紧要。

至于第三个问题,一个不完整的答案就是“挂起线程”。不完整,因为虽然在开发环境中很容易,但在生产环境中显然很麻烦。更不用说(尽管所有功能似乎在一些有限的测试中都可以正常工作)Tomcat 启动该线程是出于人们期望的一个很好的理由,并且暂停它的所有影响都是未知的(至少对我而言)。

我已经对此进行了一些调查,但可用的信息很少,充其量只是粗略的。 Tomcat softdocs 并没有真正帮助太多,只是简单地说“私有(private)线程类在固定延迟后调用此容器及其子容器的 backgroundProcess 方法。”

我怀疑它是因为我们通过正在使用的 TaskScheduler 启动的线程而启动的。这是为 30 秒的 FixedDelay 设置的(据我所知,只有在线程的主循环退出时才会调用......或者说作业结束)并且线程仅在异常情况下不断运行。

因此,也许有人可以指出这可能是由 Tomcat 错误(版本 8.5.29)引起的还是可能是“功能”,但无论如何,如何最好地处理这种情况。

关于java - 垃圾收集器在没有用户代码运行的情况下在 Tomcat Web 应用程序中频繁运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58606630/

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