[erlang-questions] Building small erlang vm suitable for bundle with app.

52 views
Skip to first unread message

Albin Stigö

unread,
Dec 8, 2011, 5:27:39 AM12/8/11
to erlang-q...@erlang.org
Hi,

I'm quite new to Erlang and this list so I hope I'm posting in the right place?

I would like to use Erlang code (couchdb) in an Mac OS X app I'm
developing and I would like to bundle it with my app. Exactly like the
Mac OS X version of Wings3D is bundling a version of erlang.

I was wondering if someone kind provide me with some ideas of how to
compile a smaller version of the Erlang VM without the developing
tools etc?

Cheers,
Albin
_______________________________________________
erlang-questions mailing list
erlang-q...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions

Ahmed Omar

unread,
Dec 8, 2011, 5:55:30 AM12/8/11
to Albin Stigö, erlang-q...@erlang.org
Hi Albin, 
Yes it's the right place :)
What you are looking for is releases. You can create a release and include the erlang runtime system (erts) executables within it. You can also include any erlang app you have, like couchdb.

For more information about that i suggest you take a look at : 
--
Best Regards,
- Ahmed Omar
Follow me on twitter

Dmitry Kolesnikov

unread,
Dec 8, 2011, 10:58:39 AM12/8/11
to Ahmed Omar, erlang-q...@erlang.org
Hi,

Yes, release is the right thing. 
Just keep in mind that your release would contain platform dependent VM. If you create it on mac then you cannot run it on Linux. Thus you would need to run Linux in VirtualBox on your Mac to assemble a distributable releases.

Tim Watson

unread,
Dec 8, 2011, 12:04:19 PM12/8/11
to Dmitry Kolesnikov, erlang-q...@erlang.org
We do something similar to build parallel OTP for different architectures, although our packaging system assembles the release for the system you run it on, and then overwrites any native artefacts of the VM (i.e., shared object files and headers) for the target OS/architecture if required. This seems to work fine, although it's worth baring in mind that some releases include other stuff besides erts that is platform dependant.  

wrp

unread,
Dec 12, 2011, 10:15:02 PM12/12/11
to erlang-q...@erlang.org

On Dec 8, 2:55 am, Ahmed Omar <spawn.th...@gmail.com> wrote:
> What you are looking for is releases. You can create a release and include
> the erlang runtime system (erts) executables within it.
> For more information about that i suggest you take a look at...

The methods described at http://learnyousomeerlang.com/release-is-the-word
use systools and reltool, which result in rather large distributables.

"...with systools...the files are a bit large. The whole release takes
over 20 MB on disk..."

