
Investigating Erlang by reading its system calls - ingve
http://jvns.ca/blog/2016/05/13/erlang-seems-really-complicated/
======
garazdawi_hn
If you run something like:

erl -noshell +sbwt none -smp disable +A 0 -mode minimal -eval
'io:format("Hello world~n").' -s init stop

instead, which is much closer to what python/java et al runs, then at least I
get around 2850 syscalls.

The constant ppoll:ing is because erts spins looking for new work from any fd.
Specifically "/sys/devices/system/node/node0" is in order to check for cpu
topology updates by the operating system, i.e. if for some reason a core/cpu
is taken offline of something like that. This is limited in my example above
by "+sbwt none"

IIRC the bind is an UDP socket to talk to the local nameserver. This is
removed in my example with "-mode minimal".

~~~
liveoneggs
this feels similar to the overhead of an escript

------
yetihehe
Maybe some analogy - C is like riding a very fast bike. Python, Java -
Starting a truck which will move what you want. Erlang - starting a railway
system.

Erlang is like another system inside your system, it's more akin to booting a
system inside a vm just to echo some hello world.

~~~
sspiff
Bike as in motorcycle, not bicycle I presume?

~~~
yetihehe
It depends IMO, small c programs - bicycle, bigger ones - motorcycle. If you
want to extend this further, C can be any bike or even a road (linux).

~~~
sargun
I'd say C is the bicycle and C++ is the motorcycle. Both give you plenty of
chances to kill yourself.

------
jen20
A quick suggestion for the author based on the "dude I can't debug anything on
OS X" line - take a look at DTrace, which is shipped with MacOS (albeit an old
version).

Compared with strace on Linux it is like night and day.

~~~
jonesetc
> [http://jvns.ca/blog/2016/01/14/a-few-notes-on-my-cusec-
> talk/](http://jvns.ca/blog/2016/01/14/a-few-notes-on-my-cusec-talk/)

On debugging, second bullet. She seems to agree.

~~~
marai2
can we have all man pages converted into "zine" pages, as Julia Evans does for
strace here :-) [http://jvns.ca/strace-zine-
unfolded.pdf](http://jvns.ca/strace-zine-unfolded.pdf)

------
al_chemist
> I wanted to debug something > I've analyzed Erlang strace > "Erlang is
> complicated"

If you want to debug Erlang program then Erlang/OTP already includes tools to
help you do that: [http://www.erlang-in-anger.com/](http://www.erlang-in-
anger.com/) \- 92 page manual that includes: \- tracing functions called with
defined parameters \- analyzing crash dumps, memory leaks, cpu scheduling

~~~
toast0
This is great, if you're planning to do many things with erlang, our you have
a lot of time. If your friend has a weird problem and comes to you because you
have a reputation for figuring things out that you've earned by using strace,
then you use strace. Incidentally, I'm reading this because I use erlang, but
it took about a minute to see the problem (tcp port exhaustion) from the
strace.

------
mweibel
cross posting what I wrote as a comment in the article:

epmd is a separate process, yes. But an erlang node connects to epmd in order
to register it's name on it. It will bind a socket to talk with epmd (probably
among other things).. See also:
[http://erlang.org/doc/apps/erts/erl_dist_protocol.html](http://erlang.org/doc/apps/erts/erl_dist_protocol.html)

------
anfroid555
Erlang is a system not just a language

------
kazinator

      $ cat hello.tl
      (pprinl "hello, world")
      $ strace txr hello.tl 2>&1 > /dev/null | wc -l
      77
    
      $ cat hello.c
      #include <stdio.h>
      int main(void) { printf("Hello, world\n"); }
      $ cc -O hello.c -o hello
      $ strace ./hello 2>&1 > /dev/null | wc -l
      29
    
      $ strace gawk 'BEGIN { print "hello") }' 2>&1 > /dev/null  | wc -l
      84

~~~
jaytaylor

        $ strace python -c "print('hello world')" 2>&1 > /dev/null | wc -l
        924
    
        $ strace python3 -c "print('hello world')" 2>&1 > /dev/null | wc -l
        543

~~~
jamesdutc
Python's site module contributes a lot to this. It attempts to load a lot of
other modules, many of which may not exist for a given install.

Using your example:

    
    
        $ strace python3 -c 'print("hello world", end="")' 2>&1 | hist
         1. stat                 122
         2. rt_sigaction         68
         3. fstat                67
         4. read                 55
         5. close                47
         6. open                 37
         7. mmap                 34
         8. lseek                30
         9. getdents             18
        10. mprotect             16
            ...                 
            TOTAL:               567
    
        $ strace python3 -S -c 'print("hello world", end="")' 2>&1 | hist
         1. rt_sigaction         68
         2. stat                 51
         3. fstat                39
         4. mmap                 31
         5. read                 27
         6. close                26
         7. open                 23
         8. mprotect             16
         9. lseek                15
        10. brk                  10
            ...                 
            TOTAL:               350

------
gjkood
Would it make sense to do a large number of iterations (in the millions) of
the basic "Hello, World\n" print statement in all the languages to amortize
the cost of the BEAM/JVM setup/initialization system calls out?

Isn't it the case that in Java and Erlang we have a large VM environment that
also needs to be launched before the first line of the trivial print statement
is executed?

------
self_awareness
Rust:

    
    
        $ cargo new --bin hello
        $ cd hello
        $ cargo build --release
        $ strace ./target/release/hello 2>&1 | wc -l           
        124

------
ysleepy
This comparison is rather meaningless. It is measuring the Runtime startup. -
Opening jars/pyc files.

Why not do a specific call before the actual code to segment the strace, or
run it with repetitions and subtract+divide to get calls/repetition?

------
stcredzero
_One last thing -- erlang runs bind once when it starts. Why does it need to
listen on a TCP socket to run hello world?_

My first thought: "So this guy is investigating Erlang with strace, but he
couldn't be bothered to Google articles on its design!?" Then I tried Googling
this myself. Uh, yeah. I happen to know this stuff, even though I don't use
Erlang, but it's not exactly easy to find packaged conveniently in one place.

