[erlang-questions] Why is erlc so quick to start?
Mon Jan 5 10:56:07 CET 2015
Making an Erlang application start quickly is a engineering problem.
It's the "then make it fast" bit of "first make it work then make it fast"
It's relatively easy to make a specific Erlang application start quickly.
In what follows I've outlined three techniques to do this:
The first step is to identify exactly which modules are actually called.
Compile this and run with
> erl -s dummy start
It prints out 75
So to do *anything* the system loads 75 modules.
To make things faster you can
1) Hand tune your application to use less than 75 modules
In my book (shameless plug) Appendix C - I've cut this down to four
modules - BUT It's NOT the OTP system. So the standard libraries
don't work - the book version loaded a simple program in 0.02 seconds
(vs 1.13 seconds on the same machine for erl)
2) Take all the beam files for the 75 modules you need, remove debugging
symbols and put them in *one* file - and load from this.
I'm not saying you *should* do this - but you *could* do it if necessary. The
downside is you can't use the standard libraries - the upside is a
deeper understanding of the system.
The "default assumption" when we built Erlang was that the system once
started never stops - so trimming the odd second of the startup time
was never considered. Amortise the startup time over a few years and
the odd second doesn't matter.
A third method of ensuring fast startups is to keep a resident Erlang
node always up and running and using to_erl to connect to it - or
keeping a resident erlang node up and using telnet (or some other
protocol) to talk
to it - then you'll be running in a few ms.
Happy New Year
On Mon, Jan 5, 2015 at 10:08 AM, Roger Lipscombe <roger@REDACTED> wrote:
> Loïc has mentioned that any Erlang package manager must be as quick to
> start as 'erlc'. So, I figured that I'd take a quick look at how
> 'erlc' is started.
> The code's in erts/etc/common/erlc.c, and it appears to do this:
> erlc +sbtu +A0 -noinput -mode minimal -boot start_clean -s
> erl_compile compile_cmdline
> For comparison, "erl -noinput -s init stop" takes, according to
> /usr/bin/time, on average, 1.15 secs elapsed to exit, versus "erlc
> +sbtu +A0 -noinput -mode minimal -boot start_clean -s init stop",
> which takes 1.10 secs. This is with a Core i7-3930K @ 3.20GHz, running
> from an SSD.
> That's not much of a saving, but I guess it could make enough difference.
> For another data point, I used "-s erlang halt" instead of "-s init
> stop", and saw much bigger savings. The average time here was 0.10
> secs. From a brief look, I don't know which of these is more relevant.
> It's difficult to get a direct comparison with running the "erlc"
> binary, because it doesn't spawn the VM if there's nothing to compile,
> and if there is something to compile, it compiles it. So I wouldn't be
> comparing like with like.
> erlang-questions mailing list
More information about the erlang-questions