Reply
Emerging Member
Posts: 59
Registered: ‎07-28-2009
Kudos: 12

Unifi controller memory - java heap size

Is there a way to control the memory footprint of the unifi controller? Being a java app, I'd like to be able to control the heap allocation with xms & xmx. But it looks like that's hard-coded to Xmx 1024M. This is problematic for hosts that are memory constrained (plug computers, small atom boards, shared hosting, etc.). Right now, I resort to bouncing unifi a few times a day using a crontab script... just to keep within my memory footprint limit (I'm on shared hosting).

As a side note: one nasty consequence of bouncing unifi like this is that it appears that users using a plan with a "limit_quota" get there usage reset to zero. i.e. it looks like the unifi server only tracks plan usage in volatile memory and does not periodically commit plan usage to disk. ouch.
New Member
Posts: 36
Registered: ‎01-20-2014
Kudos: 7

Re: Unifi controller memory - java heap size

Hi

It's not quiet "hard-coded".

You can update the Xmx parameter in the init script /usr/lib/unifi/bin/unifi.init

JSVC_OPTS="${JSVC_OPTS}\
 -home ${JAVA_HOME} \
 -cp /usr/share/java/commons-daemon.jar:${BASEDIR}/lib/ace.jar \
 -pidfile ${PIDFILE} \
 -procname ${NAME} \
 -outfile SYSLOG \
 -errfile SYSLOG \
 -Djava.awt.headless=true -Xmx1024M" # <== UPDATE HERE

 

My current controller runs with Xmx256M w/o any issues. 
But I've only a bunch of APs over here, so I've no experience w/ bigger installations!

Cheers
Domi

New Member
Posts: 36
Registered: ‎01-20-2014
Kudos: 7

Re: Unifi controller memory - java heap size

btw running on beta:

Package: unifi-beta
Status: install ok installed
Priority: optional
Section: java
Installed-Size: 35940	.
Maintainer: UniFi developers <unifi-dev@ubnt.com>
Architecture: all
Version: 3.1.9-2226
Replaces: unifi-controller
Provides: unifi-controller
Depends: mongodb-10gen (>= 2.0.0) | mongodb-server (>= 2.0.0), openjdk-6-jre-headless, default-jre-headless, jsvc
Conflicts: unifi-controller
Description: Ubiquiti UniFi server
 Ubiquiti UniFi server is a centralized management system for Ubiquiti UniFi
 AP. After the UniFi server is installed on a Mac or PC, the UniFi controller
 can be accessed through any device using a web browser. The UniFi controller
 allows the operator to instantly provision thousands of UniFi APs, map out
 networks, quickly manage system traffic, and further provision individual 
 Unifi AP devices.
Homepage: http://www.ubnt.com/unifi

 

New Member
Posts: 4
Registered: ‎03-05-2014
Kudos: 19

Re: Unifi controller memory - java heap size

Hi!

I tried lowering the maximum size of the java process. But when I change the value of the -Xmx value in /etc/init.d/unifi it is ignored. (I'm using a debian linux here)

Everytime the java process is started with the following parameters:

.../bin/java -Xmx1024M -jar /usr/lib/unifi/lib/ace.jar start

Any idea why?

BR!

 

Regular Member
Posts: 452
Registered: ‎12-02-2012
Kudos: 123
Solutions: 32

Re: Unifi controller memory - java heap size

New Member
Posts: 4
Registered: ‎03-05-2014
Kudos: 19

Re: Unifi controller memory - java heap size

Thx nicktc - but I think this is a different problem here.

Today I updated to the latest beta. But that didn't changed anything.

In /etc/init.d/unifi it is possible to change the -Xmx paramater to a lower value like -Xmx512M

...
JSVC_OPTS="${JSVC_OPTS}\
 -home ${JAVA_HOME} \
 -cp /usr/share/java/commons-daemon.jar:${BASEDIR}/lib/ace.jar \
 -pidfile ${PIDFILE} \
 -procname ${NAME} \
 -outfile SYSLOG \
 -errfile SYSLOG \
 -Djava.awt.headless=true -Xmx512M"
...

 But after starting it the java process is still launched with -Xmx1024M:

# ps x 
  PID TTY      STAT   TIME COMMAND
[...]        
 1319 ?        Ss     0:00 unifi -home /usr/lib/jvm/java-6-openjdk-i386 -cp /usr/share/java/commons-daemon.jar:/usr/lib/
 1321 ?        S      0:00 unifi -home /usr/lib/jvm/java-6-openjdk-i386 -cp /usr/share/java/commons-daemon.jar:/usr/lib/
 1322 ?        Sl     0:00 unifi -home /usr/lib/jvm/java-6-openjdk-i386 -cp /usr/share/java/commons-daemon.jar:/usr/lib/
 1351 ?        Sl     0:14 /usr/lib/jvm/java-6-openjdk-i386/jre/bin/java -Xmx1024M -jar /usr/lib/unifi/lib/ace.jar start
[...]

 And even though the java process is not using all the memory, the maximum size is still 1024M + the memory the java process itself needs:

# cat /proc/1351/status  | grep -E "VmSize|VmRSS"
VmSize:	 1262220 kB
VmRSS:	   71940 kB

 Any idea how to reduce the maximum memory?

Does anyone knows why the unifi controler is running as root user? As far as I can see no privileged ports are used. So a limited user would be enough and much safer?!

 

 

New Member
Posts: 5
Registered: ‎01-20-2014
Kudos: 9

Re: Unifi controller memory - java heap size

Up! Same problem

 

:~$ uname -a
Linux unifi 3.8.0-37-generic #53~precise1-Ubuntu SMP Wed Feb 19 21:37:54 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

Unifi 2.4.6

New Member
Posts: 5
Registered: ‎01-20-2014
Kudos: 9

Re: Unifi controller memory - java heap size

Now symptoms:

top - 09:23:40 up 16:33, 1 user, load average: 1.45, 1.14, 1.01
Tasks: 81 total, 3 running, 78 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.0%us, 2.0%sy, 0.0%ni, 25.0%id, 73.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 1018720k total, 951112k used, 67608k free, 352k buffers
Swap: 520188k total, 443204k used, 76984k free, 4196k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1821 root 20 0 1947m 776m 644 S 1.0 78.0 4:09.58 java
root@unifi:/# free -m
total used free shared buffers cached
Mem: 994 931 63 0 0 7
-/+ buffers/cache: 922 71
Swap: 507 484 23

 

New Member
Posts: 33
Registered: ‎02-04-2014
Kudos: 3
Solutions: 1

Re: Unifi controller memory - java heap size

I was running unifi 2.4.5 on Ubuntu 10.04 on a system with 512MB ram and it was working fine for many months.

Now I have upgraded it to Ubuntu 12.04 and unifi 2.4.6 and after running for several hours the java RAM usage slowly creeps up to use all of the system ram causing the whole system to crawl to a halt.

I tried lowering the Xmx value in the init script but it doesn't change anything. I am currently using the standard openjdk from the repo.

Any ideas?

New Member
Posts: 11
Registered: ‎03-19-2014
Kudos: 3

Re: Unifi controller memory - java heap size

For me (and a few others in this thread:

 

http://community.ubnt.com/t5/UniFi/Ubuntu-Linux-Unifi-controller-dying-can-t-grok-why/m-p/764214#M58...

 

.it's the Java version.

 

$ sudo apt-get install python-software-properties
$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install oracle-java8-installer

$ sudo vi /etc/init.d/unifi

#JAVA_HOME=/usr/lib/jvm/java-6-openjdk
JAVA_HOME=/usr/lib/jvm/java-8-oracle

New Member
Posts: 4
Registered: ‎03-05-2014
Kudos: 19

Re: Unifi controller memory - java heap size

The sun/oracle java version maybe fixes the memory leak problem.

But the -mx parameter is ignored with both java versions.

New Member
Posts: 10
Registered: ‎11-04-2013

Re: Unifi controller memory - java heap size

I havent'd had memory issues still a recent update even with openjdk6.


It seems there is a regression which causes memory leaks see https://bugs.launchpad.net/ubuntu/+source/openjdk-6/+bug/1295987

 

Those updates are now available on Ubuntu 12.04.

New Member
Posts: 5
Registered: ‎11-17-2011

Re: Unifi controller memory - java heap size

Any update ? Same issue at  ubuntu 12.04.5 whith openjdk-6-jre-headless  6b33-1.13.5-1ubuntu0.12.04

New Member
Posts: 2
Registered: ‎12-01-2017
Kudos: 1

Re: Unifi controller memory - java heap size

I also have the same problem, my solution to it is hacky.

 

I replaced the java binary with a script calling the java binary, and inside that script I deleted all the -Xmx and -Xms flags. Then I appended my own -Xmx128M flag. Not sure if 128M is enough but at least I can now modify it. The great disadvantage however is that it is system-wide now, so for all java commands that you run the -Xmx and -Xms flags will not work as originally intented. A solution could be to create another java install which you modify for unifi.

 

Here is the script which I used to remove all -Xmx and -Xms flags:

#!/bin/bash
args=$@
filtered=$(echo $args | sed 's/\(-Xm[sx]\([0-9]*\)[kmgKMG]\)//g')
/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/jre/bin/java-bin -Xmx128M $filtered

It works but I don't like it. It would be better if ubiquiti would solve the issue.

Emerging Member
Posts: 51
Registered: ‎10-06-2017
Kudos: 14
Solutions: 4

Re: Unifi controller memory - java heap size

@stefan-cloudt, I believe you may have missed this:

 

[NOTICE] UniFi Controller Memory Usage (5.6.20+)

 

https://community.ubnt.com/t5/UniFi-Wireless/NOTICE-UniFi-Controller-Memory-Usage-5-6-20/m-p/2137209...

 

New Member
Posts: 2
Registered: ‎12-01-2017
Kudos: 1

Re: Unifi controller memory - java heap size

I see,

Thank you very much.

Reply