[erlang-questions] Erlang code loading

Björn-Egil Dahlberg wallentin.dahlberg@REDACTED
Mon Nov 21 18:43:12 CET 2011


Erlang code is only memory referenced once for each module.

Constants in a module (literals) will be garbage collected to the heap upon
a purge if it is reachable. Hence memory can increase upon a purge and
reload.

Module loading is done from a single thread. The VM will block all other
threads, loads the module code and then pushes references  to export
entries. Upon completion the threads are released.

// Björn-Egil


2011/11/21 Max Bourinov <bourinov@REDACTED>

> I tend to think that Ladislav Lenart is right... At least I don't see any
> reason why actual code should be loaded more that once.
>
> Waiting for Erlang Super Master to clarify....
>
> Best regards,
> Max
>
>
>
>
> 2011/11/21 Max Bourinov <bourinov@REDACTED>
>
>> Does anybody knows how it exactly runs?
>>
>> Best regards,
>> Max
>>
>>
>>
>>
>> 2011/11/21 CGS <cgsmcmlxxv@REDACTED>
>>
>>> **
>>> Sorry for not being explicit. I was referring not only to the data, but
>>> also to the code itself. As far as I noticed, Erlang does not make any
>>> difference between loading the same module in different processes and
>>> different modules in different processes. Each process instance is
>>> independent and does not share any bit of its memory with other instances
>>> (it can copy, but does not share). I might be wrong in my observation,
>>> though (only a developer can be 100% sure).
>>>
>>> My test consisted in starting the same piece of code in two different
>>> Erlang sessions (processes as you call them) and I noticed the same memory
>>> consumption for each (top -d 1 -p <PID of the system process where your
>>> code is loaded>). You can test that as well and compare it with the beam
>>> size. As I said, I might be wrong because my code has a certain level of
>>> granularity which doesn't allow very large functions (I avoid large
>>> functions for better monitoring the states).
>>>
>>> I hope this answer will at least help you to convince yourself about
>>> which answer is correct.
>>>
>>> CGS
>>>
>>>
>>>
>>>
>>>
>>>
>>> On 11/21/2011 12:51 PM, Max Bourinov wrote:
>>>
>>> About the process data it is absolutely clean how Erlang handles it. I
>>> just want some clarification about the code.
>>>
>>>
>>> Best regards,
>>> Max
>>>
>>>
>>>
>>>
>>> 2011/11/21 CGS <cgsmcmlxxv@REDACTED>
>>>
>>>>  One instance per process, one memory allocation per process (even if
>>>> it is the same code running). Erlang has no explicit knowledge of beam
>>>> shared objects as far as I know. If somebody knows differently, please,
>>>> correct me.
>>>>
>>>> CGS
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> On 11/21/2011 12:40 PM, Max Bourinov wrote:
>>>>
>>>> Thank you for your reply! But in Erlang processes, not threads. There
>>>> are some differences between them...
>>>>
>>>>
>>>>
>>>> Отправлено с iPhone
>>>>
>>>> 21.11.2011, в 15:05, CGS <cgsmcmlxxv@REDACTED> написал(а):
>>>>
>>>>   Hi, Max,
>>>>
>>>> Not an expert, but I think the memory is multiplied by the number of
>>>> threads. Meaning, you start with an initial heap for that thread and add to
>>>> that the states and other internal variables (repeat that for all the
>>>> threads). At least that I noticed from my codes by now. If I am wrong, I
>>>> apologize.
>>>>
>>>> Cheers,
>>>> CGS
>>>>
>>>>
>>>>
>>>>
>>>> On 11/21/2011 11:57 AM, Max Bourinov wrote:
>>>>
>>>> Hi Erlangers,
>>>>
>>>>  I am wondering how my Erlang app would behave in this case:
>>>>
>>>>  I have a lot identical processes (the same module, state of couse is
>>>> different in each process). The module that I swap many times has a huge
>>>> function. I want to clarify how much memory it will take? It will take
>>>> memory for that huge function in each process or only once?
>>>>
>>>>  I believe it will take memory only once, but I want to make sure.
>>>>
>>>> Best regards,
>>>> Max
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> erlang-questions mailing listerlang-questions@REDACTED://erlang.org/mailman/listinfo/erlang-questions
>>>>
>>>>
>>>>   _______________________________________________
>>>> erlang-questions mailing list
>>>> erlang-questions@REDACTED
>>>> http://erlang.org/mailman/listinfo/erlang-questions
>>>>
>>>>
>>>>
>>>
>>>
>>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20111121/bacf466f/attachment.htm>


More information about the erlang-questions mailing list