Dazo-org/zerovm — Issue #7: Resource Accounting
Author: camuel
Created: 2011-11-29 20:24:28+00:00
State: open

ZeroVM must accurately account all resources consumed by NEXE:

1. Net CPU time.
2. Net NEXE initiated disk IO (excluding all disk IO that not directly initiated or visible by NEXE).
3. Net NEXE initiated network IO (excluding all overhead, only net bytes of the message).
4. Gross allocated RAM for NEXE

Why so?

Because inaccurate measurements are in fact [leaky abstractions] (http://en.wikipedia.org/wiki/Leaky_abstraction) exposing internal implementation details in addition to be plain inaccurate.

How it should be implemented:

One way (and my recommended way) to implement is to programmatically count them in plain code:
1. RAM is easy with single allocation in zvm_initialize syscall.
2. Disk IO is also easy with just keeping track and counting read bytes and written bytes following zvm_read and zvm_write calls.
3. Ditto networking with future zvm_send_message and zvm_receive_message.
4. CPU is more tricky but also easy, measure time before transferring control to NEXE with something like gettimeofday() then measure again when NEXE terminated, the delta is the consumed CPU time. Now one single complication: when any syscall is called, measure the time before the call and after and substract it from the counter so the time of syscall is not included into the counter.
This seems to be adequate, simple and straightforward implementation.

Another way to implement is to use Linux facilities to get system consumption stats. There are several places where that info can be obtained, but none is simple to get work:
1. _taskstats_ via netlink interface => not possible to differentiate Network IO from Disk IO, not possible to get per thread stats (not currently needed)
2. reading from /proc... provides just samples not counters
Tell me if I'm wrong with this...

So again my recommendation is to stick with the simple even naive programmatic measuring coz I cannot see its inadequacy.