WebThingsIO / wake-on-lan-adapter

Wake-on-LAN adapter for WebThings gateway.
Mozilla Public License 2.0
3 stars 5 forks source link

Doesn't work with 0.9 gateway #4

Closed gorbunovav closed 5 years ago

gorbunovav commented 5 years ago

Docker container with the gateway starts to eat RAM upon add-on installation, it stops if you disable the add-on.

Environment:

Raspberry Pi 4 Raspbian 10 Docker version 19.03.1, build 74b1e89 Image: mozillaiot/gateway:0.9.2-arm

docker-compose.yml:

version: "3"

services:
  webthings-gateway:
    container_name: webthings-gateway
    image: mozillaiot/gateway:arm
    restart: unless-stopped
    network_mode: host
    ports:
      - "8080:8080"
      - "4443:4443"
    volumes:
      - ./data:/home/node/.mozilla-iot
mrstegeman commented 5 years ago

Thank you for the bug report. This should work now in the latest 0.9.2 images.

gorbunovav commented 5 years ago

@mrstegeman thank you for a quick reply. I've pulled the new image, but I am observing the same behavior - high CPU usage and increasing memory allocation.

I don't see anything relevant in logs - only a few lines about the add-on launch:

2019-08-27 08:45:53.438 INFO   : Loading add-on: wake-on-lan-adapter
2019-08-27 08:45:53.912 INFO   : wake-on-lan: Opening database: /home/node/.mozilla-iot/config/db.sqlite3
2019-08-27 08:45:53.943 INFO   : wake-on-lan: Loading add-on for wake-on-lan-adapter from /home/node/.mozilla-iot/addons/wake-on-lan-adapter
mrstegeman commented 5 years ago

Previously, the arp command was not available, so the adapter was doing nothing.

I just set up a fresh gateway container with only this add-on installed and watched it for an hour. It consistently sits at 0% CPU and a constant memory footprint (~130KB).

Are you positive it's this issue causing the problem? Can you watch top or something and make sure?

gorbunovav commented 5 years ago

@mrstegeman I've checked - the arp command is available in the running image (so it is indeed the latest one).

watched it for an hour

for me, it happens immediately after I am enabling the add-on. It takes less than a minute for MEM usage to grow up to 1Gb.

Can you watch top or something and make sure?

top says, that it is node process consuming resources.

Are you positive it's this issue causing the problem?

Is there way to get some additional logs? Issue appears right after enabling the add-on and disappears immediately after it disable (MEM usage drops too). I don't see any errors in container logs.

mrstegeman commented 5 years ago

You should see several node processes. The one with the lowest PID would be the gateway, so I'm curious which process has the memory leak. You could also try with top -c, which should show the full command string.

gorbunovav commented 5 years ago

@mrstegeman it is node src/addon-loader.js /home/node/.mozilla-iot/addons/wake-on-lan-adapter

gorbunovav commented 5 years ago

@mrstegeman I've performed some experiments on my PC with x86 and arm images.

The plugin works in both modes. But I've noticed, that CPU load and memory usage jump on the add-on launch too, but after some time it cools down.

Maybe Raspberry Pi is too weak and the plugin launch takes much more time. Plus right now it hits throttling. I will try tomorrow with an open case and better cooling.

mrstegeman commented 5 years ago

Hmmm interesting. Let me know if you figure anything out.

For reference, my testing was done on a 3B+ (as well as the x86-64) image.

gorbunovav commented 5 years ago

@mrstegeman I have Raspberry Pi 4 with 2Gb of RAM. I've tested it today - the CPU temperature was ok, no throttling. The plugin dies after about 7 minutes of constant CPU usage:

2019-08-28 11:04:10.141 INFO   : Loading add-on: wake-on-lan-adapter
2019-08-28 11:04:10.696 INFO   : wake-on-lan: Opening database: /home/node/.mozilla-iot/config/db.sqlite3
2019-08-28 11:04:10.727 INFO   : wake-on-lan: Loading add-on for wake-on-lan-adapter from /home/node/.mozilla-iot/addons/wake-on-lan-adapter
...
2019-08-28 11:11:38.056 INFO   : Plugin: wake-on-lan-adapter died, code = null restarting after 0
2019-08-28 11:11:38.586 INFO   : wake-on-lan: Opening database: /home/node/.mozilla-iot/config/db.sqlite3
2019-08-28 11:11:38.615 INFO   : wake-on-lan: Loading add-on for wake-on-lan-adapter from /home/node/.mozilla-iot/addons/wake-on-lan-adapter

I've also tried with a fresh installation of the gateway (new data folder and no other plugins installed) - the behavior is the same.

gorbunovav commented 5 years ago

@mrstegeman ok, I think I've tracked it down.

I have other containers on my Pi and the gateway uses the 'host' network mode (recommended way), so the resulting network is quite extensive with a lot of network masks like 255.255.0.0.

The plugin calls 'findDevices' function from the 'local-devices' package, which in turn is not very intellectual and just tries to ping all possible IPs on all available interfaces (which in my case is more than 500K records).

mrstegeman commented 5 years ago

That would do it! You can definitely run in bridge mode and just forward the two ports (8080 and 4443). Just be aware that some device discovery methods may not work.

gorbunovav commented 5 years ago

@mrstegeman I've tried and the wake feature doesn't work in the bridge mode 🙄

mrstegeman commented 5 years ago

I just released version 0.1.1 of the adapter. Could you update your add-on and then set the checkPing option in the config to false? That should hopefully fix your issues in host networking mode.

gorbunovav commented 5 years ago

@mrstegeman Yes, I've just tried - it works for me. Thank you!