Java

Apache karaf 記憶體不足錯誤

  • May 14, 2019

我正在使用本地線上託管服務的虛擬伺服器,我想在其中執行 apache karaf 實例。

在伺服器啟動期間,出現記憶體不足異常:

Exception in thread "Karaf local console user karaf" java.lang.OutOfMemoryError: unable to create native thread: possibly out of memory or process/resource limits reached

(請參閱下面的更多細節)

我不知道這是怎麼發生的,因為伺服器有 2GB 的可用記憶體。

使用另一個 ssh-shell 登錄時,有時會收到錯誤消息

/usr/bin/lesspipe: 1: /usr/bin/lesspipe: Cannot fork

問題:為什麼 karaf 不能完全啟動?您將採取哪些步驟來更詳細地分析問題?

非常感謝您的支持!


這裡有更多資訊:

karaf setenv 文件

export JAVA_MIN_MEM=256M # Minimum memory for the JVM
export JAVA_MAX_MEM=1024M # Maximum memory for the JVM
export JAVA_PERM_MEM=256M # Minimum perm memory for the JVM
export JAVA_MAX_PERM_MEM=1024M # Maximum perm memory for the JVM

的輸出free -m

            total        used        free      shared  buff/cache       available

Mem:         2048         223        1363           0         461        1824

Swap:          0           0           0

即使在 karaf 伺服器停止工作之後,似乎還剩下一些東西:

top - 16:04:28 up 2 days,  1:09,  2 users,  load average: 0.00, 0.01, 0.05
Tasks:  26 total,   1 running,  25 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.0 us,  0.4 sy,  0.0 ni, 99.6 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  2097152 total,  1445120 free,   216712 used,   435320 buff/cache
KiB Swap:        0 total,        0 free,        0 used.  1880340 avail Mem 

 PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND            
8439 root      20   0   97176   4180   3240 S  0.3  0.2   0:00.34 sshd               
8793 karaf     20   0 3187104 192736  15088 S  0.3  9.2   0:08.82 java     

cat /proc/sys/kernel/threads-max

3092863

ulimit -a

core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 1546431
max locked memory       (kbytes, -l) 16384
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 62987
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

貓 /proc/user_beancounters

Version: 2.5
      uid  resource                     held              maxheld              barrier                limit              failcnt
  2810691: kmemsize                 73211904             74088448  9223372036854775807  9223372036854775807                    0
           lockedpages                     0                    0  9223372036854775807  9223372036854775807                    0
           privvmpages                120109               126756  9223372036854775807  9223372036854775807                    0
           shmpages                      277                 2064  9223372036854775807  9223372036854775807                    0
           dummy                           0                    0  9223372036854775807  9223372036854775807                    0
           numproc                        78                   78                  400                  400                    0
           physpages                  214852               219387               524288               524288                    0
           vmguarpages                     0                    0  9223372036854775807  9223372036854775807                    0
           oomguarpages               216059               220594                    0                    0                    0
           numtcpsock                      0                    0  9223372036854775807  9223372036854775807                    0
           numflock                        7                   15  9223372036854775807  9223372036854775807                    0
           numpty                          4                    5  9223372036854775807  9223372036854775807                    0
           numsiginfo                      0                  123  9223372036854775807  9223372036854775807                    0
           tcpsndbuf                       0                    0  9223372036854775807  9223372036854775807                    0
           tcprcvbuf                       0                    0  9223372036854775807  9223372036854775807                    0
           othersockbuf                    0                    0  9223372036854775807  9223372036854775807                    0
           dgramrcvbuf                     0                    0  9223372036854775807  9223372036854775807                    0
           numothersock                    0                    0  9223372036854775807  9223372036854775807                    0
           dcachesize               55529472             55709696  9223372036854775807  9223372036854775807                    0
           numfile                       966                 1395  9223372036854775807  9223372036854775807                    0
           dummy                           0                    0  9223372036854775807  9223372036854775807                    0
           dummy                           0                    0  9223372036854775807  9223372036854775807                    0
           dummy                           0                    0  9223372036854775807  9223372036854775807                    0
           numiptent                      36                   36                 2000                 2000                    0

df -h

/dev/ploop11992p1   51G  2.1G   46G   5% /
none               1.0G     0  1.0G   0% /sys/fs/cgroup
none               1.0G     0  1.0G   0% /dev
tmpfs              1.0G     0  1.0G   0% /dev/shm
tmpfs              1.0G  1.1M 1023M   1% /run
tmpfs              5.0M     0  5.0M   0% /run/lock
none               1.0G     0  1.0G   0% /run/shm

memory.log 的內容

Number of objects waiting finalization: 0

Heap:
   Init:      268435456
   User:      63690360
   Committed: 259588096
   Max:       1037959168
Non-Heap: 
   Init:      7667712
   User:      60647112
   Committed: 68009984
   Max:       -1

長錯誤資訊

 Apache Karaf (4.2.5)

Hit '<tab>' for a list of available commands
and '[cmd] --help' for help on a specific command.
Hit '<ctrl-d>' or type 'system:shutdown' or 'logout' to shutdown Karaf.

[7,773s][warning][os,thread] Failed to start thread - pthread_create failed (EAGAIN) for attributes: stacksize: 1024k, guardsize: 0k, detached.
[7,794s][warning][os,thread] Failed to start thread - pthread_create failed (EAGAIN) for attributes: stacksize: 1024k, guardsize: 0k, detached.
Exception in thread "Karaf local console user karaf" 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:803)
   at java.base/java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:937)
   at java.base/java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1354)
   at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:118)
   at org.apache.felix.gogo.runtime.CommandSessionImpl$JobImpl.start(CommandSessionImpl.java:799)
   at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:300)
   at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:169)
   at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:149)
   at org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:179)
   at org.apache.karaf.shell.impl.console.ConsoleSessionImpl.doExecuteScript(ConsoleSessionImpl.java:578)
   at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
   at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1654)
   at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
   at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
   at java.base/java.util.stream.StreamSpliterators$WrappingSpliterator.forEachRemaining(StreamSpliterators.java:312)
   at java.base/java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:734)
   at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:658)
   at org.apache.karaf.shell.impl.console.ConsoleSessionImpl.executeScript(ConsoleSessionImpl.java:570)
   at org.apache.karaf.shell.impl.console.ConsoleSessionImpl.run(ConsoleSessionImpl.java:401)
   at java.base/java.lang.Thread.run(Thread.java:834)

[76,701s][warning][os,thread] Failed to start thread - pthread_create failed (EAGAIN) for attributes: stacksize: 1024k, guardsize: 0k, detached.
OpenJDK 64-Bit Server VM warning: Exception java.lang.OutOfMemoryError occurred dispatching signal SIGWINCH to handler- the VM may need to be forcibly terminated
[78,236s][warning][os,thread] Failed to start thread - pthread_create failed (EAGAIN) for attributes: stacksize: 1024k, guardsize: 0k, detached.
OpenJDK 64-Bit Server VM warning: Exception java.lang.OutOfMemoryError occurred dispatching signal SIGWINCH to handler- the VM may need to be forcibly terminated

令人驚訝的答案:它的 karaf,在降級到 Java 9 後一切正常。

引用自:https://serverfault.com/questions/966832