"...Some of our more general releases would weigh in at over 35 MB.
The one described above is reduced to less than 20 MB [with
reltool}... The size is still fairly large though. That's because of
ERTS, which itself takes 18.5 MB."""

However, http://www.erlang.org/faq/implementations.html says

"A 2 MB stripped Erlang system can include the beam emulator and
almost all of the stdlib, sasl, kernel, inets and runtime_tools
libraries, provided the libraries are compiled without debugging
information and are compressed..."

Are there detailed directions anywhere on building such small
distributables?

Benoit Chesneau

unread,
Dec 13, 2011, 2:15:16 AM12/13/11
to Albin Stigö, erlang-q...@erlang.org
Hi albin,

You can use the rebared version of couchdb I've wroitten to do that. It create a full Erlang release that you can eventually customize:

http://github.com/refuge/rcouch

& rebar template:

http://github.com/refuge/rcouch_template


hope it helps,


-benoît

Gustav Simonsson

unread,
Dec 13, 2011, 3:59:34 AM12/13/11
to Albin Stigö, erlang-q...@erlang.org

Hi!

This is a scrappy half-completed bash script I used to generate
a small Erlang release. It's something I hope can eventually grow
into a more general and stable tool for generating Erlang releases.

It does contain some useful things for reducing the size of an
Erlang release.

Also thanks to Adam Lindberg for helping out with it.

https://github.com/Gustav-Simonsson/Stripped-Erlang/blob/master/minimal_erlang.sh

Regards,
Gustav Simonsson

Sent from my PC

dmitry kolesnikov

unread,
Dec 14, 2011, 3:22:03 AM12/14/11
to Gustav Simonsson, Albin Stigö, erlang-q...@erlang.org
Hi,

I have not yet spent too much time to investigate how to build 2MB self-sustainable package but systools gives me about 14MB with possible reduction to 7 - 9MB on debian 64bit.

as an example *.rel package contains following libraries:
{kernel, "2.14.5"},
{stdlib, "1.17.5"},
{sasl,   "2.1.10"},
{crypto, "2.0.4"},
{public_key, "0.13"},
{ssl,    "4.1.6"},
{inets,  "5.7.1"},
{compiler, "4.7.5"},
{syntax_tools, "1.6.7.1"},
{xmerl,    "1.2.10"},
{mochiweb, "2.3.0"}
...

systools:make_tar($$n, [{erts, code:root_dir()}]) %% do not put any extra dirs here 

most heavy components are VM by itself 
-rwxr-xr-x   1 kolesnik  wheel   7.7M Oct 19 20:53 beam
-rwxr-xr-x   1 kolesnik  wheel   9.6M Oct 19 20:53 beam.smp

- Dmitry

Gustav Simonsson

unread,
Dec 14, 2011, 3:41:42 AM12/14/11
to dmitry kolesnikov, erlang-q...@erlang.org

Yes, you can remove either the SMP or the non-SMP beam depending on your target architecture.
Also the only things you need to just run Erlang is ERTS and the stdlib and kernel libs.

If you want to reduce the disk usage as much as possibly you can read on methods
in chapter 3.2 and results in chapter 5.1 in the following thesis:
http://urn.kb.se/resolve?urn=urn:nbn:se:uu:diva-156435

Matthias Lang

unread,
Dec 14, 2011, 7:35:17 PM12/14/11
to wrp, erlang-q...@erlang.org
On Monday, December 12, wrp wrote:

> However, http://www.erlang.org/faq/implementations.html says
>
> "A 2 MB stripped Erlang system can include the beam emulator and
> almost all of the stdlib, sasl, kernel, inets and runtime_tools
> libraries, provided the libraries are compiled without debugging
> information and are compressed..."
>
> Are there detailed directions anywhere on building such small
> distributables?

That part of the FAQ was written about 10 years ago, when erts was
smaller than it is today. It's still possible to get below 3M without
pulling wild tricks, e.g. on an ARM system I have

# du
24 ./bin
1019 ./lib
1480 ./erts-5.8.4/bin
1480 ./erts-5.8.4
2523 .

Full list of files below.

The shrinking is done by judicious use of 'rm', plus this hack:

http://erlang.org/pipermail/erlang-questions/2011-June/059489.html

Matt

--------------------
# ls -lR
.:
drwxrwxr-x 2 root root 0 Dec 13 16:03 bin
drwxr-xr-x 3 root root 0 Dec 13 16:03 erts-5.8.4
drwxr-xr-x 2 root root 0 Dec 13 16:03 lib

./bin:
-rwxr-xr-x 1 root root 857 Dec 12 15:00 erl
lrwxrwxrwx 1 root root 25 Dec 13 16:03 run_erl -> ../erts-5.8.4/bin/run_erl
lrwxrwxrwx 1 root root 6 Dec 13 16:03 run_test -> ct_run
-rwxr-xr-x 1 root root 1159 Dec 12 15:00 start
-rw-r--r-- 1 root root 5372 Dec 12 15:00 start.boot
-rw-r--r-- 1 root root 6350 Dec 12 15:00 start.script
-rwxr-xr-x 1 root root 1259 Dec 12 15:00 start_erl
-rw-r--r-- 1 root root 6535 Dec 12 15:00 start_sasl.boot
lrwxrwxrwx 1 root root 24 Dec 13 16:03 to_erl -> ../erts-5.8.4/bin/to_erl

./erts-5.8.4:
drwxr-xr-x 2 root root 0 Dec 13 16:03 bin

./erts-5.8.4/bin:
-rwxr-xr-x 1 root root 1411656 Dec 12 15:00 beam
-rwxr-xr-x 1 root root 9304 Dec 12 15:00 child_setup
-rwxr-xr-x 1 root root 857 Dec 12 15:00 erl
-rwxr-xr-x 1 root root 35168 Dec 12 15:00 erlexec
-rwxr-xr-x 1 root root 32624 Dec 12 15:00 inet_gethost
-rwxr-xr-x 1 root root 16068 Dec 12 15:00 run_erl
-rwxr-xr-x 1 root root 7980 Dec 12 15:00 to_erl

./lib:
-rw-rw-r-- 1 root root 63577 Dec 12 15:00 erts-5.8.4.ez
-rw-rw-r-- 1 root root 311423 Dec 12 15:00 kernel-2.14.4.ez
-rw-rw-r-- 1 root root 39390 Dec 12 15:00 sasl-2.1.9.4.ez
-rw-rw-r-- 1 root root 628179 Dec 12 15:00 stdlib-1.17.4.ez

Andrew Gopienko

unread,
Dec 15, 2011, 4:35:30 AM12/15/11
to dmitry kolesnikov, erlang-q...@erlang.org
Hi,

You can also strip the executables and erlang beams (beam_lib:strip*).

-rwxr-xr-x 1 tdx tdx 1942300 2011-12-15 13:29 beam*
-rwxr-xr-x 1 tdx tdx 2134876 2011-12-15 13:29 beam.smp*


Andrew Gopienko

2011/12/14 dmitry kolesnikov <dmkole...@gmail.com>
Reply all
Reply to author
Forward
0 new messages