mnederlof / com.ubnt.unifi

Ubiquiti Unifi Controller integration for Homey
11 stars 10 forks source link

Memory issue? #38

Closed jjtbsomhorst closed 4 years ago

jjtbsomhorst commented 5 years ago

For some reason this app uses lots of memory ( 20mb+ ) with only 2 devices paired.

jjtbsomhorst commented 5 years ago

As your can see here: the app grows overnight in usage.

https://ibb.co/vVPWDGm https://ibb.co/g7JvCcK

mnederlof commented 5 years ago

Don't know where the issue lies. Maybe it should use different libraries, but no real clue where the issue lies. Also no experience in memory profiling a homey app / nodejs module.

jjtbsomhorst commented 5 years ago

I also have no experience in profiling but with https://developer.athom.com/tools/app-profiling you can get a nice idea on how the memory usage develops over time. That's what i did when working on domoticz, darksky and other apps.

Run the app, go to that page and select the app. Start working with it and let it run for a couple of minutes. You want to see a 'sharkfin' pattern. So memory goes up and then after a while it drops because the garbage collector kicks in. This way I could determin some leaks in my own code. For other libraries it's a bit harder because you can't see them in this overview ofcourse but atleast you can pinpoint on what event, in your app, the memory is used.

jjtbsomhorst commented 5 years ago

Any update on this? because well lets say this:

image

isn't normal for an app that actually only does some polling.

mnederlof commented 5 years ago

No update so far as i have other priorities to tend to atm. I'd guess it has to do with some modules i include to poll the API, but that would require me to do intensive digging into them or replace them for something else. If someone is willing to do the work in the meantime, i'd be happy to review and/or update the app in homey.

jjtbsomhorst commented 5 years ago

If you are interested. I'm currently working on my own implementation of the Ubiquity api. Can you tell me which events you are interested in and which capabilities of the controller api/software? This way I can add them and maybe we can replace your backend with that implementation? I'm trying to make it as small as possible :)

mnederlof commented 5 years ago

Great idea!

This are the interactions gathered from code: Events:

Interval based url fetching: Fetching all known clients (for pairing): /stat/alluser -> https://github.com/mnederlof/com.ubnt.unifi/blob/sdk-v2/drivers/wifi-client/driver.js#L571

Updating accesspoints regularly: /stat/device -> https://github.com/mnederlof/com.ubnt.unifi/blob/sdk-v2/drivers/wifi-client/driver.js#L495

Updating clients regularly: /stat/sta -> https://github.com/mnederlof/com.ubnt.unifi/blob/sdk-v2/drivers/wifi-client/driver.js#L451

Something to do with usergroups (see https://github.com/mnederlof/com.ubnt.unifi/pull/16) /list/usergroup -> https://github.com/mnederlof/com.ubnt.unifi/blob/sdk-v2/drivers/wifi-client/driver.js#L518

mnederlof commented 4 years ago

Closing for inactivity.