Re: runsvdir polling

2017-01-15 Thread Steve Litt
On Sun, 15 Jan 2017 01:40:13 -0800
39066...@gmail.com wrote:

> On Sat, Jan 14, 2017 at 04:10:07PM -0500, Steve Litt wrote:
> > On Fri, 13 Jan 2017 21:12:27 -0800
> > 39066...@gmail.com wrote:
> >   
> > > I'm using runit as my primary init on Linux to good effect but
> > > have noticed that it accumulates CPU time even while the system
> > > is idle. I  
> > 
> > How much time in how much uptime? Which process are you looking at
> > with this accumulated time? Here's what I get:  
> 
> runsvdir has used 1m 55s over a bit under 5 days. The runsv instances
> are way less (but then they have no reason to wake). Load average is
> 0.00.
> 
> > On my computer, none of this in any practical way affects my
> > computing. I would guess on a more heavily used computer, any
> > deleterious effects of runit time consumption could be solved by
> > running runsvdir and all the runsv's with a positive nice value.
> > 
> > In my opinion, by far the greatest benefit of runit is its
> > simplicity, and there's no way I'd trade that for a theoretical
> > efficiency benefit.  
> 
> That sounds sensible on a desktop. In my case the motivation is to
> trim a source of power draw for an image that's going to run on a
> battery-powered device that will be awake but idle a lot of the time.
> Why Linux? Pretty much familiarity & tooling, if power is ok then I
> get to have my cake and eat it too.

Why not try s6? IIRC, s6 doesn't poll, is a little more complex than
runit, but like runit, it's a daemontools descendent. I've used it and
like it.

One thing to consider: What is the relationship between the 1m:55s and
power consumed? Is power consumption proportional to CPU time, or does
it depend on the kind of activity being done? Are disk accesses more,
or less power hungry than loops with calculations or other CPU
intensive stuff? How would you even find out the answers to these
questons?

Another question: What sized battery, is it rechargable, and how long
do you expect it to last between replacements or recharges? What I'm
getting at is this: If power draw is proportional to time, then in 50
days runsvdir would have consumed just under 20 minutes, which is
almost nothing if you're using a good sized battery.

Are you going to use a superserver? This sounds like a good case for a
superserver. You could use xinetd, or the djb-type superserver (can't
remember its name).

This sounds interesting.

SteveT

Steve Litt 
January 2017 featured book: Troubleshooting: Just the Facts
http://www.troubleshooters.com/tjust


Re: runsvdir polling

2017-01-15 Thread Laurent Bercot

How much time in how much uptime? Which process are you looking at with
this accumulated time?


 That's not an argument.
 Even if runit's (or sysvinit's, or...) polling is completely 
unnoticeable

- and on a desktop, to be fair, it definitely is - it doesn't mean that
polling is good.
 Polling is evil for several reasons, the two most important of them 
being

the following.

 1. From a software engineering POV: software that depends on underlying
polling has to wait for the polling period to be sure its changes have
been taken into account. When you have a system A that polls, a system B
that depends on A and also polls in another place, etc., the polling
periods compound each other, and this can introduce significant delays.

 I have met a real-life example of this at Google, of all places: 
sending

a high-level command to a batch of servers takes several seconds,
sometimes several minutes - not because there's lot of CPU involved, or 
high
network delays, but because Google's software stack is big, and most of 
its

layers perform polling at some point (processing a message queue every
second, or every few seconds, instead of getting notified when a new
message arrives), and it adds up. Most of Google's high-level commands
(start a service on a cluster of servers, change routing tables to 
direct

traffic somewhere else, etc.) spend a whole lot of time doing nothing.
Big scripts using high-level commands, such as automated software 
rollouts,
sometimes take hours to complete, whereas the real work involved could 
be

accomplished in 10-15 minutes tops; and software designed around polling
is the main culprit.

 2. At the complete opposite end of the scale, from an energy 
consumption

POV: you obviously will not notice that on a desktop, but on embedded
devices that are supposed to use energy sparingly (think set top boxes 
in

"sleep" mode, battery-powered/handheld devices, etc.), every spurious
wake-up counts. Even if, as runit does, you only wake up once every 14
seconds, it means you pull the CPU out of sleep mode - it cannot sleep
for extended periods of time.

 I have also met a real-life example of this, when I was working at
Sagemcom (a French manufacturer of embedded devices), making the base
system for an energy gateway (the thing that's supposed to collect and
report consumers' energy consumption; obviously, for such a task, it
should NOT use too much energy itself, else consumers will be angry and
have the right to be). I had spent a lot of time and energy trying to
convince the project leader that we should not use D-Bus, to no avail;
his argument was that D-Bus made communication easy with the Java part
(the proprietary application software was in Java). It was making *my*
life hell, but whatever, I could take it, I'm not a Java dev snowflake.
So I made a cool base system with no polling at all, with low-level
software reporting data to D-Bus, and shipped it to the Java people.
Later on, testing showed that the energy consumption was through the 
roof,
and the board was brought back to us for analysis; what we discovered 
was

that the chosen JVM implemented its D-Bus client by actually polling its
message queue every tenth of a second.
 Yes, the thing was waking up 10 times per second. Really.
 And, obviously, none of the tweaks we made were of any help: increasing
the polling period did not cut down energy consumption quite enough, but
it did cause significant delays in the handling of D-Bus data. I don't
know what became of the project, because I left the team at that time
(my part worked, so there was no reason for me to stay there, so they
put me on another project), but so far I haven't heard of a Sagemcom
energy gateway being deployed in people's homes.

 When you're an init system, i.e. the lowest possible level for 
user-space
software, and you *already* introduce polling, well, it doesn't bode 
well
for the rest of your software stack. Your energy-saving device is 
already

screwed, and automation that relies on runsvdir picking up a new service
is already eating an average 7 second delay. As a desktop user, you
obviously don't care; as a software architect, this makes me shake my 
head.

Even systemd does better on that point.

--
 Laurent



Re: runsvdir polling

2017-01-15 Thread 39066dd5
On Sat, Jan 14, 2017 at 04:10:07PM -0500, Steve Litt wrote:
> On Fri, 13 Jan 2017 21:12:27 -0800
> 39066...@gmail.com wrote:
> 
> > I'm using runit as my primary init on Linux to good effect but have
> > noticed that it accumulates CPU time even while the system is idle. I
> 
> How much time in how much uptime? Which process are you looking at with
> this accumulated time? Here's what I get:

runsvdir has used 1m 55s over a bit under 5 days. The runsv instances are way 
less (but then they have no reason to wake). Load average is 0.00.

> On my computer, none of this in any practical way affects my computing.
> I would guess on a more heavily used computer, any deleterious effects
> of runit time consumption could be solved by running runsvdir and all
> the runsv's with a positive nice value.
> 
> In my opinion, by far the greatest benefit of runit is its simplicity,
> and there's no way I'd trade that for a theoretical efficiency benefit.

That sounds sensible on a desktop. In my case the motivation is to trim a 
source of power draw for an image that's going to run on a battery-powered 
device that will be awake but idle a lot of the time. Why Linux? Pretty much 
familiarity & tooling, if power is ok then I get to have my cake and eat it too.