[erlang-questions] ERTS; code-server; dynamically loading of code

Ulf Wiger (TN/EAB) ulf.wiger@REDACTED
Mon Sep 18 11:05:02 CEST 2006


 
I second Lennart's opinion. Don't mess with the code loading unless you've become One with the Erlang environment.

Re-reading your question, it sounds as if Erlang already does what you want. The first time a module is called, it is automatically loaded if it hadn't already been loaded during startup.

You can control the initial code loading with the help of the -mode boot flag.

   erl -mode interactive

tells erlang to load modules on-demand. The on-demand code loading is triggered by the error_handler, which you shouldn't mess with, as Lennart said. A few modules are preloaded, mainly in the kernel and stdlib. This is the default.

   erl -mode embedded

says that all modules should be loaded at startup, and Erlang will never try to load code automatically from disk. This is typically what you want in a production system with high demands on responsiveness. Embedded mode also tends to speed up the boot phase slightly(*).

   erl -mode test

loads all modules in the boot script at startup, but still does code loading on-demand. The main reason for this is (I believe) that it has the same timing characteristics as '-mode embedded' during startup, but still offers the convenience of being able to call any module in the path.

(*) There is also a seldomly mentioned option, -code_path_cache, which caches the location of all modules in the path during startup. This can give significant speedup, since the code loader doesn't have to search the path for a module during on-demand code loading.

http://www.erlang.org/doc/doc-5.5.1/lib/kernel-2.11.1/doc/html/code.html

is your friend when trying to learn how code loading works.
It pretty much describes all that I've written here, and then
some.

BR,
Ulf W


> -----Original Message-----
> From: erlang-questions-bounces@REDACTED 
> [mailto:erlang-questions-bounces@REDACTED] On Behalf Of 
> Lennart Öhman
> Sent: den 17 september 2006 19:01
> To: 'Matthias Kretschmer'; erlang-questions@REDACTED
> Subject: Re: [erlang-questions] ERTS; code-server;dynamically 
> loading of code
> 
> Hi, hope you know what your are doing :-)
> 
> When a function can not be found, a function in the module 
> error_handler is called in the context of the process wishing 
> to execute the non-existing function. The code in the 
> error_handler communicated with the code_server process 
> (implemeneted in code) which implements the dynamic code 
> loading. Read those modules and you will understand.
> 
> Further more it is possible as a process flag to set which 
> module shall be error_handler. In this way one can actually 
> make certain parts of a system load code differently.
> 
> Good luck,
> Lennart
> 
> 
> -----Original Message-----
> From: erlang-questions-bounces@REDACTED
> [mailto:erlang-questions-bounces@REDACTED] On Behalf Of 
> Matthias Kretschmer
> Sent: den 17 september 2006 16:02
> To: erlang-questions@REDACTED
> Subject: [erlang-questions] ERTS; code-server; dynamically 
> loading of code
> 
> Hello,
> 
> I am searching for a way, to do my own code loading and 
> wondered how Erlang/OTP handles it. To be precise: I want to 
> use the Erlang-VM and adopt my own code for dynamically 
> loading the code if for the first time a module is used. I 
> was browsing the code and reading the documentation, but I 
> don't find it. Maybe I am blind, but I would appreciate any 
> hints how the standard Erlang Runtime System handles that and 
> where to find the more information (like documentation, which 
> modules/code-files are involved, etc.).
> 
> --
> Cheers and thank you in advance
> Matthias Kretschmer
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
> 
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
> 




More information about the erlang-questions mailing list