armzilla / amazon-echo-ha-bridge

emulates philips hue api to other home automation gateways
Apache License 2.0
732 stars 168 forks source link

Excessive memory usage #26

Open tomchapin opened 9 years ago

tomchapin commented 9 years ago

When I use Java to run the JAR from Windows 10 (with JDK 1.8), everything works perfectly, but the process is using up 1.14 gigabytes of RAM.

Is this intended behavior? Is there anything I can do to run the server so it doesn't use up so much RAM?

P.S. Thanks for this awesome tool!

aptalca commented 9 years ago

I noticed that, too. I am running it as a docker container with an ubuntu base and yup, it is using between 850MB-1.1GB at all times.

Since so many people are running this on a raspberry pi, I am curious as to whether this is their experience as well (rpi 2 only has 1GB of ram)

Also looking at the logs, I see that this app remains in discovery mode forever and it gets absolutely hammered with discovery requests from devices on my network (new request every ten seconds). I wonder if that has anything to do with the memory usage

jlekhter commented 9 years ago

I'm running this on a rpi 2 -- its been up for 22 days now and top shows 139m resident memory and 362m virtual memory.

I agree -- awesome software. Thank you!

armzilla commented 9 years ago

I think that is default java behavior to adjust usage based on your total memory size. You try and specify the -Xmx512M flag to set max usage. e.g. java -Xmx512M -jar .

aptalca commented 9 years ago

Thanks, Arm. That was it. I set it to 512M and now the app itself consumes under 500MB.

Is 512MB a reasonable max value or could we go lower? I am running this on a server that does a whole lot of tasks so I would rather not have java tie up precious resources when not needed.

Thanks

armzilla commented 9 years ago

I think the majority of the memory usage is the embedded elasticsearch. I would imagine you can drop it down to 256M and see if it causes any issues.

maddox commented 9 years ago

Why in the world does this project use elasticsearch at all anyways? It takes requests on unique specific URLs and then makes requests to the URLs mapped to those. It's all very weird to me.

armzilla commented 9 years ago

Its embeddable, didn't want folks to have to set up mongo and such. Didn't want to set up relational db because I want to be able to upgrade the data stored from one version to next (without having to think about migration strategy). Guess I could have stored things as clobs in rdb.

maddox commented 9 years ago

You could honestly just serialize it to JSON on disk ¯(°_o)/¯ It's not a ton of data. Keep it in memory, and dump it to a JSON file. I assume the only information being stored are the "devices" we create?

It'd get rid of a ton of dependencies as well as making the app way lighter. And seeing that people run this on Raspberry Pis, that'd be a huge benefit.

armzilla commented 9 years ago

Guess I could have gone with the embedded derby route as well. Hindsight 20/20 lol

armzilla commented 9 years ago

Yep, I run mine on a pi2 with no problems. I guess the whole es route came from my other HA project to also store sensor events.