Discord JDA 350+线程触发OutOfMemoryError的栈大小调整咨询
应用创建原生线程触发内存溢出问题记录
基本场景与已尝试操作
- 运行环境:配置为32GB内存、16核心、600GB SSD存储的VPS
- 异常触发条件:应用线程数首次突破350时抛出内存溢出错误,现有调整手段未解决问题
- 已执行的调整操作:
- 传入
-XssJVM参数尝试调整线程栈大小 - 参考公开JVM调优文档配置其他GC、内存相关调优参数
- 修改系统层面的默认线程栈大小、用户进程资源限制
- 传入
- 异常观测结果:无论调整任何启动参数,应用侧统计的线程栈大小始终固定显示为1024k
关联错误日志
线程创建失败核心堆栈
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(RealInterceptor.java:121) at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptor.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(RealInterceptor.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(Http2Connection.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)
核心待解决问题
- 现有调参流程下线程栈大小始终固定为1024k,是否存在可生效的调整方式
- 配置
-Xss2g启动参数时触发系统限制报错,如何调整对应的系统阈值以适配参数要求
内容的提问来源于stack exchange,提问作者King Reload
相关产品推荐
相关产品推荐

