Emonhub - Reduce CPU usage

Well that was harder than I was expecting…

It turns out that my /etc/emonhub/emonhub.conf is a symlink to /home/pi/data/emonhub.conf, so watching /etc/emonhub and the file itself isn’t sufficient to guarantee seeing all changes…

Please test.

ARM are famous for having created a chip which, when measured, used zero power, because they had failed to connect the power supply and it was drawing enough power (<1W) from the IO pins.

The energy we have all expended talking about it is way more than the energy used by 1000x 90% idle raspberry pi! The incidental power cost of an already-running ARM chip is practically zero.

I admire your sentiment and, as evidenced by my clear desire to fix it, I agree with you :laughing:

1 Like

On Linux, you can use the inotify syscall to be notified of filesystem changes without polling. In Python you can use this: inotify · PyPI

1 Like

I still am not a fan or re-reading config files automatically when they are saved - I like to have control on when config changes take affect.

Do the other emon* components on the pi act this way ?

Regarding the energy savings, you should also think what else could be using these CPU cycles more effectively… mysql, openhab, nodered, emon* itself… and maybe be able to run it on lesser hardware too. I think we’ve all become accustomed to ‘better hardware’ vs ‘efficient software’… back in my day we had none’ of those stinkin’ giga-hertz-things, we had make do with a couple o’ nibbles and elastic band… youngsters today !

You should be able save a some watts on the PIs by running the cpu governor in power save mode… and it keeps on trucking just as well. Now multiply those watts X num of emonpis out there, that adds up.

Try this command on your Pi and see your power consumption go down (at least a tiny bit) (you may need to install the right package first) :

cpupower  frequency-set --governor powersave --max 900Mhz

Also here’s a great article on the most efficient Pi (perf per watt) … hint… it’s a Zero

Wow… that’s a lot of code to watch a file, well done for cracking it though.

Yeah… I’m not convinced it’s worth the added complexity. We don’t have a test suite (not that I’m complaining, I hate writing tests :laughing:). If we were rewriting this from scratch we would have an async event loop which would allow us to hang events like this and network, serial, bluetooth events easily, but alas.

My PR uses this. Please test it!

I agree very much!

Generally, yes. Most of it is PHP behind Apache, so when you want to do anything there has to be an HTTP request. Rewriting all that with websockets or webhooks or whatever would be a pretty big job, I expect. emonhub is quite trim in comparison.

Except that most people are just running it on the pi they bought from the OEM shop. The most energy efficient computer is the one you already own: Replacing all those pi’s with zeroes would not be better for the planet. And making emonhub more efficient, which I agree is philosophically correct, doesn’t make anything else the pi is doing more effective. We’re not even using all the cores on the pi…

In fact there is a case for “race to idle”: being able to do the work you need to do more quickly, so that the core can go back to sleep (the powersave governor defeats this, although I think the impact on ARM is truly minimal. Intel/AMD chips benefit greatly though).

That article was fascinating, thank you!

Anyway, please test. It’s almost certainly buggy. It’s still having to poll all the interfacers every 0.2s so I would be interested if you see a big difference in CPU usage.

That is an old install!

1 Like