【问题标题】:java.lang.OutOfMemoryError with Discord JDA 350+ threads带有 Discord JDA 350+ 线程的 java.lang.OutOfMemoryError
【发布时间】:2021-06-25 21:36:12
【问题描述】:

所以我会尽力解释我的问题。目前我正在做一个相当不错的规模计划。但是,我从未使用过这么多线程,如 350+ 所说。它目前给我一个内存不足的错误,但是我已经尝试了各种选项:

  • 添加 -Xss 参数
  • 添加我可以在this website 上找到的其他参数
  • 我还尝试编辑堆栈大小和用户限制

我因内存泄漏问题而得到的错误如下。

java.lang.OutOfMemoryError: unable to create native thread: possibly out of memory or process/resource limits reached
        at java.base/java.lang.Thread.start0(Native Method)
        at java.base/java.lang.Thread.start(Thread.java:804)
        at okhttp3.internal.http2.Http2Connection.start(Http2Connection.java:515)
        at okhttp3.internal.http2.Http2Connection.start(Http2Connection.java:499)
        at okhttp3.internal.connection.RealConnection.startHttp2(RealConnection.java:299)
        at okhttp3.internal.connection.RealConnection.establishProtocol(RealConnection.java:288)
        at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:169)
        at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:257)
        at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:135)
        at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:114)
        at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
        at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:94)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
        at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
        at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:125)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
        at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:264)
        at okhttp3.RealCall.execute(RealCall.java:93)
        at net.dv8tion.jda.internal.requests.Requester.execute(Requester.java:200)
        at net.dv8tion.jda.internal.requests.Requester.execute(Requester.java:140)
        at net.dv8tion.jda.internal.requests.Requester.execute(Requester.java:123)
        at net.dv8tion.jda.internal.requests.ratelimit.BotRateLimiter$Bucket.run(BotRateLimiter.java:468)
        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:835)
[111,061s][warning][os,thread] Failed to start thread - pthread_create failed (EAGAIN) for attributes: stacksize: 1024k, guardsize: 0k, detached.
Exception in thread "Thread-365" java.lang.OutOfMemoryError: unable to create native thread: possibly out of memory or process/resource limits reached
        at java.base/java.lang.Thread.start0(Native Method)
        at java.base/java.lang.Thread.start(Thread.java:804)
        at java.base/java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:937)
        at java.base/java.util.concurrent.ThreadPoolExecutor.ensurePrestart(ThreadPoolExecutor.java:1583)
        at java.base/java.util.concurrent.ScheduledThreadPoolExecutor.delayedExecute(ScheduledThreadPoolExecutor.java:346)
        at java.base/java.util.concurrent.ScheduledThreadPoolExecutor.schedule(ScheduledThreadPoolExecutor.java:562)
        at java.base/java.util.concurrent.ScheduledThreadPoolExecutor.execute(ScheduledThreadPoolExecutor.java:705)
        at okhttp3.internal.http2.Http2Connection$ReaderRunnable.applyAndAckSettings(Http2Connection.java:738)
        at okhttp3.internal.http2.Http2Connection$ReaderRunnable.settings(Http2Connection.java:710)
        at okhttp3.internal.http2.Http2Reader.readSettings(Http2Reader.java:289)
        at okhttp3.internal.http2.Http2Reader.nextFrame(Http2Reader.java:141)
        at okhttp3.internal.http2.Http2Reader.readConnectionPreface(Http2Reader.java:80)
        at okhttp3.internal.http2.Http2Connection$ReaderRunnable.execute(Http2Connection.java:607)
        at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
        at java.base/java.lang.Thread.run(Thread.java:835)

我发现无论我做什么,线程堆栈大小总是显示为 1024。

我目前从具有以下规格的 VPS 运行此 .jar 文件:

  • 无限流量
  • 32GB 内存
  • 600GB 固态硬盘
  • 16 核

我的问题是,有没有办法编辑这个线程堆栈大小?

另一个单独的问题:每当我使用 -Xss2g 时,它都会显示它超出了限制,但是有没有办法编辑这个限制?

【问题讨论】:

    标签: java multithreading discord out-of-memory discord-jda


    【解决方案1】:

    您可以尝试配置 JDA 并更改默认值以减少内存占用。确保您还使用最新版本的 JDA(当前为 4.2.0_252)。

    阅读常见问题解答:How can I reduce the memory footprint of my bot?

    【讨论】:

    • 我已经追踪了我的机器人使用的内存,主要是 JDA,只占用了 140MB,这在堆空间中并没有那么多内存。我设法找出了我自己问题的答案,但这确实是一个有效的声明,您需要使用 mavencentral 升级到 4.2.0_252,所以不要使用 jcenter。感谢您的帮助明恩
    【解决方案2】:

    其实我已经弄明白了。

    我托管的提供商将我可以同时运行的线程数量限制为 1300 个线程。因为他们的数量是固定的,所以我的线程一直遇到问题,这些错误也显示在问题中。

    因为他们锁定了这个金额,所以我的选择有限,所以我决定改用提供商。

    【讨论】:

      猜你喜欢
      • 2022-01-05
      • 2021-05-05
      • 2020-08-09
      • 2021-04-24
      • 2018-10-22
      • 2023-01-05
      • 2019-10-25
      • 2017-10-28
      • 2017-12-22
      相关资源
      最近更新 更多