In my CentOS 7 64bit server, there are several Java applications are running, such as Jira, Confluence, BitBuckit, Artifactory, Jenkins. And the server memory is 32 Gb, 16 core CPUs, firstly I thought t such huge memory should be enough for these java applications, which each application I have set JVM maximum 2 or 3 Gb memory.
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
That means when all applications are running with their full memory stack, the total memory should less than 20 Gb.
2. Problem
But I get often such error: Cannot allocate memory
Especially When Artifactory is running, the Bitbucket process always suicide. But even Artifactory is not running, the Bitbucket also dies after a while. The bitbucket will start two processes in the beginning, one is bitbucket and the other is elasticsearch. But system always kills bitbucket process and keep elasticsearch alive.
From /tmp directory, there is a lots of logs such as : hs_err_pidxxxx.log
The example logs for bitbucket and Artifactory:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (malloc) failed to allocate 1062024 bytes for Chunk::new
# Possible reasons:
# The system is out of physical RAM or swap space
# In 32 bit mode, the process size limit was hit
# Possible solutions:
# Reduce memory load on the system
# Increase physical memory or swap space
# Check if swap backing store is full
# Use 64 bit Java on a 64 bit OS
# Decrease Java heap size (-Xmx/-Xms)
# Decrease number of Java threads
# Decrease Java thread stack sizes (-Xss)
# Set larger code cache with -XX:ReservedCodeCacheSize=
# This output file may be truncated or incomplete.
#
# Out of Memory Error (allocation.cpp:390), pid=24614, tid=0x1c8f9b40
As you can see, the system memory is about 20 Gb free when the bitbucket or Artifactory is crashing.
3. Analyzing
3-1. Try 1
After reading this Bitbucket Server is reaching resource limits, I tried to set the JVM_MAXIMUM_MEMORY to 3gb for Bitbucket. But I can not start Bitbucket, with such error: cannot allocate 3xxxxxxk.
3-2. Try 2
I guess there is one system background process had like to kill bitbucket process unexpectedly, and I found this post:
The entire Bitbucket Server process suddenly terminates without warning. That is to say, the process ID (pid) is gone.
The browser shows a generic “cannot connect” or similar error, indicating that it is not able to reach the webpage
Nothing out of the ordinary appears in the Bitbucket Server application logs ($BITBUCKET_HOME/logs/atlassian-bitbucket.log), since the application was terminated without properly shutting down
Similarly, Tomcat logs (<Bitbucket Server installation directory>/logs/catalina.out) also do not show errors
The Diagnosis from this article said that:
Linux OOM-Killer is a feature on some Linux installations that will sacrifice processes to free up memory if the operating system experiences memory exhaustion for its own operations. Please note that this is different from Bitbucket Server running out of memory. In this case, the OS itself is in danger of running out of memory and thus starts terminating processes to avoid it.
On the host machine, look in the /var/log/ directory for the syslog or messages.
But in my host server, I can not find these files. But according to this CentOS 7: Disabling OOMKiller for a process, I found /proc/<pid>/oom_score_adj , which pid is the dead bitbucket pid. You can set the score of a process to avoid to be killed by OOM Killer. This could be one solution, You need set the value every time when you restart Bitbucket manually or automatically, for example:
1
2
........
echo-1000>/proc/$PID/oom_score_adj;done;
3-3. Try 3
I created one support ticket and sent it to my host support. I get the answer from support.
Some virtual linux server will limit the parallel running Java process amount, your server has the limit of 1300 processes. You can check the limit under this file: cat /proc/user_beancounters
I found numprocthis field, limit is 1300, and held is 1130.
The field held shows the current counter for the Private Virtual servers (resource “usage”).
The field maxheld shows the counter’s maximum for the lifetime of the Virtual server. The lifetime of the Virtual server/Node/Vserver is usually just the time between the start and stop of your VPS.
This could be the reason when I start both Artifactory and Bitbucket, the numproc will exceed the maximum process limit. In this condition, OOM killer will find its favorite process to kill.
3-4. Try 3
An idea flashed through my mind, I can try running Bitbucket with lower memory.
1
2
JVM_MINIMUM_MEMORY=1500m
JVM_MAXIMUM_MEMORY=1500m
And miracle comes, the Bitbucket is running stable. WTF?
Reason unknown. 2G is a huge size for a 20Gb memory free host??
3-5. Try 4
I will do some research to find out how many processes were created by each Java application.
To check all the running applications, enter
1
2
ps-e
another good option is:
1
ps aux
And this is part of running applications
1
2
3
4
5
6
7
8
USER PID%CPU%MEM VSZ RSS TTY STAT START TIME COMMAND
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the ...
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
Cookie
Duration
Description
cookielawinfo-checkbox-analytics
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional
11 months
The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy
11 months
The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.