<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<id>tag:old.nabble.com,2006:forum-14095</id>
	<title>Nabble - Erlang</title>
	<updated>2009-11-09T09:42:39Z</updated>
	<link rel="self" type="application/atom+xml" href="http://old.nabble.com/Erlang-f14095.xml" />
	<link rel="alternate" type="text/html" href="http://old.nabble.com/Erlang-f14095.html" />
	<subtitle type="html">Erlang is a programming language which has many features more commonly associated with an operating system than with a programming language: concurrent processes, scheduling, memory management, distribution, networking, etc. Erlang home is &lt;a href=&quot;http://www.erlang.org/&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;here&lt;/a&gt;.</subtitle>
	
<entry>
	<id>tag:old.nabble.com,2006:post-26271203</id>
	<title>Re: Why Beam.smp crashes when memory is over?</title>
	<published>2009-11-09T09:42:39Z</published>
	<updated>2009-11-09T09:42:39Z</updated>
	<author>
		<name>Jayson Vantuyl-2</name>
	</author>
	<content type="html">The problem is that there is no way for the VM to really know which &amp;nbsp;
&lt;br&gt;process is leaking. &amp;nbsp;The Linux OOM-killer has gone through a bunch of &amp;nbsp;
&lt;br&gt;rewrites and it still doesn't always get it right.
&lt;br&gt;&lt;br&gt;It might be possible to have a threshold trigger that would hit some &amp;nbsp;
&lt;br&gt;sort of global alarm that could be application specific. &amp;nbsp;That's &amp;nbsp;
&lt;br&gt;probably the closest you could get though.
&lt;br&gt;&lt;br&gt;On Nov 8, 2009, at 9:08 PM, Max Lapshin wrote:
&lt;br&gt;&lt;div class='shrinkable-quote'&gt;&lt;br&gt;&amp;gt; Look, I have a program, that reads MPEG TS stream from network. There
&lt;br&gt;&amp;gt; is some bug in my code
&lt;br&gt;&amp;gt; and my ts_lander crashes beam. How is it possible to store state of
&lt;br&gt;&amp;gt; external HTTP stream??
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; If Erlang VM wouldn't crash, but only kill the leaking process, I
&lt;br&gt;&amp;gt; could buffer stream in other process and feed
&lt;br&gt;&amp;gt; new mpeg ts lander after restart. But it is impossible =(
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; ________________________________________________________________
&lt;br&gt;&amp;gt; erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;&amp;gt; erlang-questions (at) erlang.org
&lt;br&gt;&amp;gt;
&lt;/div&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;-- 
&lt;br&gt;Jayson Vantuyl
&lt;br&gt;&lt;a href=&quot;http://old.nabble.com/user/SendEmail.jtp?type=post&amp;post=26271203&amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;kagato@...&lt;/a&gt;
&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;________________________________________________________________
&lt;br&gt;erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;erlang-questions (at) erlang.org
&lt;br&gt;&lt;br&gt;&lt;p&gt;From forum: &lt;a href=&quot;http://old.nabble.com/Erlang-Questions-f14096.html&quot; embed=&quot;fixTarget[14096]&quot; target=&quot;_top&quot; &gt;Erlang Questions&lt;/a&gt;&lt;/p&gt;</content>
	<link rel="alternate" type="text/html" href="http://old.nabble.com/Why-Beam.smp-crashes-when-memory-is-over--tp26257892p26271203.html" />
</entry>

<entry>
	<id>tag:old.nabble.com,2006:post-26271159</id>
	<title>Re: Why Beam.smp crashes when memory is over?</title>
	<published>2009-11-09T09:40:55Z</published>
	<updated>2009-11-09T09:40:55Z</updated>
	<author>
		<name>Jayson Vantuyl-2</name>
	</author>
	<content type="html">You could run two Erlang VMs (thus, keeping the HTTP connection and &amp;nbsp;
&lt;br&gt;its state separate). &amp;nbsp;Then the crasher wouldn't take the other one &amp;nbsp;
&lt;br&gt;down. &amp;nbsp;One with the processing and one with the networking, and have &amp;nbsp;
&lt;br&gt;them communicate via distributed Erlang. &amp;nbsp;You should still ulimit beam &amp;nbsp;
&lt;br&gt;to keep the other one from getting OOM-killed though.
&lt;br&gt;&lt;br&gt;Assuming you can get the throughput you need, this also would &amp;nbsp;
&lt;br&gt;decompose some of the components, which might helps scale horizontally &amp;nbsp;
&lt;br&gt;later.
&lt;br&gt;&lt;br&gt;On Nov 8, 2009, at 9:08 PM, Max Lapshin wrote:
&lt;br&gt;&lt;div class='shrinkable-quote'&gt;&lt;br&gt;&amp;gt; Look, I have a program, that reads MPEG TS stream from network. There
&lt;br&gt;&amp;gt; is some bug in my code
&lt;br&gt;&amp;gt; and my ts_lander crashes beam. How is it possible to store state of
&lt;br&gt;&amp;gt; external HTTP stream??
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; If Erlang VM wouldn't crash, but only kill the leaking process, I
&lt;br&gt;&amp;gt; could buffer stream in other process and feed
&lt;br&gt;&amp;gt; new mpeg ts lander after restart. But it is impossible =(
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; ________________________________________________________________
&lt;br&gt;&amp;gt; erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;&amp;gt; erlang-questions (at) erlang.org
&lt;br&gt;&amp;gt;
&lt;/div&gt;&lt;br&gt;&lt;br&gt;________________________________________________________________
&lt;br&gt;erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;erlang-questions (at) erlang.org
&lt;br&gt;&lt;br&gt;&lt;p&gt;From forum: &lt;a href=&quot;http://old.nabble.com/Erlang-Questions-f14096.html&quot; embed=&quot;fixTarget[14096]&quot; target=&quot;_top&quot; &gt;Erlang Questions&lt;/a&gt;&lt;/p&gt;</content>
	<link rel="alternate" type="text/html" href="http://old.nabble.com/Why-Beam.smp-crashes-when-memory-is-over--tp26257892p26271159.html" />
</entry>

<entry>
	<id>tag:old.nabble.com,2006:post-26270548</id>
	<title>Re: AW: Why Beam.smp crashes when memory is over?</title>
	<published>2009-11-09T09:38:59Z</published>
	<updated>2009-11-09T09:38:59Z</updated>
	<author>
		<name>Jayson Vantuyl-2</name>
	</author>
	<content type="html">This would be a very useful tunable.
&lt;br&gt;&lt;br&gt;On Nov 9, 2009, at 2:31 AM, Decker, Nils wrote:
&lt;br&gt;&lt;div class='shrinkable-quote'&gt;&lt;br&gt;&amp;gt; Hello,
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; I had a few occasions during developing that a runaway process &amp;nbsp;
&lt;br&gt;&amp;gt; caused my machine to swap and gind to a halt. (i should have used &amp;nbsp;
&lt;br&gt;&amp;gt; ulimit on beam)
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; I wondered why there is no way to limit the size of a single &amp;nbsp;
&lt;br&gt;&amp;gt; process. It could be a simple option to spawn to limit the heap size &amp;nbsp;
&lt;br&gt;&amp;gt; of a process. (like ulimit)
&lt;br&gt;&amp;gt; The process gets killed if it ever grows beyond the limit. A limit &amp;nbsp;
&lt;br&gt;&amp;gt; for the size of the message queue would be nice too, because a &amp;nbsp;
&lt;br&gt;&amp;gt; process with a few thousand entries is (most of the time) not going &amp;nbsp;
&lt;br&gt;&amp;gt; to cope with it anyway.
&lt;br&gt;&amp;gt; A similar limit for ETS tables would be possible too. A memory limit &amp;nbsp;
&lt;br&gt;&amp;gt; for shared resources (large binaries) would be more difficult.
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; Nils Decker
&lt;/div&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;-- 
&lt;br&gt;Jayson Vantuyl
&lt;br&gt;&lt;a href=&quot;http://old.nabble.com/user/SendEmail.jtp?type=post&amp;post=26270548&amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;kagato@...&lt;/a&gt;
&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;________________________________________________________________
&lt;br&gt;erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;erlang-questions (at) erlang.org
&lt;br&gt;&lt;br&gt;&lt;p&gt;From forum: &lt;a href=&quot;http://old.nabble.com/Erlang-Questions-f14096.html&quot; embed=&quot;fixTarget[14096]&quot; target=&quot;_top&quot; &gt;Erlang Questions&lt;/a&gt;&lt;/p&gt;</content>
	<link rel="alternate" type="text/html" href="http://old.nabble.com/Why-Beam.smp-crashes-when-memory-is-over--tp26257892p26270548.html" />
</entry>

<entry>
	<id>tag:old.nabble.com,2006:post-26269216</id>
	<title>Re: Why Beam.smp crashes when memory is over?</title>
	<published>2009-11-09T08:21:41Z</published>
	<updated>2009-11-09T08:21:41Z</updated>
	<author>
		<name>Angel Alvarez</name>
	</author>
	<content type="html">&lt;br&gt;El Lunes, 9 de Noviembre de 2009 Tony Rogvall escribió:
&lt;div class='shrinkable-quote'&gt;&lt;br&gt;&amp;gt; Hi!
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; On 9 nov 2009, at 14.54, Angel Alvarez wrote:
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; &amp;gt; Well still there are many issues with this new approach
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; Yes! &amp;nbsp;But it does not scare me ;-)
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; &amp;gt; Where are the maibox of processes located?
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt; With a heap pre process...
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; Depends on the implementation. But in general you could do something &amp;nbsp;
&lt;br&gt;&amp;gt; like, If the the data is shared then
&lt;br&gt;&amp;gt; you split the share (memory_size/ref_count). If the data is copied &amp;nbsp;
&lt;br&gt;&amp;gt; then you must count it in.
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt; Couldnt you trigger a memory exception on a remote process by just &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt; sending one message
&lt;br&gt;&amp;gt; &amp;gt; when the process is almost consuming its reserved memory?
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; Yes. But that is the point. If it pass the limit the process will die.
&lt;br&gt;&amp;gt; There are many special cases where you could think of using the memory &amp;nbsp;
&lt;br&gt;&amp;gt; in a better and more optimal way.
&lt;br&gt;&amp;gt; Lets say you are reaching the memory limit you may switch to a &amp;nbsp;
&lt;br&gt;&amp;gt; compression algorithm for heap memory !?
&lt;br&gt;&amp;gt; But lets keep it simple for the prototype, and see if it useful.
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; &amp;gt; Systems other than embedded erlangs deploy ( form de current erlang &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt; movement as a server/desktop plataform)
&lt;br&gt;&amp;gt; &amp;gt; will suffer from resource contention beetween erlang VM and other OS &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt; processes.
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt; Port programs also need system resources...
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; For loadable drivers using driver_alloc, one could possibly do &amp;nbsp;
&lt;br&gt;&amp;gt; something, otherwise it will be
&lt;br&gt;&amp;gt; up to the driver designer to handle it. There is a max_ports in the &amp;nbsp;
&lt;br&gt;&amp;gt; prototype that limits number of
&lt;br&gt;&amp;gt; open_ports. If sockets/files are mapped to single ports then it may &amp;nbsp;
&lt;br&gt;&amp;gt; help a bit.
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; &amp;gt; Well in the end your approach is still very interesting as a &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt; framework for continous erlang VM innovations...
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; Thanks.
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; &amp;gt; but please correct me if im wrong but I saw that memory carriers &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt; allowed to set several options on erlang VM start-up so,
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; I am not sure what you mean here?
&lt;/div&gt;&lt;br&gt;Well some bits can be controlled as you show on spawn_opt. In the other hand i mean that VM Safe memory
&lt;br&gt;as stated by others (Andrew, Tom ...) should be controlled on memory carriers: ( erts_alloc(3) )
&lt;br&gt;&lt;br&gt;In esence
&lt;br&gt;&lt;br&gt;- A new emergency memory alocator in the alloc_util framework just in case the VM need memory to recover from a OOM.
&lt;br&gt;&lt;br&gt;or perhaps
&lt;br&gt;&lt;br&gt;&amp;lt;WARNING speculative mode ON&amp;gt;
&lt;br&gt;&lt;br&gt;- Using the segment allocator on mmap supported arquitectures to allow fast recovery for the full erlang vm (sort of checkpointing)
&lt;br&gt;using a special BIF you could instruct memory carriers to checkpoint the entire VM usining this allocator just in case the VM crashes.
&lt;br&gt;so on next run the enrire VM can be recovered parsing the last checkpint
&lt;br&gt;&lt;br&gt;&amp;lt;/WARNING&amp;gt;
&lt;br&gt;&lt;br&gt;&lt;br&gt;Still i think is better and more clean having two o more instances that bulletprooffing the VM
&lt;br&gt;&lt;br&gt;/Angel 
&lt;br&gt;&lt;div class='shrinkable-quote'&gt;&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; /Tony
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; &amp;gt; is stil posible to pacth those carriers to allow a safe memory &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt; reservation to let de VM manage properly a memory full
&lt;br&gt;&amp;gt; &amp;gt; condition by killing the offending process (sort of a OOM killer for &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt; the VM)?
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt; Just telling the VM not to &amp;quot;kill system process&amp;quot; and let the &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt; supervisors do the work...
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; &amp;gt; /Angel
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt; El Lunes, 9 de Noviembre de 2009 Tony Rogvall escribió:
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; It is still the same &amp;quot;let it crash&amp;quot; concept using the resource limit
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; system I am designing.
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; But you can limit the crash in a more controlled way. Also you will &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; be
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; able to report
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; interesting information about what is crashing and when.
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; There is sometimes an issue when big systems crash. The restart may
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; take a lot of time.
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; Nodes must be synchronised, database tables must be repaired etc etc.
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; I guess you can design this to be light and easy, but it is not &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; always
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; the case.
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; /Tony
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; On 9 nov 2009, at 12.43, Angel Alvarez wrote:
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; Well please let me say something
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; I'm plain new but some things are pretty clear for me.
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; The beauty of the erlang concept is &amp;quot;let it crash&amp;quot; , &amp;quot;don't program
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; defensively&amp;quot;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; so the VM and the underlaying hardware are entities that can fail,
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; that's it.
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; What's the problem so?
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; Joe said...
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; If you want failure tolerance you need at least two nodes...
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; From J.A thesis
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; &amp;nbsp;&amp;quot; ...Schneider [60, 59] answered this question by giving three
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; properties
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; that he thought a hardware system should have in order to be
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; suitable for
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; programming a fault-tolerant system. These properties Schneider
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; called:...&amp;quot;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; 1. Halt on failure — in the event of an error a processor should &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; halt
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; &amp;nbsp; &amp;nbsp; instead of performing a possibly erroneous operation.2
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; So on memory exhaustation the VM has to die and other node (erlang)
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; will do the recovery.
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; that's the distrirbution role, no only to span computations over
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; several nodes to enhance performance
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; but to provide resilence in the presence of fatal errors (non
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; correctable).
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; As a OS process the VM has to compete with other OS processes so in
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; a shared deployment (a VM running
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; on a server or a desktop) you cant be safe agaisnt a OOM trigered by
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; other entities.
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; Such resource control thing wil only augment process overhead and
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; context switching in the VM.
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; People new to erlang will be atracted to this hierarquical
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; decomposition of tasks as joe stated in his thesis
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; &amp;quot;If you cant run certaing task try doing something simpler&amp;quot;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; Many languages and VM's are incorporating erlang's good &amp;quot;multicore&amp;quot;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; features but not the erlang powerfull error handling concept
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; and you guys want to kill the simpliticy incorporating many
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; defensive capabilities to avoid fatality instead of just organize
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; code to
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; handle such fatality.
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; ¿whats next?, &amp;nbsp;¿A mailbox maximum message queue control?
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; Well, that's all i have to say about that, Forrest Gump.
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; El Lunes, 9 de Noviembre de 2009 09:45:10 Tony Rogvall escribió:
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt; Interesting discussion!
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt; I have been working on a resource system for Erlang for nearly two
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt; years now.
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt; I have a working (tm) prototype where you can set resource limits
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt; like
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt; max_processes/max_ports/max_memory/max_time/max_reductions ...
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt; The limits are passed with spawn_opt and are inherited by the
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt; processes spawned.
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt; This means that if you spawn_opt(M,F,A[{max_memory, 1024*1024}]) &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt; the
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt; process
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt; will be able to use 1M words for it self and it's &amp;quot;subprocesses&amp;quot;.
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt; This
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt; also means
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt; that the spawner will get 1M less to use (as designed right now).
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt; If a
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt; resource limit
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt; is reached the process crash with system_limt reason.
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt; There are still some details to work out before a release, but I &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt; will
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt; try to get it ready before
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt; end of this year.
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt; /Tony
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt; On 9 nov 2009, at 09.16, Robert Virding wrote:
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; No.
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; There is a major difference between handling OOM in an OS and in &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; the
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; BEAM.
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; In an OS it usually at a per process level that memory runs out so
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; it is
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; easy to decide which process to kill so that the OS can &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; continue. In
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; the
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; BEAM, however, it is the VM as a whole which has run out of memory
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; not a
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; specific, it is. therefore, much more difficult to work out which
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; process is
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; the culprit and to decide what to do. For example it might be that
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; the
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; process which causes the OOM is not the actual problem process, it
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; might
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; just the last straw. Or the actual cause may that the whole app
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; might be
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; generating large binaries too quickly. Or it might be that the &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; whole
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; app is
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; spawning to many processes without any one process being the &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; cause.
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; Or ...
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; In all these cases killing the process which triggered the OOM &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; would
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; be the
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; Wrong Thing. We found that it was difficult to work out a &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; reasonable
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; strategy to handle the actual cause so we decided not handle it.
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; &amp;quot;Don't catch an error which you can't handle&amp;quot; as the bard put it.
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; Robert
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; 2009/11/9 Max Lapshin &amp;lt;&lt;a href=&quot;http://old.nabble.com/user/SendEmail.jtp?type=post&amp;post=26269216&amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;max.lapshin@...&lt;/a&gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; Yes, there are techniques to write watchdogs, but my question
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; was: is
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; it possible to prevent Erlang VM from crash?
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; ________________________________________________________________
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; erlang-questions (at) erlang.org
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt; ________________________________________________________________
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt; erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt; erlang-questions (at) erlang.org
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; Este correo no tiene dibujos. Las formas extrañas en la pantalla son
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; letras.
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; __________________________________________
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; Clist UAH a.k.a Angel
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; __________________________________________
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; Warning: Microsoft_bribery.ISO contains OOXML code.
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; ________________________________________________________________
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; erlang-questions (at) erlang.org
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt; -- 
&lt;br&gt;&amp;gt; &amp;gt; No imprima este correo si no es necesario. El medio ambiente está en &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt; nuestras manos.
&lt;br&gt;&amp;gt; &amp;gt; __________________________________________
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt; Clist UAH a.k.a Angel
&lt;br&gt;&amp;gt; &amp;gt; __________________________________________
&lt;br&gt;&amp;gt; &amp;gt; China 'limpia' el Tibet para las Olimpiadas.
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; 
&lt;/div&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;-- 
&lt;br&gt;Este correo no tiene dibujos. Las formas extrañas en la pantalla son letras.
&lt;br&gt;__________________________________________
&lt;br&gt;&lt;br&gt;Clist UAH a.k.a Angel
&lt;br&gt;__________________________________________
&lt;br&gt;Artista -- (internet) --&amp;gt; Usuario final. Así los artistas cobran más y dicen menos paridas sobre lo que creen que es la piratería.
&lt;br&gt;&lt;br&gt;________________________________________________________________
&lt;br&gt;erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;erlang-questions (at) erlang.org
&lt;br&gt;&lt;br&gt;&lt;p&gt;From forum: &lt;a href=&quot;http://old.nabble.com/Erlang-Questions-f14096.html&quot; embed=&quot;fixTarget[14096]&quot; target=&quot;_top&quot; &gt;Erlang Questions&lt;/a&gt;&lt;/p&gt;</content>
	<link rel="alternate" type="text/html" href="http://old.nabble.com/Why-Beam.smp-crashes-when-memory-is-over--tp26257892p26269216.html" />
</entry>

<entry>
	<id>tag:old.nabble.com,2006:post-26267513</id>
	<title>Re: Why Beam.smp crashes when memory is over?</title>
	<published>2009-11-09T06:38:02Z</published>
	<updated>2009-11-09T06:38:02Z</updated>
	<author>
		<name>Tony Rogvall-2</name>
	</author>
	<content type="html">Hi!
&lt;br&gt;&lt;br&gt;On 9 nov 2009, at 14.54, Angel Alvarez wrote:
&lt;br&gt;&lt;br&gt;&amp;gt; Well still there are many issues with this new approach
&lt;br&gt;&amp;gt;
&lt;br&gt;Yes! &amp;nbsp;But it does not scare me ;-)
&lt;br&gt;&lt;br&gt;&amp;gt; Where are the maibox of processes located?
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; With a heap pre process...
&lt;br&gt;&lt;br&gt;Depends on the implementation. But in general you could do something &amp;nbsp;
&lt;br&gt;like, If the the data is shared then
&lt;br&gt;you split the share (memory_size/ref_count). If the data is copied &amp;nbsp;
&lt;br&gt;then you must count it in.
&lt;br&gt;&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; Couldnt you trigger a memory exception on a remote process by just &amp;nbsp;
&lt;br&gt;&amp;gt; sending one message
&lt;br&gt;&amp;gt; when the process is almost consuming its reserved memory?
&lt;br&gt;&amp;gt;
&lt;br&gt;Yes. But that is the point. If it pass the limit the process will die.
&lt;br&gt;There are many special cases where you could think of using the memory &amp;nbsp;
&lt;br&gt;in a better and more optimal way.
&lt;br&gt;Lets say you are reaching the memory limit you may switch to a &amp;nbsp;
&lt;br&gt;compression algorithm for heap memory !?
&lt;br&gt;But lets keep it simple for the prototype, and see if it useful.
&lt;br&gt;&lt;br&gt;&lt;br&gt;&amp;gt; Systems other than embedded erlangs deploy ( form de current erlang &amp;nbsp;
&lt;br&gt;&amp;gt; movement as a server/desktop plataform)
&lt;br&gt;&amp;gt; will suffer from resource contention beetween erlang VM and other OS &amp;nbsp;
&lt;br&gt;&amp;gt; processes.
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; Port programs also need system resources...
&lt;br&gt;&amp;gt;
&lt;br&gt;For loadable drivers using driver_alloc, one could possibly do &amp;nbsp;
&lt;br&gt;something, otherwise it will be
&lt;br&gt;up to the driver designer to handle it. There is a max_ports in the &amp;nbsp;
&lt;br&gt;prototype that limits number of
&lt;br&gt;open_ports. If sockets/files are mapped to single ports then it may &amp;nbsp;
&lt;br&gt;help a bit.
&lt;br&gt;&lt;br&gt;&lt;br&gt;&amp;gt; Well in the end your approach is still very interesting as a &amp;nbsp;
&lt;br&gt;&amp;gt; framework for continous erlang VM innovations...
&lt;br&gt;&amp;gt;
&lt;br&gt;Thanks.
&lt;br&gt;&lt;br&gt;&amp;gt; but please correct me if im wrong but I saw that memory carriers &amp;nbsp;
&lt;br&gt;&amp;gt; allowed to set several options on erlang VM start-up so,
&lt;br&gt;&amp;gt;
&lt;br&gt;I am not sure what you mean here?
&lt;br&gt;&lt;br&gt;/Tony
&lt;br&gt;&lt;br&gt;&amp;gt; is stil posible to pacth those carriers to allow a safe memory &amp;nbsp;
&lt;br&gt;&amp;gt; reservation to let de VM manage properly a memory full
&lt;br&gt;&amp;gt; condition by killing the offending process (sort of a OOM killer for &amp;nbsp;
&lt;br&gt;&amp;gt; the VM)?
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; Just telling the VM not to &amp;quot;kill system process&amp;quot; and let the &amp;nbsp;
&lt;br&gt;&amp;gt; supervisors do the work...
&lt;br&gt;&amp;gt;
&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;div class='shrinkable-quote'&gt;&lt;br&gt;&amp;gt; /Angel
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; El Lunes, 9 de Noviembre de 2009 Tony Rogvall escribió:
&lt;br&gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt; It is still the same &amp;quot;let it crash&amp;quot; concept using the resource limit
&lt;br&gt;&amp;gt;&amp;gt; system I am designing.
&lt;br&gt;&amp;gt;&amp;gt; But you can limit the crash in a more controlled way. Also you will &amp;nbsp;
&lt;br&gt;&amp;gt;&amp;gt; be
&lt;br&gt;&amp;gt;&amp;gt; able to report
&lt;br&gt;&amp;gt;&amp;gt; interesting information about what is crashing and when.
&lt;br&gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt; There is sometimes an issue when big systems crash. The restart may
&lt;br&gt;&amp;gt;&amp;gt; take a lot of time.
&lt;br&gt;&amp;gt;&amp;gt; Nodes must be synchronised, database tables must be repaired etc etc.
&lt;br&gt;&amp;gt;&amp;gt; I guess you can design this to be light and easy, but it is not &amp;nbsp;
&lt;br&gt;&amp;gt;&amp;gt; always
&lt;br&gt;&amp;gt;&amp;gt; the case.
&lt;br&gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt; /Tony
&lt;br&gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt; On 9 nov 2009, at 12.43, Angel Alvarez wrote:
&lt;br&gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; Well please let me say something
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; I'm plain new but some things are pretty clear for me.
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; The beauty of the erlang concept is &amp;quot;let it crash&amp;quot; , &amp;quot;don't program
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; defensively&amp;quot;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; so the VM and the underlaying hardware are entities that can fail,
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; that's it.
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; What's the problem so?
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; Joe said...
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; If you want failure tolerance you need at least two nodes...
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; From J.A thesis
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; &amp;nbsp;&amp;quot; ...Schneider [60, 59] answered this question by giving three
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; properties
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; that he thought a hardware system should have in order to be
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; suitable for
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; programming a fault-tolerant system. These properties Schneider
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; called:...&amp;quot;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; 1. Halt on failure — in the event of an error a processor should &amp;nbsp;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; halt
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; &amp;nbsp; &amp;nbsp; instead of performing a possibly erroneous operation.2
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; So on memory exhaustation the VM has to die and other node (erlang)
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; will do the recovery.
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; that's the distrirbution role, no only to span computations over
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; several nodes to enhance performance
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; but to provide resilence in the presence of fatal errors (non
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; correctable).
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; As a OS process the VM has to compete with other OS processes so in
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; a shared deployment (a VM running
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; on a server or a desktop) you cant be safe agaisnt a OOM trigered by
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; other entities.
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; Such resource control thing wil only augment process overhead and
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; context switching in the VM.
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; People new to erlang will be atracted to this hierarquical
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; decomposition of tasks as joe stated in his thesis
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; &amp;quot;If you cant run certaing task try doing something simpler&amp;quot;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; Many languages and VM's are incorporating erlang's good &amp;quot;multicore&amp;quot;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; features but not the erlang powerfull error handling concept
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; and you guys want to kill the simpliticy incorporating many
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; defensive capabilities to avoid fatality instead of just organize
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; code to
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; handle such fatality.
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; ¿whats next?, &amp;nbsp;¿A mailbox maximum message queue control?
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; Well, that's all i have to say about that, Forrest Gump.
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; El Lunes, 9 de Noviembre de 2009 09:45:10 Tony Rogvall escribió:
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; Interesting discussion!
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; I have been working on a resource system for Erlang for nearly two
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; years now.
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; I have a working (tm) prototype where you can set resource limits
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; like
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; max_processes/max_ports/max_memory/max_time/max_reductions ...
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; The limits are passed with spawn_opt and are inherited by the
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; processes spawned.
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; This means that if you spawn_opt(M,F,A[{max_memory, 1024*1024}]) &amp;nbsp;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; the
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; process
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; will be able to use 1M words for it self and it's &amp;quot;subprocesses&amp;quot;.
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; This
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; also means
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; that the spawner will get 1M less to use (as designed right now).
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; If a
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; resource limit
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; is reached the process crash with system_limt reason.
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; There are still some details to work out before a release, but I &amp;nbsp;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; will
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; try to get it ready before
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; end of this year.
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; /Tony
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; On 9 nov 2009, at 09.16, Robert Virding wrote:
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; No.
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; There is a major difference between handling OOM in an OS and in &amp;nbsp;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; the
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; BEAM.
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; In an OS it usually at a per process level that memory runs out so
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; it is
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; easy to decide which process to kill so that the OS can &amp;nbsp;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; continue. In
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; the
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; BEAM, however, it is the VM as a whole which has run out of memory
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; not a
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; specific, it is. therefore, much more difficult to work out which
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; process is
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; the culprit and to decide what to do. For example it might be that
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; the
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; process which causes the OOM is not the actual problem process, it
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; might
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; just the last straw. Or the actual cause may that the whole app
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; might be
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; generating large binaries too quickly. Or it might be that the &amp;nbsp;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; whole
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; app is
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; spawning to many processes without any one process being the &amp;nbsp;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; cause.
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; Or ...
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; In all these cases killing the process which triggered the OOM &amp;nbsp;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; would
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; be the
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; Wrong Thing. We found that it was difficult to work out a &amp;nbsp;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; reasonable
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; strategy to handle the actual cause so we decided not handle it.
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; &amp;quot;Don't catch an error which you can't handle&amp;quot; as the bard put it.
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; Robert
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; 2009/11/9 Max Lapshin &amp;lt;&lt;a href=&quot;http://old.nabble.com/user/SendEmail.jtp?type=post&amp;post=26267513&amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;max.lapshin@...&lt;/a&gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; Yes, there are techniques to write watchdogs, but my question
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; was: is
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; it possible to prevent Erlang VM from crash?
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; ________________________________________________________________
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; erlang-questions (at) erlang.org
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; ________________________________________________________________
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; erlang-questions (at) erlang.org
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; Este correo no tiene dibujos. Las formas extrañas en la pantalla son
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; letras.
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; __________________________________________
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; Clist UAH a.k.a Angel
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; __________________________________________
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; Warning: Microsoft_bribery.ISO contains OOXML code.
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; ________________________________________________________________
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; erlang-questions (at) erlang.org
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; -- 
&lt;br&gt;&amp;gt; No imprima este correo si no es necesario. El medio ambiente está en &amp;nbsp;
&lt;br&gt;&amp;gt; nuestras manos.
&lt;br&gt;&amp;gt; __________________________________________
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; Clist UAH a.k.a Angel
&lt;br&gt;&amp;gt; __________________________________________
&lt;br&gt;&amp;gt; China 'limpia' el Tibet para las Olimpiadas.
&lt;/div&gt;&lt;br&gt;&lt;br&gt;________________________________________________________________
&lt;br&gt;erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;erlang-questions (at) erlang.org
&lt;br&gt;&lt;br&gt;&lt;p&gt;From forum: &lt;a href=&quot;http://old.nabble.com/Erlang-Questions-f14096.html&quot; embed=&quot;fixTarget[14096]&quot; target=&quot;_top&quot; &gt;Erlang Questions&lt;/a&gt;&lt;/p&gt;</content>
	<link rel="alternate" type="text/html" href="http://old.nabble.com/Why-Beam.smp-crashes-when-memory-is-over--tp26257892p26267513.html" />
</entry>

<entry>
	<id>tag:old.nabble.com,2006:post-26266807</id>
	<title>Re: Why Beam.smp crashes when memory is over?</title>
	<published>2009-11-09T05:54:10Z</published>
	<updated>2009-11-09T05:54:10Z</updated>
	<author>
		<name>Angel Alvarez</name>
	</author>
	<content type="html">Well still there are many issues with this new approach
&lt;br&gt;&lt;br&gt;Where are the maibox of processes located? 
&lt;br&gt;&lt;br&gt;With a heap pre process...
&lt;br&gt;&lt;br&gt;&amp;nbsp;Couldnt you trigger a memory exception on a remote process by just sending one message
&lt;br&gt;when the process is almost consuming its reserved memory?
&lt;br&gt;&lt;br&gt;Systems other than embedded erlangs deploy ( form de current erlang movement as a server/desktop plataform)
&lt;br&gt;will suffer from resource contention beetween erlang VM and other OS processes. 
&lt;br&gt;&lt;br&gt;Port programs also need system resources...
&lt;br&gt;&lt;br&gt;Well in the end your approach is still very interesting as a framework for continous erlang VM innovations...
&lt;br&gt;&lt;br&gt;but please correct me if im wrong but I saw that memory carriers allowed to set several options on erlang VM start-up so, 
&lt;br&gt;&lt;br&gt;is stil posible to pacth those carriers to allow a safe memory reservation to let de VM manage properly a memory full 
&lt;br&gt;condition by killing the offending process (sort of a OOM killer for the VM)?
&lt;br&gt;&lt;br&gt;Just telling the VM not to &amp;quot;kill system process&amp;quot; and let the supervisors do the work...
&lt;br&gt;&lt;br&gt;/Angel
&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;El Lunes, 9 de Noviembre de 2009 Tony Rogvall escribió:
&lt;div class='shrinkable-quote'&gt;&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; It is still the same &amp;quot;let it crash&amp;quot; concept using the resource limit &amp;nbsp;
&lt;br&gt;&amp;gt; system I am designing.
&lt;br&gt;&amp;gt; But you can limit the crash in a more controlled way. Also you will be &amp;nbsp;
&lt;br&gt;&amp;gt; able to report
&lt;br&gt;&amp;gt; interesting information about what is crashing and when.
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; There is sometimes an issue when big systems crash. The restart may &amp;nbsp;
&lt;br&gt;&amp;gt; take a lot of time.
&lt;br&gt;&amp;gt; Nodes must be synchronised, database tables must be repaired etc etc.
&lt;br&gt;&amp;gt; I guess you can design this to be light and easy, but it is not always &amp;nbsp;
&lt;br&gt;&amp;gt; the case.
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; /Tony
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; On 9 nov 2009, at 12.43, Angel Alvarez wrote:
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt; Well please let me say something
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt; I'm plain new but some things are pretty clear for me.
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt; The beauty of the erlang concept is &amp;quot;let it crash&amp;quot; , &amp;quot;don't program &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt; defensively&amp;quot;
&lt;br&gt;&amp;gt; &amp;gt; so the VM and the underlaying hardware are entities that can fail, &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt; that's it.
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt; What's the problem so?
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt; Joe said...
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt; If you want failure tolerance you need at least two nodes...
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt; From J.A thesis
&lt;br&gt;&amp;gt; &amp;gt; &amp;nbsp; &amp;quot; ...Schneider [60, 59] answered this question by giving three &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt; properties
&lt;br&gt;&amp;gt; &amp;gt; that he thought a hardware system should have in order to be &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt; suitable for
&lt;br&gt;&amp;gt; &amp;gt; programming a fault-tolerant system. These properties Schneider &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt; called:...&amp;quot;
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt; 1. Halt on failure — in the event of an error a processor should halt
&lt;br&gt;&amp;gt; &amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;instead of performing a possibly erroneous operation.2
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt; So on memory exhaustation the VM has to die and other node (erlang) &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt; will do the recovery.
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt; that's the distrirbution role, no only to span computations over &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt; several nodes to enhance performance
&lt;br&gt;&amp;gt; &amp;gt; but to provide resilence in the presence of fatal errors (non &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt; correctable).
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt; As a OS process the VM has to compete with other OS processes so in &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt; a shared deployment (a VM running
&lt;br&gt;&amp;gt; &amp;gt; on a server or a desktop) you cant be safe agaisnt a OOM trigered by &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt; other entities.
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt; Such resource control thing wil only augment process overhead and &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt; context switching in the VM.
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt; People new to erlang will be atracted to this hierarquical &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt; decomposition of tasks as joe stated in his thesis
&lt;br&gt;&amp;gt; &amp;gt; &amp;quot;If you cant run certaing task try doing something simpler&amp;quot;
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt; Many languages and VM's are incorporating erlang's good &amp;quot;multicore&amp;quot; &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt; features but not the erlang powerfull error handling concept
&lt;br&gt;&amp;gt; &amp;gt; and you guys want to kill the simpliticy incorporating many &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt; defensive capabilities to avoid fatality instead of just organize &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt; code to
&lt;br&gt;&amp;gt; &amp;gt; handle such fatality.
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt; ¿whats next?, &amp;nbsp;¿A mailbox maximum message queue control?
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt; Well, that's all i have to say about that, Forrest Gump.
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt; El Lunes, 9 de Noviembre de 2009 09:45:10 Tony Rogvall escribió:
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; Interesting discussion!
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; I have been working on a resource system for Erlang for nearly two
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; years now.
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; I have a working (tm) prototype where you can set resource limits &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; like
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; max_processes/max_ports/max_memory/max_time/max_reductions ...
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; The limits are passed with spawn_opt and are inherited by the
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; processes spawned.
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; This means that if you spawn_opt(M,F,A[{max_memory, 1024*1024}]) the
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; process
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; will be able to use 1M words for it self and it's &amp;quot;subprocesses&amp;quot;. &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; This
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; also means
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; that the spawner will get 1M less to use (as designed right now). &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; If a
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; resource limit
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; is reached the process crash with system_limt reason.
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; There are still some details to work out before a release, but I will
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; try to get it ready before
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; end of this year.
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; /Tony
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; On 9 nov 2009, at 09.16, Robert Virding wrote:
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; No.
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; There is a major difference between handling OOM in an OS and in the
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; BEAM.
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; In an OS it usually at a per process level that memory runs out so
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; it is
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; easy to decide which process to kill so that the OS can continue. In
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; the
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; BEAM, however, it is the VM as a whole which has run out of memory
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; not a
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; specific, it is. therefore, much more difficult to work out which
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; process is
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; the culprit and to decide what to do. For example it might be that &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; the
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; process which causes the OOM is not the actual problem process, it
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; might
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; just the last straw. Or the actual cause may that the whole app
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; might be
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; generating large binaries too quickly. Or it might be that the whole
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; app is
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; spawning to many processes without any one process being the cause.
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; Or ...
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; In all these cases killing the process which triggered the OOM would
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; be the
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; Wrong Thing. We found that it was difficult to work out a reasonable
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; strategy to handle the actual cause so we decided not handle it.
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; &amp;quot;Don't catch an error which you can't handle&amp;quot; as the bard put it.
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; Robert
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; 2009/11/9 Max Lapshin &amp;lt;&lt;a href=&quot;http://old.nabble.com/user/SendEmail.jtp?type=post&amp;post=26266807&amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;max.lapshin@...&lt;/a&gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt; Yes, there are techniques to write watchdogs, but my question &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt; was: is
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt; it possible to prevent Erlang VM from crash?
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt; ________________________________________________________________
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt; erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt; erlang-questions (at) erlang.org
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; ________________________________________________________________
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; erlang-questions (at) erlang.org
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt; Este correo no tiene dibujos. Las formas extrañas en la pantalla son &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt; letras.
&lt;br&gt;&amp;gt; &amp;gt; __________________________________________
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt; Clist UAH a.k.a Angel
&lt;br&gt;&amp;gt; &amp;gt; __________________________________________
&lt;br&gt;&amp;gt; &amp;gt; Warning: Microsoft_bribery.ISO contains OOXML code.
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt; ________________________________________________________________
&lt;br&gt;&amp;gt; &amp;gt; erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;&amp;gt; &amp;gt; erlang-questions (at) erlang.org
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; 
&lt;/div&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;-- 
&lt;br&gt;No imprima este correo si no es necesario. El medio ambiente está en nuestras manos.
&lt;br&gt;__________________________________________
&lt;br&gt;&lt;br&gt;Clist UAH a.k.a Angel
&lt;br&gt;__________________________________________
&lt;br&gt;China 'limpia' el Tibet para las Olimpiadas.
&lt;br&gt;&lt;br&gt;________________________________________________________________
&lt;br&gt;erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;erlang-questions (at) erlang.org
&lt;br&gt;&lt;br&gt;&lt;p&gt;From forum: &lt;a href=&quot;http://old.nabble.com/Erlang-Questions-f14096.html&quot; embed=&quot;fixTarget[14096]&quot; target=&quot;_top&quot; &gt;Erlang Questions&lt;/a&gt;&lt;/p&gt;</content>
	<link rel="alternate" type="text/html" href="http://old.nabble.com/Why-Beam.smp-crashes-when-memory-is-over--tp26257892p26266807.html" />
</entry>

<entry>
	<id>tag:old.nabble.com,2006:post-26267321</id>
	<title>Re: Why Beam.smp crashes when memory is over?</title>
	<published>2009-11-09T05:25:09Z</published>
	<updated>2009-11-09T05:25:09Z</updated>
	<author>
		<name>Thomas Lindgren</name>
	</author>
	<content type="html">&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;----- Original Message ----
&lt;div class='shrinkable-quote'&gt;&lt;br&gt;&amp;gt; From: Andrew Thompson &amp;lt;&lt;a href=&quot;http://old.nabble.com/user/SendEmail.jtp?type=post&amp;post=26267321&amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;andrew@...&lt;/a&gt;&amp;gt;
&lt;br&gt;&amp;gt; ... it'd be nice to have an
&lt;br&gt;&amp;gt; alternative in cases where nuking the VM and having to recover or simply
&lt;br&gt;&amp;gt; discard a lot of state is unpleasant.
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; In an ideal world I'd like to see an *optional* OOM behaviour similar to
&lt;br&gt;&amp;gt; the following:
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; On startup, the VM pre-allocates enough memory to be able to attempt OOM
&lt;br&gt;&amp;gt; recovery without additional malloc calls. If and when an OOM condition
&lt;br&gt;&amp;gt; is detected, freeze the VM, iterate the process list and simply
&lt;br&gt;&amp;gt; exit(FatPid, oom) the process with the most memory allocated (obviously
&lt;br&gt;&amp;gt; this strategy is full of holes, epecially with regard to off-heap
&lt;br&gt;&amp;gt; binaries), but *sometimes* it's better than just blowing away the whole
&lt;br&gt;&amp;gt; thing. Then, if the malloc fails again, revert to the current behaviour.
&lt;/div&gt;&lt;br&gt;&lt;br&gt;Another way of doing that might be to hand the decision to (a modified version of) the supervisor hierarchy (if any). The supervisor could get info on sibling priority (if any) and/or memory usage as part of the request perhaps. Restart up the supervisor hierarchy to suit. That might give more structure to the restarting.
&lt;br&gt;&lt;br&gt;Or you could do the OOM-killing in distributed erlang + unix instead. Run the buggy, memory-hungry stuff in a separate VM with a memory limit on the process, and manage the work from a &amp;quot;supervisor VM&amp;quot; using monitoring and rpc. Not quite as elegant, of course.
&lt;br&gt;&lt;br&gt;Best,
&lt;br&gt;Thomas
&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 
&lt;br&gt;&lt;br&gt;________________________________________________________________
&lt;br&gt;erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;erlang-questions (at) erlang.org
&lt;br&gt;&lt;br&gt;&lt;p&gt;From forum: &lt;a href=&quot;http://old.nabble.com/Erlang-Questions-f14096.html&quot; embed=&quot;fixTarget[14096]&quot; target=&quot;_top&quot; &gt;Erlang Questions&lt;/a&gt;&lt;/p&gt;</content>
	<link rel="alternate" type="text/html" href="http://old.nabble.com/Why-Beam.smp-crashes-when-memory-is-over--tp26257892p26267321.html" />
</entry>

<entry>
	<id>tag:old.nabble.com,2006:post-26266198</id>
	<title>Re: Why Beam.smp crashes when memory is over?</title>
	<published>2009-11-09T05:11:34Z</published>
	<updated>2009-11-09T05:11:34Z</updated>
	<author>
		<name>Tony Rogvall-2</name>
	</author>
	<content type="html">&lt;br&gt;It is still the same &amp;quot;let it crash&amp;quot; concept using the resource limit &amp;nbsp;
&lt;br&gt;system I am designing.
&lt;br&gt;But you can limit the crash in a more controlled way. Also you will be &amp;nbsp;
&lt;br&gt;able to report
&lt;br&gt;interesting information about what is crashing and when.
&lt;br&gt;&lt;br&gt;There is sometimes an issue when big systems crash. The restart may &amp;nbsp;
&lt;br&gt;take a lot of time.
&lt;br&gt;Nodes must be synchronised, database tables must be repaired etc etc.
&lt;br&gt;I guess you can design this to be light and easy, but it is not always &amp;nbsp;
&lt;br&gt;the case.
&lt;br&gt;&lt;br&gt;/Tony
&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;On 9 nov 2009, at 12.43, Angel Alvarez wrote:
&lt;br&gt;&lt;div class='shrinkable-quote'&gt;&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; Well please let me say something
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; I'm plain new but some things are pretty clear for me.
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; The beauty of the erlang concept is &amp;quot;let it crash&amp;quot; , &amp;quot;don't program &amp;nbsp;
&lt;br&gt;&amp;gt; defensively&amp;quot;
&lt;br&gt;&amp;gt; so the VM and the underlaying hardware are entities that can fail, &amp;nbsp;
&lt;br&gt;&amp;gt; that's it.
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; What's the problem so?
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; Joe said...
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; If you want failure tolerance you need at least two nodes...
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; From J.A thesis
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;quot; ...Schneider [60, 59] answered this question by giving three &amp;nbsp;
&lt;br&gt;&amp;gt; properties
&lt;br&gt;&amp;gt; that he thought a hardware system should have in order to be &amp;nbsp;
&lt;br&gt;&amp;gt; suitable for
&lt;br&gt;&amp;gt; programming a fault-tolerant system. These properties Schneider &amp;nbsp;
&lt;br&gt;&amp;gt; called:...&amp;quot;
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; 1. Halt on failure — in the event of an error a processor should halt
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;instead of performing a possibly erroneous operation.2
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; So on memory exhaustation the VM has to die and other node (erlang) &amp;nbsp;
&lt;br&gt;&amp;gt; will do the recovery.
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; that's the distrirbution role, no only to span computations over &amp;nbsp;
&lt;br&gt;&amp;gt; several nodes to enhance performance
&lt;br&gt;&amp;gt; but to provide resilence in the presence of fatal errors (non &amp;nbsp;
&lt;br&gt;&amp;gt; correctable).
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; As a OS process the VM has to compete with other OS processes so in &amp;nbsp;
&lt;br&gt;&amp;gt; a shared deployment (a VM running
&lt;br&gt;&amp;gt; on a server or a desktop) you cant be safe agaisnt a OOM trigered by &amp;nbsp;
&lt;br&gt;&amp;gt; other entities.
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; Such resource control thing wil only augment process overhead and &amp;nbsp;
&lt;br&gt;&amp;gt; context switching in the VM.
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; People new to erlang will be atracted to this hierarquical &amp;nbsp;
&lt;br&gt;&amp;gt; decomposition of tasks as joe stated in his thesis
&lt;br&gt;&amp;gt; &amp;quot;If you cant run certaing task try doing something simpler&amp;quot;
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; Many languages and VM's are incorporating erlang's good &amp;quot;multicore&amp;quot; &amp;nbsp;
&lt;br&gt;&amp;gt; features but not the erlang powerfull error handling concept
&lt;br&gt;&amp;gt; and you guys want to kill the simpliticy incorporating many &amp;nbsp;
&lt;br&gt;&amp;gt; defensive capabilities to avoid fatality instead of just organize &amp;nbsp;
&lt;br&gt;&amp;gt; code to
&lt;br&gt;&amp;gt; handle such fatality.
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; ¿whats next?, &amp;nbsp;¿A mailbox maximum message queue control?
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; Well, that's all i have to say about that, Forrest Gump.
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; El Lunes, 9 de Noviembre de 2009 09:45:10 Tony Rogvall escribió:
&lt;br&gt;&amp;gt;&amp;gt; Interesting discussion!
&lt;br&gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt; I have been working on a resource system for Erlang for nearly two
&lt;br&gt;&amp;gt;&amp;gt; years now.
&lt;br&gt;&amp;gt;&amp;gt; I have a working (tm) prototype where you can set resource limits &amp;nbsp;
&lt;br&gt;&amp;gt;&amp;gt; like
&lt;br&gt;&amp;gt;&amp;gt; max_processes/max_ports/max_memory/max_time/max_reductions ...
&lt;br&gt;&amp;gt;&amp;gt; The limits are passed with spawn_opt and are inherited by the
&lt;br&gt;&amp;gt;&amp;gt; processes spawned.
&lt;br&gt;&amp;gt;&amp;gt; This means that if you spawn_opt(M,F,A[{max_memory, 1024*1024}]) the
&lt;br&gt;&amp;gt;&amp;gt; process
&lt;br&gt;&amp;gt;&amp;gt; will be able to use 1M words for it self and it's &amp;quot;subprocesses&amp;quot;. &amp;nbsp;
&lt;br&gt;&amp;gt;&amp;gt; This
&lt;br&gt;&amp;gt;&amp;gt; also means
&lt;br&gt;&amp;gt;&amp;gt; that the spawner will get 1M less to use (as designed right now). &amp;nbsp;
&lt;br&gt;&amp;gt;&amp;gt; If a
&lt;br&gt;&amp;gt;&amp;gt; resource limit
&lt;br&gt;&amp;gt;&amp;gt; is reached the process crash with system_limt reason.
&lt;br&gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt; There are still some details to work out before a release, but I will
&lt;br&gt;&amp;gt;&amp;gt; try to get it ready before
&lt;br&gt;&amp;gt;&amp;gt; end of this year.
&lt;br&gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt; /Tony
&lt;br&gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt; On 9 nov 2009, at 09.16, Robert Virding wrote:
&lt;br&gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; No.
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; There is a major difference between handling OOM in an OS and in the
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; BEAM.
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; In an OS it usually at a per process level that memory runs out so
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; it is
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; easy to decide which process to kill so that the OS can continue. In
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; the
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; BEAM, however, it is the VM as a whole which has run out of memory
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; not a
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; specific, it is. therefore, much more difficult to work out which
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; process is
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; the culprit and to decide what to do. For example it might be that &amp;nbsp;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; the
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; process which causes the OOM is not the actual problem process, it
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; might
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; just the last straw. Or the actual cause may that the whole app
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; might be
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; generating large binaries too quickly. Or it might be that the whole
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; app is
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; spawning to many processes without any one process being the cause.
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; Or ...
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; In all these cases killing the process which triggered the OOM would
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; be the
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; Wrong Thing. We found that it was difficult to work out a reasonable
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; strategy to handle the actual cause so we decided not handle it.
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; &amp;quot;Don't catch an error which you can't handle&amp;quot; as the bard put it.
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; Robert
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; 2009/11/9 Max Lapshin &amp;lt;&lt;a href=&quot;http://old.nabble.com/user/SendEmail.jtp?type=post&amp;post=26266198&amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;max.lapshin@...&lt;/a&gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; Yes, there are techniques to write watchdogs, but my question &amp;nbsp;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; was: is
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; it possible to prevent Erlang VM from crash?
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; ________________________________________________________________
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; erlang-questions (at) erlang.org
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt; ________________________________________________________________
&lt;br&gt;&amp;gt;&amp;gt; erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;&amp;gt;&amp;gt; erlang-questions (at) erlang.org
&lt;br&gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; Este correo no tiene dibujos. Las formas extrañas en la pantalla son &amp;nbsp;
&lt;br&gt;&amp;gt; letras.
&lt;br&gt;&amp;gt; __________________________________________
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; Clist UAH a.k.a Angel
&lt;br&gt;&amp;gt; __________________________________________
&lt;br&gt;&amp;gt; Warning: Microsoft_bribery.ISO contains OOXML code.
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; ________________________________________________________________
&lt;br&gt;&amp;gt; erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;&amp;gt; erlang-questions (at) erlang.org
&lt;br&gt;&amp;gt;
&lt;/div&gt;&lt;br&gt;&lt;br&gt;________________________________________________________________
&lt;br&gt;erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;erlang-questions (at) erlang.org
&lt;br&gt;&lt;br&gt;&lt;p&gt;From forum: &lt;a href=&quot;http://old.nabble.com/Erlang-Questions-f14096.html&quot; embed=&quot;fixTarget[14096]&quot; target=&quot;_top&quot; &gt;Erlang Questions&lt;/a&gt;&lt;/p&gt;</content>
	<link rel="alternate" type="text/html" href="http://old.nabble.com/Why-Beam.smp-crashes-when-memory-is-over--tp26257892p26266198.html" />
</entry>

<entry>
	<id>tag:old.nabble.com,2006:post-26265010</id>
	<title>Re: Why Beam.smp crashes when memory is over?</title>
	<published>2009-11-09T03:43:02Z</published>
	<updated>2009-11-09T03:43:02Z</updated>
	<author>
		<name>Angel Alvarez</name>
	</author>
	<content type="html">&lt;br&gt;Well please let me say something
&lt;br&gt;&lt;br&gt;I'm plain new but some things are pretty clear for me.
&lt;br&gt;&lt;br&gt;&lt;br&gt;The beauty of the erlang concept is &amp;quot;let it crash&amp;quot; , &amp;quot;don't program defensively&amp;quot;
&lt;br&gt;so the VM and the underlaying hardware are entities that can fail, that's it.
&lt;br&gt;&lt;br&gt;What's the problem so?
&lt;br&gt;&lt;br&gt;Joe said...
&lt;br&gt;&lt;br&gt;If you want failure tolerance you need at least two nodes...
&lt;br&gt;&lt;br&gt;From J.A thesis
&lt;br&gt;&amp;nbsp; &amp;nbsp;&amp;quot; ...Schneider [60, 59] answered this question by giving three properties
&lt;br&gt;that he thought a hardware system should have in order to be suitable for
&lt;br&gt;programming a fault-tolerant system. These properties Schneider called:...&amp;quot;
&lt;br&gt;&amp;nbsp; &amp;nbsp;
&lt;br&gt;1. Halt on failure — in the event of an error a processor should halt
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; instead of performing a possibly erroneous operation.2
&lt;br&gt;&lt;br&gt;So on memory exhaustation the VM has to die and other node (erlang) will do the recovery.
&lt;br&gt;&lt;br&gt;that's the distrirbution role, no only to span computations over several nodes to enhance performance
&lt;br&gt;but to provide resilence in the presence of fatal errors (non correctable).
&lt;br&gt;&lt;br&gt;As a OS process the VM has to compete with other OS processes so in a shared deployment (a VM running 
&lt;br&gt;on a server or a desktop) you cant be safe agaisnt a OOM trigered by other entities.
&lt;br&gt;&lt;br&gt;Such resource control thing wil only augment process overhead and context switching in the VM.
&lt;br&gt;&lt;br&gt;People new to erlang will be atracted to this hierarquical decomposition of tasks as joe stated in his thesis
&lt;br&gt;&amp;quot;If you cant run certaing task try doing something simpler&amp;quot;
&lt;br&gt;&lt;br&gt;Many languages and VM's are incorporating erlang's good &amp;quot;multicore&amp;quot; features but not the erlang powerfull error handling concept
&lt;br&gt;and you guys want to kill the simpliticy incorporating many defensive capabilities to avoid fatality instead of just organize code to 
&lt;br&gt;handle such fatality.
&lt;br&gt;&lt;br&gt;¿whats next?, &amp;nbsp;¿A mailbox maximum message queue control?
&lt;br&gt;&lt;br&gt;&lt;br&gt;Well, that's all i have to say about that, Forrest Gump.
&lt;br&gt;&lt;br&gt;&lt;br&gt;El Lunes, 9 de Noviembre de 2009 09:45:10 Tony Rogvall escribió:
&lt;div class='shrinkable-quote'&gt;&lt;br&gt;&amp;gt; Interesting discussion!
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; I have been working on a resource system for Erlang for nearly two &amp;nbsp;
&lt;br&gt;&amp;gt; years now.
&lt;br&gt;&amp;gt; I have a working (tm) prototype where you can set resource limits like
&lt;br&gt;&amp;gt; max_processes/max_ports/max_memory/max_time/max_reductions ...
&lt;br&gt;&amp;gt; The limits are passed with spawn_opt and are inherited by the &amp;nbsp;
&lt;br&gt;&amp;gt; processes spawned.
&lt;br&gt;&amp;gt; This means that if you spawn_opt(M,F,A[{max_memory, 1024*1024}]) the &amp;nbsp;
&lt;br&gt;&amp;gt; process
&lt;br&gt;&amp;gt; will be able to use 1M words for it self and it's &amp;quot;subprocesses&amp;quot;. This &amp;nbsp;
&lt;br&gt;&amp;gt; also means
&lt;br&gt;&amp;gt; that the spawner will get 1M less to use (as designed right now). If a &amp;nbsp;
&lt;br&gt;&amp;gt; resource limit
&lt;br&gt;&amp;gt; is reached the process crash with system_limt reason.
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; There are still some details to work out before a release, but I will &amp;nbsp;
&lt;br&gt;&amp;gt; try to get it ready before
&lt;br&gt;&amp;gt; end of this year.
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; /Tony
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; On 9 nov 2009, at 09.16, Robert Virding wrote:
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; &amp;gt; No.
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt; There is a major difference between handling OOM in an OS and in the &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt; BEAM.
&lt;br&gt;&amp;gt; &amp;gt; In an OS it usually at a per process level that memory runs out so &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt; it is
&lt;br&gt;&amp;gt; &amp;gt; easy to decide which process to kill so that the OS can continue. In &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt; the
&lt;br&gt;&amp;gt; &amp;gt; BEAM, however, it is the VM as a whole which has run out of memory &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt; not a
&lt;br&gt;&amp;gt; &amp;gt; specific, it is. therefore, much more difficult to work out which &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt; process is
&lt;br&gt;&amp;gt; &amp;gt; the culprit and to decide what to do. For example it might be that the
&lt;br&gt;&amp;gt; &amp;gt; process which causes the OOM is not the actual problem process, it &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt; might
&lt;br&gt;&amp;gt; &amp;gt; just the last straw. Or the actual cause may that the whole app &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt; might be
&lt;br&gt;&amp;gt; &amp;gt; generating large binaries too quickly. Or it might be that the whole &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt; app is
&lt;br&gt;&amp;gt; &amp;gt; spawning to many processes without any one process being the cause. &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt; Or ...
&lt;br&gt;&amp;gt; &amp;gt; In all these cases killing the process which triggered the OOM would &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt; be the
&lt;br&gt;&amp;gt; &amp;gt; Wrong Thing. We found that it was difficult to work out a reasonable
&lt;br&gt;&amp;gt; &amp;gt; strategy to handle the actual cause so we decided not handle it.
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt; &amp;quot;Don't catch an error which you can't handle&amp;quot; as the bard put it.
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt; Robert
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt; 2009/11/9 Max Lapshin &amp;lt;&lt;a href=&quot;http://old.nabble.com/user/SendEmail.jtp?type=post&amp;post=26265010&amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;max.lapshin@...&lt;/a&gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; Yes, there are techniques to write watchdogs, but my question was: is
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; it possible to prevent Erlang VM from crash?
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; ________________________________________________________________
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; erlang-questions (at) erlang.org
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; ________________________________________________________________
&lt;br&gt;&amp;gt; erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;&amp;gt; erlang-questions (at) erlang.org
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; 
&lt;/div&gt;&lt;br&gt;&lt;br&gt;Este correo no tiene dibujos. Las formas extrañas en la pantalla son letras.
&lt;br&gt;__________________________________________
&lt;br&gt;&lt;br&gt;Clist UAH a.k.a Angel
&lt;br&gt;__________________________________________
&lt;br&gt;Warning: Microsoft_bribery.ISO contains OOXML code.
&lt;br&gt;&lt;br&gt;________________________________________________________________
&lt;br&gt;erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;erlang-questions (at) erlang.org
&lt;br&gt;&lt;br&gt;&lt;p&gt;From forum: &lt;a href=&quot;http://old.nabble.com/Erlang-Questions-f14096.html&quot; embed=&quot;fixTarget[14096]&quot; target=&quot;_top&quot; &gt;Erlang Questions&lt;/a&gt;&lt;/p&gt;</content>
	<link rel="alternate" type="text/html" href="http://old.nabble.com/Why-Beam.smp-crashes-when-memory-is-over--tp26257892p26265010.html" />
</entry>

<entry>
	<id>tag:old.nabble.com,2006:post-26264924</id>
	<title>Re: Dialyzer problem on OSX 10.6 (Erlang R13B02-1)</title>
	<published>2009-11-09T03:35:18Z</published>
	<updated>2009-11-09T03:35:18Z</updated>
	<author>
		<name>Tamas Nagy-3</name>
	</author>
	<content type="html">Hi Tino,
&lt;br&gt;&lt;br&gt;Are you using homebrew?
&lt;br&gt;&lt;br&gt;So far it seems that homebrew applies some c compiler magic (e.g optimizations) when building erlang which somehow borks dialyzer (strange) as compiling from source with the same ./configure options homebrew uses results in an erlang installation which works like a charm.
&lt;br&gt;&lt;br&gt;Regards,
&lt;br&gt;&amp;nbsp; &amp;nbsp; Tamas
&lt;br&gt;----- &amp;quot;Tino Breddin&amp;quot; &amp;lt;&lt;a href=&quot;http://old.nabble.com/user/SendEmail.jtp?type=post&amp;post=26264924&amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;tino.breddin@...&lt;/a&gt;&amp;gt; wrote:
&lt;br&gt;&lt;div class='shrinkable-quote'&gt;&lt;br&gt;&amp;gt; Hey Tamas,
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; Here's the output for the command run on my machine (Macbook Pro Core 
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; Duo, running OSX 10.6.1 32-bit):
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; dialyzer --build_plt -r /usr/local/Cellar/erlang/R13B02-1/lib/erlang/
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; lib/erts-5.7.3/ebin/ /usr/local/Cellar/erlang/R13B02-1/lib/erlang/lib/
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; kernel-2.13.3/ebin/ /usr/local/Cellar/erlang/R13B02-1/lib/erlang/lib/
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; stdlib-1.16.3/ebin/
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp;Creating PLT /Users/tino/.dialyzer_plt ...
&lt;br&gt;&amp;gt; Unknown functions:
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp;compile:file/2
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp;compile:forms/2
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp;compile:noenv_forms/2
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp;compile:output_generated/1
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp;crypto:des3_cbc_decrypt/5
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp;crypto:start/0
&lt;br&gt;&amp;gt; &amp;nbsp; done in 46m22.52s
&lt;br&gt;&amp;gt; done (passed successfully)
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; Apparently it takes some time to complete but you'll get there.
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; Cheers,
&lt;br&gt;&amp;gt; Tino
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; On Nov 8, 2009, at 11:35 PM, Tamas Nagy wrote:
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; &amp;gt; Hi Kostis,
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt; This is what all I get:
&lt;br&gt;&amp;gt; &amp;gt; $ dialyzer --build_plt -r /usr/local/Cellar/erlang/R13B02-1/lib/ 
&lt;br&gt;&amp;gt; &amp;gt; erlang/lib/erts-5.7.3/ebin/ /usr/local/Cellar/erlang/R13B02-1/lib/ 
&lt;br&gt;&amp;gt; &amp;gt; erlang/lib/kernel-2.13.3/ebin/
&lt;br&gt;&amp;gt; /usr/local/Cellar/erlang/R13B02-1/lib/ 
&lt;br&gt;&amp;gt; &amp;gt; erlang/lib/stdlib-1.16.3/ebin/
&lt;br&gt;&amp;gt; &amp;gt; &amp;nbsp;Creating PLT /Users/lestat/.dialyzer_plt ...
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt; I will try to rebuild erlang with disabling hipe to see if that
&lt;br&gt;&amp;gt; helps.
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt; I am happy to run some tests/traces you would like to see the &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt; results of to help.
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt; Regards,
&lt;br&gt;&amp;gt; &amp;gt; 	Tamas
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt; Tamas Nagy
&lt;br&gt;&amp;gt; &amp;gt; Erlang Training &amp; Consulting
&lt;br&gt;&amp;gt; &amp;gt; &lt;a href=&quot;http://www.erlang-consulting.com&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang-consulting.com&lt;/a&gt;&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt; On 8 Nov 2009, at 19:52, Kostis Sagonas wrote:
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; Tamas Nagy wrote:
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; Hi,
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; Am I the only one who cannot build a plt under OSX 10.6 in &amp;nbsp; 
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; R13B02-1?
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; No matter what applications I specify for the initial plt it just 
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; hangs eating processing power but not producing anything.
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; Erlang was installed with homebrew, but that shouldn't matter. Or 
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; maybe it does. (beam is compiled for 64 bit)
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; Here is the command I used:
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; dialyzer --build_plt -r /usr/local/Cellar/erlang/R13B02-1/lib/ 
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; erlang/lib/erts-5.7.3/ebin/ /usr/local/Cellar/erlang/R13B02-1/lib/
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; erlang/lib/kernel-2.13.3/ebin/ /usr/local/Cellar/erlang/R13B02-1/
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; lib/erlang/lib/stdlib-1.16.3/ebin/
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; I gave waiting for it to finish after ~1 hour (on an old type &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; white MacBook (MacBook2,1) with 2GB of RAM).
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; None of the dialyzer developers has access to such a machine to see
&lt;br&gt;&amp;gt; &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; what's happening. &amp;nbsp;Perhaps somebody else in that list might want to
&lt;br&gt;&amp;gt; &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; report whether this is reproducible or not.
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; However, perhaps the following might help: when building the PLT, 
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; do you see a message:
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; 	Compiling some key modules to native code...
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; If so, can you disable hipe (64-bit Mac is not a platform we have 
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; ever tested due to no access to such a machine) to see whether this
&lt;br&gt;&amp;gt; &amp;nbsp;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; may be the culprit?
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;&amp;gt; Kostis
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt;
&lt;br&gt;&amp;gt; &amp;gt; ________________________________________________________________
&lt;br&gt;&amp;gt; &amp;gt; erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;&amp;gt; &amp;gt; erlang-questions (at) erlang.org
&lt;br&gt;&amp;gt; &amp;gt;
&lt;/div&gt;&lt;br&gt;-- 
&lt;br&gt;Tamas Nagy
&lt;br&gt;Erlang Training &amp; Consulting
&lt;br&gt;&lt;a href=&quot;http://www.erlang-consulting.com&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang-consulting.com&lt;/a&gt;&lt;br&gt;&lt;br&gt;________________________________________________________________
&lt;br&gt;erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;erlang-questions (at) erlang.org
&lt;br&gt;&lt;br&gt;&lt;p&gt;From forum: &lt;a href=&quot;http://old.nabble.com/Erlang-Questions-f14096.html&quot; embed=&quot;fixTarget[14096]&quot; target=&quot;_top&quot; &gt;Erlang Questions&lt;/a&gt;&lt;/p&gt;</content>
	<link rel="alternate" type="text/html" href="http://old.nabble.com/Dialyzer-problem-on-OSX-10.6-%28Erlang-R13B02-1%29-tp26256992p26264924.html" />
</entry>

<entry>
	<id>tag:old.nabble.com,2006:post-26264551</id>
	<title>Re: Why Beam.smp crashes when memory is over?</title>
	<published>2009-11-09T03:05:41Z</published>
	<updated>2009-11-09T03:05:41Z</updated>
	<author>
		<name>Dmitry Belyaev</name>
	</author>
	<content type="html">What if you'll have different nodes for different tasks instead of
&lt;br&gt;processes?
&lt;br&gt;&lt;br&gt;Start one node to read stream and one (or many) other node to process
&lt;br&gt;the stream part.
&lt;br&gt;&lt;br&gt;On Mon, 2009-11-09 at 08:08 +0300, Max Lapshin wrote:
&lt;div class='shrinkable-quote'&gt;&lt;br&gt;&amp;gt; Look, I have a program, that reads MPEG TS stream from network. There
&lt;br&gt;&amp;gt; is some bug in my code
&lt;br&gt;&amp;gt; and my ts_lander crashes beam. How is it possible to store state of
&lt;br&gt;&amp;gt; external HTTP stream??
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; If Erlang VM wouldn't crash, but only kill the leaking process, I
&lt;br&gt;&amp;gt; could buffer stream in other process and feed
&lt;br&gt;&amp;gt; new mpeg ts lander after restart. But it is impossible =(
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; ________________________________________________________________
&lt;br&gt;&amp;gt; erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;&amp;gt; erlang-questions (at) erlang.org
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; 
&lt;/div&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;________________________________________________________________
&lt;br&gt;erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;erlang-questions (at) erlang.org
&lt;br&gt;&lt;br&gt;&lt;p&gt;From forum: &lt;a href=&quot;http://old.nabble.com/Erlang-Questions-f14096.html&quot; embed=&quot;fixTarget[14096]&quot; target=&quot;_top&quot; &gt;Erlang Questions&lt;/a&gt;&lt;/p&gt;</content>
	<link rel="alternate" type="text/html" href="http://old.nabble.com/Why-Beam.smp-crashes-when-memory-is-over--tp26257892p26264551.html" />
</entry>

<entry>
	<id>tag:old.nabble.com,2006:post-26264132</id>
	<title>AW: Why Beam.smp crashes when memory is over?</title>
	<published>2009-11-09T02:31:19Z</published>
	<updated>2009-11-09T02:31:19Z</updated>
	<author>
		<name>Decker, Nils</name>
	</author>
	<content type="html">Hello,
&lt;br&gt;&lt;br&gt;I had a few occasions during developing that a runaway process caused my machine to swap and gind to a halt. (i should have used ulimit on beam)
&lt;br&gt;&lt;br&gt;I wondered why there is no way to limit the size of a single process. It could be a simple option to spawn to limit the heap size of a process. (like ulimit)
&lt;br&gt;The process gets killed if it ever grows beyond the limit. A limit for the size of the message queue would be nice too, because a process with a few thousand entries is (most of the time) not going to cope with it anyway.
&lt;br&gt;A similar limit for ETS tables would be possible too. A memory limit for shared resources (large binaries) would be more difficult.
&lt;br&gt;&lt;br&gt;Nils Decker
&lt;br&gt;________________________________________________________________
&lt;br&gt;erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;erlang-questions (at) erlang.org
&lt;br&gt;&lt;br&gt;&lt;p&gt;From forum: &lt;a href=&quot;http://old.nabble.com/Erlang-Questions-f14096.html&quot; embed=&quot;fixTarget[14096]&quot; target=&quot;_top&quot; &gt;Erlang Questions&lt;/a&gt;&lt;/p&gt;</content>
	<link rel="alternate" type="text/html" href="http://old.nabble.com/Why-Beam.smp-crashes-when-memory-is-over--tp26257892p26264132.html" />
</entry>

<entry>
	<id>tag:old.nabble.com,2006:post-26263677</id>
	<title>Re: Why Beam.smp crashes when memory is over?</title>
	<published>2009-11-09T01:53:10Z</published>
	<updated>2009-11-09T01:53:10Z</updated>
	<author>
		<name>Kenneth Lundin</name>
	</author>
	<content type="html">On Mon, Nov 9, 2009 at 9:16 AM, Robert Virding &amp;lt;&lt;a href=&quot;http://old.nabble.com/user/SendEmail.jtp?type=post&amp;post=26263677&amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;rvirding@...&lt;/a&gt;&amp;gt; wrote:
&lt;div class='shrinkable-quote'&gt;&lt;br&gt;&amp;gt; No.
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; There is a major difference between handling OOM in an OS and in the BEAM.
&lt;br&gt;&amp;gt; In an OS it usually at a per process level that memory runs out so it is
&lt;br&gt;&amp;gt; easy to decide which process to kill so that the OS can continue. In the
&lt;br&gt;&amp;gt; BEAM, however, it is the VM as a whole which has run out of memory not a
&lt;br&gt;&amp;gt; specific, it is. therefore, much more difficult to work out which process is
&lt;br&gt;&amp;gt; the culprit and to decide what to do. For example it might be that the
&lt;br&gt;&amp;gt; process which causes the OOM is not the actual problem process, it might
&lt;br&gt;&amp;gt; just the last straw. Or the actual cause may that the whole app might be
&lt;br&gt;&amp;gt; generating large binaries too quickly. Or it might be that the whole app is
&lt;br&gt;&amp;gt; spawning to many processes without any one process being the cause. Or ...
&lt;br&gt;&amp;gt; In all these cases killing the process which triggered the OOM would be the
&lt;br&gt;&amp;gt; Wrong Thing. We found that it was difficult to work out a reasonable
&lt;br&gt;&amp;gt; strategy to handle the actual cause so we decided not handle it.
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;quot;Don't catch an error which you can't handle&amp;quot; as the bard put it.
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; Robert
&lt;/div&gt;&lt;br&gt;We have discussed this many times and have always come to the same
&lt;br&gt;conclusion as Robert expains above, that we can't know the right thing
&lt;br&gt;to do so we just do nothing and terminate the VM.
&lt;br&gt;&lt;br&gt;What we could do is to make it easier for the user to prevent OOM
&lt;br&gt;situations and also to
&lt;br&gt;let him take the decision when it occurs or rather before it occurs.
&lt;br&gt;&lt;br&gt;One way would be to let the user set a memory quota on a process with
&lt;br&gt;options at spawn time. When the process reaches it quota it can be
&lt;br&gt;automatically killed or the user can
&lt;br&gt;be notified in some way and take actions.
&lt;br&gt;&lt;br&gt;We have also thought about ways for the user to monitor memory consumption and
&lt;br&gt;by this taking actions before the VM runs out of memory.
&lt;br&gt;&lt;br&gt;/Kenneth, Erlang/OTP Ericsson
&lt;br&gt;&lt;br&gt;________________________________________________________________
&lt;br&gt;erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;erlang-questions (at) erlang.org
&lt;br&gt;&lt;br&gt;&lt;p&gt;From forum: &lt;a href=&quot;http://old.nabble.com/Erlang-Questions-f14096.html&quot; embed=&quot;fixTarget[14096]&quot; target=&quot;_top&quot; &gt;Erlang Questions&lt;/a&gt;&lt;/p&gt;</content>
	<link rel="alternate" type="text/html" href="http://old.nabble.com/Why-Beam.smp-crashes-when-memory-is-over--tp26257892p26263677.html" />
</entry>

<entry>
	<id>tag:old.nabble.com,2006:post-26263613</id>
	<title>Re: Why Beam.smp crashes when memory is over?</title>
	<published>2009-11-09T00:45:10Z</published>
	<updated>2009-11-09T00:45:10Z</updated>
	<author>
		<name>Tony Rogvall-2</name>
	</author>
	<content type="html">Interesting discussion!
&lt;br&gt;&lt;br&gt;I have been working on a resource system for Erlang for nearly two &amp;nbsp;
&lt;br&gt;years now.
&lt;br&gt;I have a working (tm) prototype where you can set resource limits like
&lt;br&gt;max_processes/max_ports/max_memory/max_time/max_reductions ...
&lt;br&gt;The limits are passed with spawn_opt and are inherited by the &amp;nbsp;
&lt;br&gt;processes spawned.
&lt;br&gt;This means that if you spawn_opt(M,F,A[{max_memory, 1024*1024}]) the &amp;nbsp;
&lt;br&gt;process
&lt;br&gt;will be able to use 1M words for it self and it's &amp;quot;subprocesses&amp;quot;. This &amp;nbsp;
&lt;br&gt;also means
&lt;br&gt;that the spawner will get 1M less to use (as designed right now). If a &amp;nbsp;
&lt;br&gt;resource limit
&lt;br&gt;is reached the process crash with system_limt reason.
&lt;br&gt;&lt;br&gt;There are still some details to work out before a release, but I will &amp;nbsp;
&lt;br&gt;try to get it ready before
&lt;br&gt;end of this year.
&lt;br&gt;&lt;br&gt;/Tony
&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;On 9 nov 2009, at 09.16, Robert Virding wrote:
&lt;br&gt;&lt;div class='shrinkable-quote'&gt;&lt;br&gt;&amp;gt; No.
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; There is a major difference between handling OOM in an OS and in the &amp;nbsp;
&lt;br&gt;&amp;gt; BEAM.
&lt;br&gt;&amp;gt; In an OS it usually at a per process level that memory runs out so &amp;nbsp;
&lt;br&gt;&amp;gt; it is
&lt;br&gt;&amp;gt; easy to decide which process to kill so that the OS can continue. In &amp;nbsp;
&lt;br&gt;&amp;gt; the
&lt;br&gt;&amp;gt; BEAM, however, it is the VM as a whole which has run out of memory &amp;nbsp;
&lt;br&gt;&amp;gt; not a
&lt;br&gt;&amp;gt; specific, it is. therefore, much more difficult to work out which &amp;nbsp;
&lt;br&gt;&amp;gt; process is
&lt;br&gt;&amp;gt; the culprit and to decide what to do. For example it might be that the
&lt;br&gt;&amp;gt; process which causes the OOM is not the actual problem process, it &amp;nbsp;
&lt;br&gt;&amp;gt; might
&lt;br&gt;&amp;gt; just the last straw. Or the actual cause may that the whole app &amp;nbsp;
&lt;br&gt;&amp;gt; might be
&lt;br&gt;&amp;gt; generating large binaries too quickly. Or it might be that the whole &amp;nbsp;
&lt;br&gt;&amp;gt; app is
&lt;br&gt;&amp;gt; spawning to many processes without any one process being the cause. &amp;nbsp;
&lt;br&gt;&amp;gt; Or ...
&lt;br&gt;&amp;gt; In all these cases killing the process which triggered the OOM would &amp;nbsp;
&lt;br&gt;&amp;gt; be the
&lt;br&gt;&amp;gt; Wrong Thing. We found that it was difficult to work out a reasonable
&lt;br&gt;&amp;gt; strategy to handle the actual cause so we decided not handle it.
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;quot;Don't catch an error which you can't handle&amp;quot; as the bard put it.
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; Robert
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; 2009/11/9 Max Lapshin &amp;lt;&lt;a href=&quot;http://old.nabble.com/user/SendEmail.jtp?type=post&amp;post=26263613&amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;max.lapshin@...&lt;/a&gt;&amp;gt;
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt; Yes, there are techniques to write watchdogs, but my question was: is
&lt;br&gt;&amp;gt;&amp;gt; it possible to prevent Erlang VM from crash?
&lt;br&gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt; ________________________________________________________________
&lt;br&gt;&amp;gt;&amp;gt; erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;&amp;gt;&amp;gt; erlang-questions (at) erlang.org
&lt;br&gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;
&lt;/div&gt;&lt;br&gt;&lt;br&gt;________________________________________________________________
&lt;br&gt;erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;erlang-questions (at) erlang.org
&lt;br&gt;&lt;br&gt;&lt;p&gt;From forum: &lt;a href=&quot;http://old.nabble.com/Erlang-Questions-f14096.html&quot; embed=&quot;fixTarget[14096]&quot; target=&quot;_top&quot; &gt;Erlang Questions&lt;/a&gt;&lt;/p&gt;</content>
	<link rel="alternate" type="text/html" href="http://old.nabble.com/Why-Beam.smp-crashes-when-memory-is-over--tp26257892p26263613.html" />
</entry>

<entry>
	<id>tag:old.nabble.com,2006:post-26262889</id>
	<title>Re: Why Beam.smp crashes when memory is over?</title>
	<published>2009-11-09T00:42:03Z</published>
	<updated>2009-11-09T00:42:03Z</updated>
	<author>
		<name>Robert Virding</name>
	</author>
	<content type="html">That would be a start, it very much depends on your app. I am not really the
&lt;br&gt;right person to ask about details on chasing the culprit, but I do remember
&lt;br&gt;the discussions we had long ago on trying to work out a good solution. Which
&lt;br&gt;we couldn't.
&lt;br&gt;&lt;br&gt;2009/11/9 Max Lapshin &amp;lt;&lt;a href=&quot;http://old.nabble.com/user/SendEmail.jtp?type=post&amp;post=26262889&amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;max.lapshin@...&lt;/a&gt;&amp;gt;
&lt;br&gt;&lt;br&gt;&amp;gt; Ok, so You advice is just to look after memory usage of &amp;quot;dangereous&amp;quot;
&lt;br&gt;&amp;gt; processes?
&lt;br&gt;&amp;gt;
&lt;br&gt;&lt;p&gt;From forum: &lt;a href=&quot;http://old.nabble.com/Erlang-Questions-f14096.html&quot; embed=&quot;fixTarget[14096]&quot; target=&quot;_top&quot; &gt;Erlang Questions&lt;/a&gt;&lt;/p&gt;</content>
	<link rel="alternate" type="text/html" href="http://old.nabble.com/Why-Beam.smp-crashes-when-memory-is-over--tp26257892p26262889.html" />
</entry>

<entry>
	<id>tag:old.nabble.com,2006:post-26262659</id>
	<title>Re: Why Beam.smp crashes when memory is over?</title>
	<published>2009-11-09T00:19:12Z</published>
	<updated>2009-11-09T00:19:12Z</updated>
	<author>
		<name>Max Lapshin-2</name>
	</author>
	<content type="html">Ok, so You advice is just to look after memory usage of &amp;quot;dangereous&amp;quot; processes?
&lt;br&gt;&lt;br&gt;________________________________________________________________
&lt;br&gt;erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;erlang-questions (at) erlang.org
&lt;br&gt;&lt;br&gt;&lt;p&gt;From forum: &lt;a href=&quot;http://old.nabble.com/Erlang-Questions-f14096.html&quot; embed=&quot;fixTarget[14096]&quot; target=&quot;_top&quot; &gt;Erlang Questions&lt;/a&gt;&lt;/p&gt;</content>
	<link rel="alternate" type="text/html" href="http://old.nabble.com/Why-Beam.smp-crashes-when-memory-is-over--tp26257892p26262659.html" />
</entry>

<entry>
	<id>tag:old.nabble.com,2006:post-26262631</id>
	<title>Re: Why Beam.smp crashes when memory is over?</title>
	<published>2009-11-09T00:16:44Z</published>
	<updated>2009-11-09T00:16:44Z</updated>
	<author>
		<name>Robert Virding</name>
	</author>
	<content type="html">No.
&lt;br&gt;&lt;br&gt;There is a major difference between handling OOM in an OS and in the BEAM.
&lt;br&gt;In an OS it usually at a per process level that memory runs out so it is
&lt;br&gt;easy to decide which process to kill so that the OS can continue. In the
&lt;br&gt;BEAM, however, it is the VM as a whole which has run out of memory not a
&lt;br&gt;specific, it is. therefore, much more difficult to work out which process is
&lt;br&gt;the culprit and to decide what to do. For example it might be that the
&lt;br&gt;process which causes the OOM is not the actual problem process, it might
&lt;br&gt;just the last straw. Or the actual cause may that the whole app might be
&lt;br&gt;generating large binaries too quickly. Or it might be that the whole app is
&lt;br&gt;spawning to many processes without any one process being the cause. Or ...
&lt;br&gt;In all these cases killing the process which triggered the OOM would be the
&lt;br&gt;Wrong Thing. We found that it was difficult to work out a reasonable
&lt;br&gt;strategy to handle the actual cause so we decided not handle it.
&lt;br&gt;&lt;br&gt;&amp;quot;Don't catch an error which you can't handle&amp;quot; as the bard put it.
&lt;br&gt;&lt;br&gt;Robert
&lt;br&gt;&lt;br&gt;2009/11/9 Max Lapshin &amp;lt;&lt;a href=&quot;http://old.nabble.com/user/SendEmail.jtp?type=post&amp;post=26262631&amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;max.lapshin@...&lt;/a&gt;&amp;gt;
&lt;br&gt;&lt;br&gt;&amp;gt; Yes, there are techniques to write watchdogs, but my question was: is
&lt;br&gt;&amp;gt; it possible to prevent Erlang VM from crash?
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; ________________________________________________________________
&lt;br&gt;&amp;gt; erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;&amp;gt; erlang-questions (at) erlang.org
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt;
&lt;br&gt;&lt;p&gt;From forum: &lt;a href=&quot;http://old.nabble.com/Erlang-Questions-f14096.html&quot; embed=&quot;fixTarget[14096]&quot; target=&quot;_top&quot; &gt;Erlang Questions&lt;/a&gt;&lt;/p&gt;</content>
	<link rel="alternate" type="text/html" href="http://old.nabble.com/Why-Beam.smp-crashes-when-memory-is-over--tp26257892p26262631.html" />
</entry>

<entry>
	<id>tag:old.nabble.com,2006:post-26262318</id>
	<title>Re: Why Beam.smp crashes when memory is over?</title>
	<published>2009-11-08T23:37:32Z</published>
	<updated>2009-11-08T23:37:32Z</updated>
	<author>
		<name>Max Lapshin-2</name>
	</author>
	<content type="html">Yes, there are techniques to write watchdogs, but my question was: is
&lt;br&gt;it possible to prevent Erlang VM from crash?
&lt;br&gt;&lt;br&gt;________________________________________________________________
&lt;br&gt;erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;erlang-questions (at) erlang.org
&lt;br&gt;&lt;br&gt;&lt;p&gt;From forum: &lt;a href=&quot;http://old.nabble.com/Erlang-Questions-f14096.html&quot; embed=&quot;fixTarget[14096]&quot; target=&quot;_top&quot; &gt;Erlang Questions&lt;/a&gt;&lt;/p&gt;</content>
	<link rel="alternate" type="text/html" href="http://old.nabble.com/Why-Beam.smp-crashes-when-memory-is-over--tp26257892p26262318.html" />
</entry>

<entry>
	<id>tag:old.nabble.com,2006:post-26262244</id>
	<title>Re: Why Beam.smp crashes when memory is over?</title>
	<published>2009-11-08T23:31:24Z</published>
	<updated>2009-11-08T23:31:24Z</updated>
	<author>
		<name>Zoltan Lajos Kis</name>
	</author>
	<content type="html">Why don't you create a process, which regularly checks on the memory usage
&lt;br&gt;of those processes, and kills them when they begin to eat up too much
&lt;br&gt;memory?
&lt;br&gt;&lt;br&gt;Zoltan.
&lt;br&gt;&lt;div class='shrinkable-quote'&gt;&lt;br&gt;&amp;gt; Look, I have a program, that reads MPEG TS stream from network. There
&lt;br&gt;&amp;gt; is some bug in my code
&lt;br&gt;&amp;gt; and my ts_lander crashes beam. How is it possible to store state of
&lt;br&gt;&amp;gt; external HTTP stream??
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; If Erlang VM wouldn't crash, but only kill the leaking process, I
&lt;br&gt;&amp;gt; could buffer stream in other process and feed
&lt;br&gt;&amp;gt; new mpeg ts lander after restart. But it is impossible =(
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; ________________________________________________________________
&lt;br&gt;&amp;gt; erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;&amp;gt; erlang-questions (at) erlang.org
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt;
&lt;/div&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;________________________________________________________________
&lt;br&gt;erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;erlang-questions (at) erlang.org
&lt;br&gt;&lt;br&gt;&lt;p&gt;From forum: &lt;a href=&quot;http://old.nabble.com/Erlang-Questions-f14096.html&quot; embed=&quot;fixTarget[14096]&quot; target=&quot;_top&quot; &gt;Erlang Questions&lt;/a&gt;&lt;/p&gt;</content>
	<link rel="alternate" type="text/html" href="http://old.nabble.com/Why-Beam.smp-crashes-when-memory-is-over--tp26257892p26262244.html" />
</entry>

<entry>
	<id>tag:old.nabble.com,2006:post-26262143</id>
	<title>accessing ets from the process on other node</title>
	<published>2009-11-08T23:16:39Z</published>
	<updated>2009-11-08T23:16:39Z</updated>
	<author>
		<name>sapan shah</name>
	</author>
	<content type="html">HI,&lt;br&gt;&lt;br&gt;I use digraph module to create graphs and apply some functions on it. The digraph is internally stored as ets tuples.&lt;br&gt;I am using mapreduce architecture to speed up the computations on the digraph (using plists.erl from Stephen Marsh).&lt;br&gt;

So, When the graph is passed to a process on some other node on network, it exits with error. (may be because it is not able to access the ets tuples)&lt;br clear=&quot;all&quot;&gt;Any solution???&lt;br&gt;&lt;br&gt;Below is a small test example to generate the error&lt;br&gt;

%%%%%%%%%%%%%%%%%%%%%%%%%%%&lt;br&gt;-module(pliststest).&lt;br&gt;-compile(export_all).&lt;br&gt;&lt;br&gt;malt() -&amp;gt;&lt;br&gt;    [100, {nodes, [{&amp;#39;sap@laptop1&amp;#39;, 3}, {&amp;#39;sap@laptop2&amp;#39;, 3}]}].&lt;br&gt;&lt;br&gt;test(G, List) -&amp;gt;&lt;br&gt;    Fun = fun(X) -&amp;gt; io:format(&amp;quot;TROUBLE: ~p~n&amp;quot;,[digraph:vertices(G)]), lists:foldr(fun(_Y,ACC) -&amp;gt; ACC+1 end, 0, X) end,&lt;br&gt;

    Fuse = fun(X, Y) -&amp;gt; X+Y end,&lt;br&gt;    plists:runmany(Fun, Fuse, List, malt()).&lt;br&gt;%%%%%%%%%%%%%%%%%%%%%%%%%%%%&lt;br&gt;&lt;br&gt;Also, PFA the plists.erl (from Stephen Marsh).&lt;br&gt;&lt;br&gt;-- &lt;br&gt;Regards,&lt;br&gt;Sapan Shah&lt;br&gt;
&lt;br /&gt;&lt;tt&gt;[plists.erl]&lt;/tt&gt;&lt;br /&gt;&lt;hr align=&quot;left&quot; width=&quot;300&quot; /&gt;&lt;tt&gt;% @author Stephen Marsh
&lt;br&gt;% @copyright 2007 Stephen Marsh freeyourmind ++ [$@|gmail.com]
&lt;br&gt;% @doc plists is a drop-in replacement for module
&lt;br&gt;% &amp;lt;a href=&amp;quot;http://www.erlang.org/doc/man/lists.html&amp;quot;&amp;gt;lists&amp;lt;/a&amp;gt;,
&lt;br&gt;% making most list operations parallel. It can operate on each element in
&lt;br&gt;% parallel, for IO-bound operations, on sublists in parallel, for
&lt;br&gt;% taking advantage of multi-core machines with CPU-bound operations, and
&lt;br&gt;% across erlang nodes, for parallizing inside a cluster. It handles
&lt;br&gt;% errors and node failures. It can be configured, tuned, and tweaked to
&lt;br&gt;% get optimal performance while minimizing overhead.
&lt;br&gt;%
&lt;br&gt;% Almost all the functions are
&lt;br&gt;% identical to equivalent functions in lists, returning exactly the same
&lt;br&gt;% result, and having both a form with an identical syntax that operates on
&lt;br&gt;% each element in parallel and a form which takes an optional &amp;quot;malt&amp;quot;,
&lt;br&gt;% a specification for how to parallize the operation.
&lt;br&gt;%
&lt;br&gt;% fold is the one exception, parallel fold is different from linear fold.
&lt;br&gt;% This module also include a simple mapreduce implementation, and the
&lt;br&gt;% function runmany. All the other functions are implemented with runmany,
&lt;br&gt;% which is as a generalization of parallel list operations.
&lt;br&gt;%
&lt;br&gt;% == Malts ==
&lt;br&gt;% A malt specifies how to break a list into sublists, and can optionally
&lt;br&gt;% specify a timeout, which nodes to run on, and how many processes to start
&lt;br&gt;% per node.
&lt;br&gt;%
&lt;br&gt;% Malt = MaltComponent | [MaltComponent]&amp;lt;br/&amp;gt;
&lt;br&gt;% MaltComponent = SubListSize::integer() | {processes, integer()} |
&lt;br&gt;% {timeout, Milliseconds::integer()} | {nodes, [NodeSpec]}&amp;lt;br/&amp;gt;
&lt;br&gt;% NodeSpec = Node::atom() | {Node::atom(), NumProcesses::integer()}
&lt;br&gt;%
&lt;br&gt;% An integer can be given to specify the exact size for
&lt;br&gt;% sublists. 1 is a good choice for IO-bound operations and when
&lt;br&gt;% the operation on each list element is expensive. Larger numbers
&lt;br&gt;% minimize overhead and are faster for cheap operations.
&lt;br&gt;%
&lt;br&gt;% If the integer is omitted, and
&lt;br&gt;% you have specified a {processes, X}, the list is
&lt;br&gt;% split into X sublists. This is only
&lt;br&gt;% useful when the time to process each element is close to identical and you
&lt;br&gt;% know exactly how many lines of execution are available to you.
&lt;br&gt;%
&lt;br&gt;% If neither of the above applies, the sublist size defaults to 1.
&lt;br&gt;%
&lt;br&gt;% You can use {processes, X} to have the list processed
&lt;br&gt;% by X processes on the local machine. A good choice for X is the number of
&lt;br&gt;% lines of execution (cores) the machine provides.
&lt;br&gt;%
&lt;br&gt;% {timeout, Milliseconds} specifies a timeout. This is a timeout for the entire
&lt;br&gt;% operation, both operating on the sublists and combining the results.
&lt;br&gt;% exit(timeout) is evaluated if the timeout is exceeded.
&lt;br&gt;%
&lt;br&gt;% {nodes, NodeList} specifies that the operation should be done across nodes.
&lt;br&gt;% Every element of NodeList is of the form {NodeName, NumProcesses} or
&lt;br&gt;% NodeName, which means the same as {NodeName, 1}. plists runs
&lt;br&gt;% NumProcesses process on NodeName concurrently. A good choice for
&lt;br&gt;% NumProcesses is the number of lines of execution (cores) a machine provides
&lt;br&gt;% plus one. This ensures the machine is completely busy even when
&lt;br&gt;% fetching a new sublist. plists is able to recover if a node goes down.
&lt;br&gt;% If all nodes go down, exit(allnodescrashed) is evaluated.
&lt;br&gt;%
&lt;br&gt;% Any of the above may be used as a malt, or may be combined into a list.
&lt;br&gt;% {nodes, NodeList} and {processes, X} may not be combined.
&lt;br&gt;%
&lt;br&gt;% === Examples ===
&lt;br&gt;% % start a process for each element (1-element sublists)&amp;lt;br/&amp;gt;
&lt;br&gt;% 1
&lt;br&gt;%
&lt;br&gt;% % start a process for each ten elements (10-element sublists)&amp;lt;br/&amp;gt;
&lt;br&gt;% 10
&lt;br&gt;%
&lt;br&gt;% % split the list into two sublists and process in two processes&amp;lt;br/&amp;gt;
&lt;br&gt;% {processes, 2}
&lt;br&gt;%
&lt;br&gt;% % split the list into 10-element sublists and process in two processes&amp;lt;br/&amp;gt;
&lt;br&gt;% [10, {processes, 2}]
&lt;br&gt;%
&lt;br&gt;% % timeout after one second. Assumes that a process should be started&amp;lt;br/&amp;gt;
&lt;br&gt;% % for each element.&amp;lt;br/&amp;gt;
&lt;br&gt;% {timeout, 1000}
&lt;br&gt;%
&lt;br&gt;% % Runs 3 processes at a time on apple@desktop,
&lt;br&gt;% and 2 on orange@laptop&amp;lt;br/&amp;gt;
&lt;br&gt;% % This is the best way to utilize all the CPU-power of a dual-core&amp;lt;br/&amp;gt;
&lt;br&gt;% % desktop and a single-core laptop. Assumes that the list should be&amp;lt;br/&amp;gt;
&lt;br&gt;% % split into 1-element sublists.&amp;lt;br/&amp;gt;
&lt;br&gt;% {nodes, [{apple@desktop, 3}, {orange@laptop, 2}]}
&lt;br&gt;%
&lt;br&gt;% % Gives apple and orange three seconds to process the list as&amp;lt;br/&amp;gt;
&lt;br&gt;% % 100-element sublists.&amp;lt;br/&amp;gt;
&lt;br&gt;% [100, {timeout, 3000}, {nodes, [{apple@desktop, 3}, {orange@laptop, 2}]}]
&lt;br&gt;%
&lt;br&gt;% === Aside: Why Malt? ===
&lt;br&gt;% I needed a word for this concept, so maybe my subconsciousness gave me one by
&lt;br&gt;% making me misspell multiply. Maybe it is an acronym for Malt is A List
&lt;br&gt;% Tearing Specification. Maybe it is a beer metaphor, suggesting that code
&lt;br&gt;% only runs in parallel if bribed with spirits. It's jargon, learn it
&lt;br&gt;% or you can't be part of the in-group.
&lt;br&gt;%
&lt;br&gt;% == Messages and Errors ==
&lt;br&gt;% plists assures that no extraneous messages are left in or will later
&lt;br&gt;% enter the message queue. This is guaranteed even in the event of an error.
&lt;br&gt;%
&lt;br&gt;% Errors in spawned processes are caught and propagated to the calling
&lt;br&gt;% process. If you invoke
&lt;br&gt;%
&lt;br&gt;% plists:map(fun (X) -&amp;gt; 1/X end, [1, 2, 3, 0]).
&lt;br&gt;%
&lt;br&gt;% you get a badarith error, exactly like when you use lists:map.
&lt;br&gt;%
&lt;br&gt;% plists uses monitors to watch the processes it spawns. It is not a good idea
&lt;br&gt;% to invoke plists when you are already monitoring processes. If one of them
&lt;br&gt;% does a non-normal exit, plists receives the 'DOWN' message believing it to be
&lt;br&gt;% from one of its own processes. The error propagation system goes into
&lt;br&gt;% effect, which results in the error occuring in the calling process.
&lt;br&gt;%
&lt;br&gt;% == License ==
&lt;br&gt;% The MIT License
&lt;br&gt;%
&lt;br&gt;% Copyright (c) 2007 Stephen Marsh
&lt;br&gt;% 
&lt;br&gt;% Permission is hereby granted, free of charge, to any person obtaining a copy
&lt;br&gt;% of this software and associated documentation files (the &amp;quot;Software&amp;quot;), to deal
&lt;br&gt;% in the Software without restriction, including without limitation the rights
&lt;br&gt;% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
&lt;br&gt;% copies of the Software, and to permit persons to whom the Software is
&lt;br&gt;% furnished to do so, subject to the following conditions:
&lt;br&gt;% 
&lt;br&gt;% The above copyright notice and this permission notice shall be included in
&lt;br&gt;% all copies or substantial portions of the Software.
&lt;br&gt;% 
&lt;br&gt;% THE SOFTWARE IS PROVIDED &amp;quot;AS IS&amp;quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
&lt;br&gt;% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
&lt;br&gt;% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
&lt;br&gt;% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
&lt;br&gt;% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
&lt;br&gt;% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
&lt;br&gt;% THE SOFTWARE.
&lt;br&gt;&lt;br&gt;&lt;br&gt;-module(plists).
&lt;br&gt;-export([all/2, all/3, any/2, any/3, filter/2, filter/3,
&lt;br&gt;fold/3, fold/4, fold/5, foreach/2, foreach/3, map/2, map/3,
&lt;br&gt;partition/2, partition/3, sort/1, sort/2, sort/3,
&lt;br&gt;usort/1, usort/2, usort/3, mapreduce/2, mapreduce/3,
&lt;br&gt;runmany/3, runmany/4]).
&lt;br&gt;&lt;br&gt;% Everything here is defined in terms of runmany.
&lt;br&gt;% The following methods are convient interfaces to runmany.
&lt;br&gt;&lt;br&gt;% @doc Same semantics as in module
&lt;br&gt;% &amp;lt;a href=&amp;quot;http://www.erlang.org/doc/man/lists.html&amp;quot;&amp;gt;lists&amp;lt;/a&amp;gt;.
&lt;br&gt;% @spec (Fun, List) -&amp;gt; bool()
&lt;br&gt;all(Fun, List) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; all(Fun, List, 1).
&lt;br&gt;&lt;br&gt;% @doc Same semantics as in module
&lt;br&gt;% &amp;lt;a href=&amp;quot;http://www.erlang.org/doc/man/lists.html&amp;quot;&amp;gt;lists&amp;lt;/a&amp;gt;.
&lt;br&gt;% @spec (Fun, List, Malt) -&amp;gt; bool()
&lt;br&gt;all(Fun, List, Malt) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; try runmany(fun (L) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; B = lists:all(Fun, L),
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if B -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; nil;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;true -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; exit(notall)
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end,
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; fun (_A1, _A2) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; nil
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end,
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; List, Malt) of
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; _ -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; true
&lt;br&gt;&amp;nbsp; &amp;nbsp; catch exit:notall -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; false
&lt;br&gt;&amp;nbsp; &amp;nbsp; end.
&lt;br&gt;&lt;br&gt;% @doc Same semantics as in module
&lt;br&gt;% &amp;lt;a href=&amp;quot;http://www.erlang.org/doc/man/lists.html&amp;quot;&amp;gt;lists&amp;lt;/a&amp;gt;.
&lt;br&gt;% @spec (Fun, List) -&amp;gt; bool()
&lt;br&gt;any(Fun, List) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; any(Fun, List, 1).
&lt;br&gt;&lt;br&gt;% @doc Same semantics as in module
&lt;br&gt;% &amp;lt;a href=&amp;quot;http://www.erlang.org/doc/man/lists.html&amp;quot;&amp;gt;lists&amp;lt;/a&amp;gt;.
&lt;br&gt;% @spec (Fun, List, Malt) -&amp;gt; bool()
&lt;br&gt;any(Fun, List, Malt) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; try runmany(fun (L) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; B = lists:any(Fun, L),
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if B -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; exit(any);
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;true -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; nil
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end,
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; fun (_A1, _A2) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; nil
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end,
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; List, Malt) of
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; _ -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; false
&lt;br&gt;&amp;nbsp; &amp;nbsp; catch exit:any -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; true
&lt;br&gt;&amp;nbsp; &amp;nbsp; end.
&lt;br&gt;&lt;br&gt;% @doc Same semantics as in module
&lt;br&gt;% &amp;lt;a href=&amp;quot;http://www.erlang.org/doc/man/lists.html&amp;quot;&amp;gt;lists&amp;lt;/a&amp;gt;.
&lt;br&gt;% @spec (Fun, List) -&amp;gt; list()
&lt;br&gt;filter(Fun, List) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; filter(Fun, List, 1).
&lt;br&gt;&lt;br&gt;% @doc Same semantics as in module
&lt;br&gt;% &amp;lt;a href=&amp;quot;http://www.erlang.org/doc/man/lists.html&amp;quot;&amp;gt;lists&amp;lt;/a&amp;gt;.
&lt;br&gt;% @spec (Fun, List, Malt) -&amp;gt; list()
&lt;br&gt;filter(Fun, List, Malt) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; runmany(fun (L) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; lists:filter(Fun, L)
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end,
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; fun (A1, A2) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A1 ++ A2
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end,
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; List, Malt).
&lt;br&gt;&lt;br&gt;% Note that with parallel fold there is not foldl and foldr,
&lt;br&gt;% instead just one fold that can fuse Accumlators.
&lt;br&gt;&lt;br&gt;% @doc Like below, but assumes 1 as the Malt. This function is almost useless,
&lt;br&gt;% and is intended only to aid converting code from using lists to plists.
&lt;br&gt;% @spec (Fun, InitAcc, List) -&amp;gt; term()
&lt;br&gt;fold(Fun, InitAcc, List) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; fold(Fun, Fun, InitAcc, List, 1).
&lt;br&gt;&lt;br&gt;% @doc Like below, but uses the Fun as the Fuse by default.
&lt;br&gt;% @spec (Fun, InitAcc, List, Malt) -&amp;gt; term()
&lt;br&gt;fold(Fun, InitAcc, List, Malt) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; fold(Fun, Fun, InitAcc, List, Malt).
&lt;br&gt;&lt;br&gt;% @doc fold is more complex when made parallel. There is no foldl and foldr,
&lt;br&gt;% accumulators aren't passed in any defined order.
&lt;br&gt;% The list is split into sublists which are folded together. Fun is
&lt;br&gt;% identical to the function passed to lists:fold[lr], it takes
&lt;br&gt;% (an element, and the accumulator) and returns -&amp;gt; a new accumulator.
&lt;br&gt;% It is used for the initial stage of folding sublists. Fuse fuses together
&lt;br&gt;% the results, it takes (Results1, Result2) and returns -&amp;gt; a new result.
&lt;br&gt;% By default sublists are fused left to right, each result of a fuse being
&lt;br&gt;% fed into the first element of the next fuse. The result of the last fuse
&lt;br&gt;% is the result.
&lt;br&gt;%
&lt;br&gt;% Fusing may also run in parallel using a recursive algorithm,
&lt;br&gt;% by specifying the fuse as {recursive, Fuse}. See
&lt;br&gt;% the discussion in {@link runmany/4}.
&lt;br&gt;%
&lt;br&gt;% Malt is the malt for the initial folding of sublists, and for the
&lt;br&gt;% possible recursive fuse.
&lt;br&gt;% @spec (Fun, Fuse, InitAcc, List, Malt) -&amp;gt; term()
&lt;br&gt;fold(Fun, Fuse, InitAcc, List, Malt) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; Fun2 = fun (L) -&amp;gt; lists:foldl(Fun, InitAcc, L) end,
&lt;br&gt;&amp;nbsp; &amp;nbsp; runmany(Fun2, Fuse, List, Malt).
&lt;br&gt;&lt;br&gt;% @doc Same semantics as in module
&lt;br&gt;% &amp;lt;a href=&amp;quot;http://www.erlang.org/doc/man/lists.html&amp;quot;&amp;gt;lists&amp;lt;/a&amp;gt;.
&lt;br&gt;% @spec (Fun, List) -&amp;gt; void()
&lt;br&gt;foreach(Fun, List) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; foreach(Fun, List, 1).
&lt;br&gt;&lt;br&gt;% @doc Same semantics as in module
&lt;br&gt;% &amp;lt;a href=&amp;quot;http://www.erlang.org/doc/man/lists.html&amp;quot;&amp;gt;lists&amp;lt;/a&amp;gt;.
&lt;br&gt;% @spec (Fun, List, Malt) -&amp;gt; void()
&lt;br&gt;foreach(Fun, List, Malt) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; runmany(fun (L) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; lists:foreach(Fun, L)
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end,
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; fun (_A1, _A2) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ok
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end,
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; List, Malt).
&lt;br&gt;&lt;br&gt;% @doc Same semantics as in module
&lt;br&gt;% &amp;lt;a href=&amp;quot;http://www.erlang.org/doc/man/lists.html&amp;quot;&amp;gt;lists&amp;lt;/a&amp;gt;.
&lt;br&gt;% @spec (Fun, List) -&amp;gt; list()
&lt;br&gt;map(Fun, List) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; map(Fun, List, 1).
&lt;br&gt;&lt;br&gt;% @doc Same semantics as in module
&lt;br&gt;% &amp;lt;a href=&amp;quot;http://www.erlang.org/doc/man/lists.html&amp;quot;&amp;gt;lists&amp;lt;/a&amp;gt;.
&lt;br&gt;% @spec (Fun, List, Malt) -&amp;gt; list()
&lt;br&gt;map(Fun, List, Malt) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; runmany(fun (L) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; lists:map(Fun, L)
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end,
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; fun (A1, A2) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A1 ++ A2
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end,
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; List, Malt).
&lt;br&gt;&lt;br&gt;% @doc Same semantics as in module
&lt;br&gt;% &amp;lt;a href=&amp;quot;http://www.erlang.org/doc/man/lists.html&amp;quot;&amp;gt;lists&amp;lt;/a&amp;gt;.
&lt;br&gt;% @spec (Fun, List) -&amp;gt; {list(), list()}
&lt;br&gt;partition(Fun, List) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; partition(Fun, List, 1).
&lt;br&gt;&lt;br&gt;% @doc Same semantics as in module
&lt;br&gt;% &amp;lt;a href=&amp;quot;http://www.erlang.org/doc/man/lists.html&amp;quot;&amp;gt;lists&amp;lt;/a&amp;gt;.
&lt;br&gt;% @spec (Fun, List, Malt) -&amp;gt; {list(), list()}
&lt;br&gt;partition(Fun, List, Malt) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; runmany(fun (L) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; lists:partition(Fun, L)
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end,
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; fun ({True1, False1}, {True2, False2}) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {True1 ++ True2, False1 ++ False2}
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end,
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; List, Malt).
&lt;br&gt;&lt;br&gt;% SORTMALT needs to be tuned
&lt;br&gt;-define(SORTMALT, 100).
&lt;br&gt;&lt;br&gt;% @doc Same semantics as in module
&lt;br&gt;% &amp;lt;a href=&amp;quot;http://www.erlang.org/doc/man/lists.html&amp;quot;&amp;gt;lists&amp;lt;/a&amp;gt;.
&lt;br&gt;% @spec (List) -&amp;gt; list()
&lt;br&gt;sort(List) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; sort(fun (A, B) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A =&amp;lt; B
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end,
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;List).
&lt;br&gt;&lt;br&gt;% @doc Same semantics as in module
&lt;br&gt;% &amp;lt;a href=&amp;quot;http://www.erlang.org/doc/man/lists.html&amp;quot;&amp;gt;lists&amp;lt;/a&amp;gt;.
&lt;br&gt;% @spec (Fun, List) -&amp;gt; list()
&lt;br&gt;sort(Fun, List) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; sort(Fun, List, ?SORTMALT).
&lt;br&gt;&lt;br&gt;% @doc This version lets you specify your own malt for sort.
&lt;br&gt;%
&lt;br&gt;% sort splits the list into sublists and sorts them, and it merges the
&lt;br&gt;% sorted lists together. These are done in parallel. Each sublist is
&lt;br&gt;% sorted in a seperate process, and each merging of results is done in a
&lt;br&gt;% seperate process. Malt defaults to 100, causing the list to be split into
&lt;br&gt;% 100-element sublists.
&lt;br&gt;% @spec (Fun, List, Malt) -&amp;gt; list()
&lt;br&gt;sort(Fun, List, Malt) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; Fun2 = fun (L) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; lists:sort(Fun, L)
&lt;br&gt;&amp;nbsp; &amp;nbsp; end,
&lt;br&gt;&amp;nbsp; &amp;nbsp; Fuse = fun (A1, A2) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; lists:merge(Fun, A1, A2)
&lt;br&gt;&amp;nbsp; &amp;nbsp; end,
&lt;br&gt;&amp;nbsp; &amp;nbsp; runmany(Fun2, {recursive, Fuse}, List, Malt).
&lt;br&gt;&lt;br&gt;% @doc Same semantics as in module
&lt;br&gt;% &amp;lt;a href=&amp;quot;http://www.erlang.org/doc/man/lists.html&amp;quot;&amp;gt;lists&amp;lt;/a&amp;gt;.
&lt;br&gt;% @spec (List) -&amp;gt; list()
&lt;br&gt;usort(List) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; usort(fun (A, B) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A =&amp;lt; B
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end,
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;List).
&lt;br&gt;&lt;br&gt;% @doc Same semantics as in module
&lt;br&gt;% &amp;lt;a href=&amp;quot;http://www.erlang.org/doc/man/lists.html&amp;quot;&amp;gt;lists&amp;lt;/a&amp;gt;.
&lt;br&gt;% @spec (Fun, List) -&amp;gt; list()
&lt;br&gt;usort(Fun, List) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; usort(Fun, List, ?SORTMALT).
&lt;br&gt;&lt;br&gt;% @doc This version lets you specify your own malt for usort.
&lt;br&gt;%
&lt;br&gt;% usort splits the list into sublists and sorts them, and it merges the
&lt;br&gt;% sorted lists together. These are done in parallel. Each sublist is
&lt;br&gt;% sorted in a seperate process, and each merging of results is done in a
&lt;br&gt;% seperate process. Malt defaults to 100, causing the list to be split into
&lt;br&gt;% 100-element sublists.
&lt;br&gt;%
&lt;br&gt;% usort removes duplicate elments while it sorts.
&lt;br&gt;% @spec (Fun, List, Malt) -&amp;gt; list()
&lt;br&gt;usort(Fun, List, Malt) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; Fun2 = fun (L) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; lists:usort(Fun, L)
&lt;br&gt;&amp;nbsp; &amp;nbsp; end,
&lt;br&gt;&amp;nbsp; &amp;nbsp; Fuse = fun (A1, A2) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; lists:umerge(Fun, A1, A2)
&lt;br&gt;&amp;nbsp; &amp;nbsp; end,
&lt;br&gt;&amp;nbsp; &amp;nbsp; runmany(Fun2, {recursive, Fuse}, List, Malt).
&lt;br&gt;&lt;br&gt;% @doc Like below, assumes default MapMalt of 1.
&lt;br&gt;% @spec (MapFunc, List) -&amp;gt; Dict
&lt;br&gt;% MapFunc = (term()) -&amp;gt; DeepListOfKeyValuePairs
&lt;br&gt;% DeepListOfKeyValuePairs = [DeepListOfKeyValuePairs] | {Key, Value}
&lt;br&gt;mapreduce(MapFunc, List) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; mapreduce(MapFunc, List, 1).
&lt;br&gt;&lt;br&gt;% @doc This is a very basic mapreduce. You won't write a Google-rivaling
&lt;br&gt;% search engine with it. It has no equivalent in lists. Each
&lt;br&gt;% element in the list is run through the MapFunc, which produces either
&lt;br&gt;% a {Key, Value} pair, or a lists of key value pairs, or a list of lists of
&lt;br&gt;% key value pairs...etc. A reducer process runs in parallel with the mapping
&lt;br&gt;% processes, collecting the key value pairs into a
&lt;br&gt;% &amp;lt;a href=&amp;quot;http://www.erlang.org/doc/man/dict.html&amp;quot;&amp;gt;dict&amp;lt;/a&amp;gt;. This dict
&lt;br&gt;% is returned as the result.
&lt;br&gt;%
&lt;br&gt;% MapMalt is the malt for the mapping operation, with a default value of 1,
&lt;br&gt;% meaning each element of the list is mapped by a seperate process.
&lt;br&gt;%
&lt;br&gt;% mapreduce requires OTP R11B, or it may leave monitoring messages in the
&lt;br&gt;% message queue.
&lt;br&gt;% @spec (MapFunc, List, MapMalt) -&amp;gt; Dict
&lt;br&gt;% MapFunc = (term()) -&amp;gt; DeepListOfKeyValuePairs
&lt;br&gt;% DeepListOfKeyValuePairs = [DeepListOfKeyValuePairs] | {Key, Value}
&lt;br&gt;mapreduce(MapFunc, List, MapMalt) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; Parent = self(),
&lt;br&gt;&amp;nbsp; &amp;nbsp; {Reducer, ReducerRef} =
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; erlang:spawn_monitor(fun () -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;reducer(Parent, dict:new(), 0)
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end),
&lt;br&gt;&amp;nbsp; &amp;nbsp; MapFunc2 = fun (L) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Reducer ! lists:map(MapFunc, L),
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end,
&lt;br&gt;&amp;nbsp; &amp;nbsp; SentMessages = try runmany(MapFunc2, fun (A, B) -&amp;gt; A+B end, List, MapMalt)
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;catch
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;exit:Reason -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;erlang:demonitor(ReducerRef, [flush]),
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Reducer ! die,
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;exit(Reason)
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end,
&lt;br&gt;&amp;nbsp; &amp;nbsp; Reducer ! {done, SentMessages},
&lt;br&gt;&amp;nbsp; &amp;nbsp; Results = receive
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {Reducer, Results2} -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Results2;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {'DOWN', _, _, Reducer, Reason2} -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; exit(Reason2)
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end,
&lt;br&gt;&amp;nbsp; &amp;nbsp; receive
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {'DOWN', _, _, Reducer, normal} -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; nil
&lt;br&gt;&amp;nbsp; &amp;nbsp; end,
&lt;br&gt;&amp;nbsp; &amp;nbsp; Results.
&lt;br&gt;&lt;br&gt;reducer(Parent, Dict, NumReceived) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; receive
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; die -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; nil;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {done, NumReceived} -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Parent ! {self (), Dict};
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Keys &amp;nbsp;-&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; reducer(Parent, add_keys(Dict, Keys), NumReceived + 1)
&lt;br&gt;&amp;nbsp; &amp;nbsp; end.
&lt;br&gt;&lt;br&gt;add_keys(Dict, [{Key, Value}|Keys]) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; case dict:is_key(Key, Dict) of
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; true -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; add_keys(dict:append(Key, Value, Dict), Keys);
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; false -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; add_keys(dict:store(Key, [Value], Dict), Keys)
&lt;br&gt;&amp;nbsp; &amp;nbsp; end;
&lt;br&gt;add_keys(Dict, [List|Keys]) when is_list(List) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; add_keys(add_keys(Dict, List), Keys);
&lt;br&gt;add_keys(Dict, []) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; Dict.
&lt;br&gt;&lt;br&gt;% @doc Like below, but assumes a Malt of 1,
&lt;br&gt;% meaning each element of the list is processed by a seperate process.
&lt;br&gt;% @spec (Fun, Fuse, List) -&amp;gt; term()
&lt;br&gt;runmany(Fun, Fuse, List) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; runmany(Fun, Fuse, List, 1).
&lt;br&gt;&lt;br&gt;% Begin internal stuff (though runmany/4 is exported).
&lt;br&gt;&lt;br&gt;% @doc All of the other functions are implemented with runmany. runmany
&lt;br&gt;% takes a List, splits it into sublists, and starts processes to operate on
&lt;br&gt;% each sublist, all done according to Malt. Each process passes its sublist
&lt;br&gt;% into Fun and sends the result back.
&lt;br&gt;%
&lt;br&gt;% The results are then fused together to get the final result. There are two
&lt;br&gt;% ways this can operate, lineraly and recursively. If Fuse is a function,
&lt;br&gt;% a fuse is done linearly left-to-right on the sublists, the results
&lt;br&gt;% of processing the first and second sublists being passed to Fuse, then
&lt;br&gt;% the result of that fuse and processing the third sublits, and so on.
&lt;br&gt;% This method preserves the original order of the lists elements.
&lt;br&gt;%
&lt;br&gt;% To do a recursive fuse, pass Fuse as {recursive, FuseFunc}.
&lt;br&gt;% The recursive fuse makes no guarantee about the order the results of
&lt;br&gt;% sublists, or the results of fuses are passed to FuseFunc. It
&lt;br&gt;% continues fusing pairs of results until it is down to one.
&lt;br&gt;%
&lt;br&gt;% Recursive fuse is down in parallel with processing the sublists, and a
&lt;br&gt;% process is spawned to fuse each pair of results. It is a parallized
&lt;br&gt;% algorithm. Linear fuse is done after all results of processing sublists
&lt;br&gt;% have been collected, and can only run in a single process.
&lt;br&gt;%
&lt;br&gt;% Even if you pass {recursive, FuseFunc}, a recursive fuse is only done if
&lt;br&gt;% the malt contains {nodes, NodeList} or {processes, X}. If this is not the
&lt;br&gt;% case, a linear fuse is done.
&lt;br&gt;% @spec (Fun, Fuse, List, Malt) -&amp;gt; term()
&lt;br&gt;% Fun = (list()) -&amp;gt; term()
&lt;br&gt;% Fuse = FuseFunc | {recursive, FuseFunc}
&lt;br&gt;% FuseFunc = (term(), term()) -&amp;gt; term()
&lt;br&gt;runmany(Fun, Fuse, List, Malt) when is_list(Malt) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; % If the sublist size wasn't specified, assume a default.
&lt;br&gt;&amp;nbsp; &amp;nbsp; case lists:any(fun (X) when is_integer(X) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;true;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(_) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;false
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end, Malt) of
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; true -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; runmany(Fun, Fuse, List, local, Malt);
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; false -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; case lists:foldl(fun({processes, X}, _A) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;X;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (_, A) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end, no_processes, Malt) of
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; no_processes -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; runmany(Fun, Fuse, List, local, [1|Malt]);
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; X -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; % split list into X sublists.
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; L = length(List),
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; case L rem X of
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; runmany(Fun, Fuse, List, local, [L div X|Malt]);
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; _ -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; runmany(Fun, Fuse, List, local, [L div X + 1|Malt])
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end
&lt;br&gt;&amp;nbsp; &amp;nbsp; end;
&lt;br&gt;runmany(Fun, Fuse, List, Malt) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; runmany(Fun, Fuse, List, [Malt]).
&lt;br&gt;&lt;br&gt;runmany(Fun, Fuse, List, Nodes, [MaltTerm|Malt]) when is_integer(MaltTerm) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; runmany(Fun, Fuse, splitmany(List, MaltTerm), Nodes, Malt);
&lt;br&gt;% run X process on local machine
&lt;br&gt;runmany(Fun, Fuse, List, local, [{processes, X}|Malt]) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; Nodes = lists:duplicate(X, node()),
&lt;br&gt;&amp;nbsp; &amp;nbsp; runmany(Fun, Fuse, List, Nodes, Malt);
&lt;br&gt;runmany(Fun, Fuse, List, Nodes, [{timeout, X}|Malt]) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; Parent = self(),
&lt;br&gt;&amp;nbsp; &amp;nbsp; Timer = spawn(fun () -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; receive
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; stoptimer -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Parent ! {timerstopped, self()}
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; after X -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Parent ! {timerrang, self()},
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; receive
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; stoptimer -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Parent ! {timerstopped, self()}
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end),
&lt;br&gt;&amp;nbsp; &amp;nbsp; Ans = try runmany(Fun, Fuse, List, Nodes, Malt)
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; catch
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; % we really just want the after block, the syntax
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; % makes this catch necessary.
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; willneverhappen -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; nil
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; after
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Timer ! stoptimer,
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cleanup_timer(Timer)
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end,
&lt;br&gt;&amp;nbsp; &amp;nbsp; Ans;
&lt;br&gt;runmany(Fun, Fuse, List, local, [{nodes, NodeList}|Malt]) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; Nodes = lists:foldl(fun ({Node, X}, A) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; lists:reverse(lists:duplicate(X, Node), A);
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; (Node, A) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [Node|A]
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end,
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [], NodeList),
&lt;br&gt;&amp;nbsp; &amp;nbsp; runmany(Fun, Fuse, List, Nodes, Malt);
&lt;br&gt;% local recursive fuse, for when we weren't invoked with {processes, X}
&lt;br&gt;% or {nodes, NodeList}. Degenerates recursive fuse into linear fuse.
&lt;br&gt;runmany(Fun, {recursive, Fuse}, List, local, []) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; runmany(Fun, Fuse, List, local, []);
&lt;br&gt;runmany(Fun, Fuse, List, local, []) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; local_runmany(Fun, Fuse, List);
&lt;br&gt;runmany(Fun, Fuse, List, Nodes, []) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; cluster_runmany(Fun, Fuse, List, Nodes).
&lt;br&gt;&lt;br&gt;cleanup_timer(Timer) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; receive
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {timerrang, Timer} -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cleanup_timer(Timer);
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {timerstopped, Timer} -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; nil
&lt;br&gt;&amp;nbsp; &amp;nbsp; end.
&lt;br&gt;&lt;br&gt;% local runmany, for when we weren't invoked with {processes, X}
&lt;br&gt;% or {nodes, NodeList}. Every sublist is processed in parallel.
&lt;br&gt;local_runmany(Fun, Fuse, List) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; Parent = self (),
&lt;br&gt;&amp;nbsp; &amp;nbsp; Pids = lists:map(fun (L) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;F = fun () -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Parent !
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{self (), Fun(L)}
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end,
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{Pid, _} = erlang:spawn_monitor(F),
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Pid
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end,
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;List),
&lt;br&gt;&amp;nbsp; &amp;nbsp; Answers = try lists:map(fun receivefrom/1, Pids)
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; catch throw:Message -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {BadPid, Reason} = Message,
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; handle_error(BadPid, Reason, Pids)
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end,
&lt;br&gt;&amp;nbsp; &amp;nbsp; lists:foreach(fun (Pid) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; normal_cleanup(Pid)
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end, Pids),
&lt;br&gt;&amp;nbsp; &amp;nbsp; fuse(Fuse, Answers).
&lt;br&gt;&lt;br&gt;receivefrom(Pid) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; receive
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {Pid, R} -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; R;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {'DOWN', _, _, BadPid, Reason} when Reason =/= normal -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; throw({BadPid, Reason});
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {timerrang, _} -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; throw({nil, timeout})
&lt;br&gt;&amp;nbsp; &amp;nbsp; end.
&lt;br&gt;&lt;br&gt;% Convert List into [{Number, Sublist}]
&lt;br&gt;cluster_runmany(Fun, Fuse, List, Nodes) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; {List2, _} = lists:foldl(fun (X, {L, Count}) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {[{Count, X}|L], Count+1}
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end,
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {[], 0}, List),
&lt;br&gt;&amp;nbsp; &amp;nbsp; cluster_runmany(Fun, Fuse, List2, Nodes, [], []).
&lt;br&gt;&lt;br&gt;% Add a pair of results into the TaskList as a fusing task
&lt;br&gt;cluster_runmany(Fun, {recursive, Fuse}, [], Nodes, Running,
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [{_, R1}, {_, R2}|Results]) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; cluster_runmany(Fun, {recursive, Fuse}, [{fuse, R1, R2}], Nodes,
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Running, Results);
&lt;br&gt;% recursive fuse done, return result
&lt;br&gt;cluster_runmany(_, {recursive, _Fuse}, [], _Nodes, [], [{_, Result}]) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; Result;
&lt;br&gt;% edge case where we are asked to do nothing
&lt;br&gt;cluster_runmany(_, {recursive, _Fuse}, [], _Nodes, [], []) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; [];
&lt;br&gt;% We're done, now we just have to [linear] fuse the results
&lt;br&gt;cluster_runmany(_, Fuse, [], _Nodes, [], Results) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; fuse(Fuse, lists:map(fun ({_, R}) -&amp;gt; R end,
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;lists:sort(fun ({A, _}, {B, _}) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; A =&amp;lt; B
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end,
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; lists:reverse(Results))));
&lt;br&gt;% We have a ready node and a sublist or fuse to be processed, so we start
&lt;br&gt;% a new process
&lt;br&gt;cluster_runmany(Fun, Fuse, [Task|TaskList], [N|Nodes], Running, Results) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; Parent = self(),
&lt;br&gt;&amp;nbsp; &amp;nbsp; case Task of
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {Num, L2} -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Fun2 = fun () -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Parent ! {self(), Num, Fun(L2)}
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {fuse, R1, R2} -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {recursive, FuseFunc} = Fuse,
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Fun2 = fun () -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Parent ! {self(), junknum, FuseFunc(R1, R2)}
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end
&lt;br&gt;&amp;nbsp; &amp;nbsp; end,
&lt;br&gt;&amp;nbsp; &amp;nbsp; Pid = spawn(N, Fun2),
&lt;br&gt;&amp;nbsp; &amp;nbsp; erlang:monitor(process, Pid),
&lt;br&gt;&amp;nbsp; &amp;nbsp; cluster_runmany(Fun, Fuse, TaskList, Nodes, [{Pid, N, Task}|Running], Results);
&lt;br&gt;% We can't start a new process, but can watch over already running ones
&lt;br&gt;cluster_runmany(Fun, Fuse, TaskList, Nodes, Running, Results) when length(Running) &amp;gt; 0 -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; receive
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {Pid, Num, Result} -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; % throw out the normal exit message
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; receive {'DOWN', _, _, Pid, normal} -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; nil;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {'DOWN', _, _, Pid, noproc}-&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; nil
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end,
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {Running2, FinishedNode, _} = delete_running(Pid, Running, []),
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cluster_runmany(Fun, Fuse, TaskList,
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [FinishedNode|Nodes], Running2, [{Num, Result}|Results]);
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {timerrang, _} -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; RunningPids = lists:map(fun ({Pid, _, _}) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Pid
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end,
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Running),
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; handle_error(nil, timeout, RunningPids);
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; % node failure
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {'DOWN', _, _, Pid, noconnection} -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {Running2, _DeadNode, Task} = delete_running(Pid, Running, []),
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cluster_runmany(Fun, Fuse, [Task|TaskList], Nodes,
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Running2, Results);
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {'DOWN', _, _, BadPid, Reason} when Reason =/= normal -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; RunningPids = lists:map(fun ({Pid, _, _}) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Pid
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end,
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Running),
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; handle_error(BadPid, Reason, RunningPids)
&lt;br&gt;&amp;nbsp; &amp;nbsp; end;
&lt;br&gt;% We have data, but no nodes either available or occupied
&lt;br&gt;cluster_runmany(_, _, [_Non|_Empty], []=_Nodes, []=_Running, _) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; exit(allnodescrashed).
&lt;br&gt;&lt;br&gt;delete_running(Pid, [{Pid, Node, List}|Running], Acc) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; {Running ++ Acc, Node, List};
&lt;br&gt;delete_running(Pid, [R|Running], Acc) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; delete_running(Pid, Running, [R|Acc]).
&lt;br&gt;&lt;br&gt;handle_error(BadPid, Reason, Pids) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; lists:foreach(fun (Pid) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; exit(Pid, siblingdied)
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end, Pids),
&lt;br&gt;&amp;nbsp; &amp;nbsp; lists:foreach(fun (Pid) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; error_cleanup(Pid, BadPid)
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; end, Pids),
&lt;br&gt;&amp;nbsp; &amp;nbsp; exit(Reason).
&lt;br&gt;&lt;br&gt;error_cleanup(BadPid, BadPid) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; ok;
&lt;br&gt;error_cleanup(Pid, BadPid) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; receive
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {Pid, _} -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; error_cleanup(Pid, BadPid);
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {Pid, _, _} -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; error_cleanup(Pid, BadPid);
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {'DOWN', _, _, Pid, _Reason} -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ok
&lt;br&gt;&amp;nbsp; &amp;nbsp; end.
&lt;br&gt;&lt;br&gt;normal_cleanup(Pid) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; receive
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {'DOWN', _, _, Pid, _Reason} -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ok
&lt;br&gt;&amp;nbsp; &amp;nbsp; end.
&lt;br&gt;&lt;br&gt;fuse(Fuse, [R1|Results]) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; fuse(Fuse, Results, R1);
&lt;br&gt;fuse(_, []) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; [].
&lt;br&gt;&lt;br&gt;fuse(Fuse, [R2|Results], R1) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; fuse(Fuse, Results, Fuse(R1, R2));
&lt;br&gt;fuse(_, [], R) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; R.
&lt;br&gt;&lt;br&gt;% Splits a list into a list of sublists, each of size Size,
&lt;br&gt;% except for the last element which is less if the original list
&lt;br&gt;% could not be evenly divided into Size-sized lists.
&lt;br&gt;splitmany(List, Size) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; splitmany(List, [], Size).
&lt;br&gt;&lt;br&gt;splitmany([], Acc, _) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; lists:reverse(Acc);
&lt;br&gt;splitmany(List, Acc, Size) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; {Top, NList} = split(Size, List),
&lt;br&gt;&amp;nbsp; &amp;nbsp; splitmany(NList, [Top|Acc], Size).
&lt;br&gt;&lt;br&gt;% Like lists:split, except it splits a list smaller than its first
&lt;br&gt;% parameter
&lt;br&gt;split(Size, List) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; split(Size, List, []).
&lt;br&gt;&lt;br&gt;split(0, List, Acc) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; {lists:reverse(Acc), List};
&lt;br&gt;split(Size, [H|List], Acc) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; split(Size - 1, List, [H|Acc]);
&lt;br&gt;split(_, [], Acc) -&amp;gt;
&lt;br&gt;&amp;nbsp; &amp;nbsp; {lists:reverse(Acc), []}.
&lt;br&gt;&lt;/tt&gt;&lt;hr align=&quot;left&quot; width=&quot;300&quot; /&gt;&lt;br /&gt;&lt;br&gt;________________________________________________________________
&lt;br&gt;erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;erlang-questions (at) erlang.org&lt;p&gt;From forum: &lt;a href=&quot;http://old.nabble.com/Erlang-Questions-f14096.html&quot; embed=&quot;fixTarget[14096]&quot; target=&quot;_top&quot; &gt;Erlang Questions&lt;/a&gt;&lt;/p&gt;</content>
	<link rel="alternate" type="text/html" href="http://old.nabble.com/accessing-ets-from-the-process-on-other-node-tp26262143p26262143.html" />
</entry>

<entry>
	<id>tag:old.nabble.com,2006:post-26261940</id>
	<title>Re: Why Beam.smp crashes when memory is over?</title>
	<published>2009-11-08T22:48:11Z</published>
	<updated>2009-11-08T22:48:11Z</updated>
	<author>
		<name>Andrew Thompson-15</name>
	</author>
	<content type="html">On Sun, Nov 08, 2009 at 10:43:25PM -0700, Tony Arcieri wrote:
&lt;div class='shrinkable-quote'&gt;&lt;br&gt;&amp;gt; I'm not really sure if we're speaking about the same thing then. &amp;nbsp;Erlang is
&lt;br&gt;&amp;gt; best utilized as a stateless platform, with a &amp;quot;fail early fail often&amp;quot;
&lt;br&gt;&amp;gt; philosophy, and crashing the entire interpreter in the event of some
&lt;br&gt;&amp;gt; underlying problem with the OS fits that entirely. &amp;nbsp;You seem to be seeking a
&lt;br&gt;&amp;gt; platform that lets you program defensively, handling errors rather than
&lt;br&gt;&amp;gt; crashing and restoring with a clean state. &amp;nbsp;In that regard, Erlang may not
&lt;br&gt;&amp;gt; be the best language for you to work with, but then again the problem of
&lt;br&gt;&amp;gt; successfully recovering from an out-of-resource condition is an extremely
&lt;br&gt;&amp;gt; difficult one to handle well without scrapping it all and trying to restart
&lt;br&gt;&amp;gt; with a clean state.
&lt;br&gt;&amp;gt;
&lt;/div&gt;&lt;br&gt;I agree that Erlang is best used when your application is as stateless
&lt;br&gt;as possible, or has clear transfer of responsibility (HTTP server, SMTP
&lt;br&gt;server, etc), but sometimes Erlang still has a lot of benefits even if
&lt;br&gt;you're lugging some state around, and that's when the current OOM
&lt;br&gt;behaviour is a little annoying. I don't say that the current behaviour
&lt;br&gt;is not the best in a lot of situations, but it'd be nice to have an
&lt;br&gt;alternative in cases where nuking the VM and having to recover or simply
&lt;br&gt;discard a lot of state is unpleasant.
&lt;br&gt;&lt;br&gt;In an ideal world I'd like to see an *optional* OOM behaviour similar to
&lt;br&gt;the following:
&lt;br&gt;&lt;br&gt;On startup, the VM pre-allocates enough memory to be able to attempt OOM
&lt;br&gt;recovery without additional malloc calls. If and when an OOM condition
&lt;br&gt;is detected, freeze the VM, iterate the process list and simply
&lt;br&gt;exit(FatPid, oom) the process with the most memory allocated (obviously
&lt;br&gt;this strategy is full of holes, epecially with regard to off-heap
&lt;br&gt;binaries), but *sometimes* it's better than just blowing away the whole
&lt;br&gt;thing. Then, if the malloc fails again, revert to the current behaviour.
&lt;br&gt;&lt;br&gt;You could, of course try to be smarter about it (look at the process
&lt;br&gt;calling malloc, look at the reference counted binaries, try to avoid
&lt;br&gt;killing SASL or system processes), but the point is that sometimes the
&lt;br&gt;obvious offender is the only one you need to kill to restore a system's
&lt;br&gt;functionality.
&lt;br&gt;&lt;br&gt;Of course, I'm no expert on this, these are merely musings from having
&lt;br&gt;(entirely due to my own fault) triggered plenty of OOM VM kills that
&lt;br&gt;would have been as easily solved if a single process had been killed.
&lt;br&gt;&lt;br&gt;Andrew
&lt;br&gt;&lt;br&gt;________________________________________________________________
&lt;br&gt;erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;erlang-questions (at) erlang.org
&lt;br&gt;&lt;br&gt;&lt;p&gt;From forum: &lt;a href=&quot;http://old.nabble.com/Erlang-Questions-f14096.html&quot; embed=&quot;fixTarget[14096]&quot; target=&quot;_top&quot; &gt;Erlang Questions&lt;/a&gt;&lt;/p&gt;</content>
	<link rel="alternate" type="text/html" href="http://old.nabble.com/Why-Beam.smp-crashes-when-memory-is-over--tp26257892p26261940.html" />
</entry>

<entry>
	<id>tag:old.nabble.com,2006:post-26261578</id>
	<title>Re: Why Beam.smp crashes when memory is over?</title>
	<published>2009-11-08T21:43:25Z</published>
	<updated>2009-11-08T21:43:25Z</updated>
	<author>
		<name>Tony Arcieri</name>
	</author>
	<content type="html">On Sun, Nov 8, 2009 at 9:56 PM, Max Lapshin &amp;lt;&lt;a href=&quot;http://old.nabble.com/user/SendEmail.jtp?type=post&amp;post=26261578&amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;max.lapshin@...&lt;/a&gt;&amp;gt; wrote:
&lt;br&gt;&lt;br&gt;&amp;gt; I understand your arguments. Yet, It would be great to have
&lt;br&gt;&amp;gt; instrument, that tells supervisor, that child
&lt;br&gt;&amp;gt; is eating too much memory. Look, if we are speaking about reliable
&lt;br&gt;&amp;gt; platform, than it is better to have some
&lt;br&gt;&amp;gt; predictable behaviour.
&lt;br&gt;&amp;gt;
&lt;br&gt;&lt;br&gt;I'm not really sure if we're speaking about the same thing then. &amp;nbsp;Erlang is
&lt;br&gt;best utilized as a stateless platform, with a &amp;quot;fail early fail often&amp;quot;
&lt;br&gt;philosophy, and crashing the entire interpreter in the event of some
&lt;br&gt;underlying problem with the OS fits that entirely. &amp;nbsp;You seem to be seeking a
&lt;br&gt;platform that lets you program defensively, handling errors rather than
&lt;br&gt;crashing and restoring with a clean state. &amp;nbsp;In that regard, Erlang may not
&lt;br&gt;be the best language for you to work with, but then again the problem of
&lt;br&gt;successfully recovering from an out-of-resource condition is an extremely
&lt;br&gt;difficult one to handle well without scrapping it all and trying to restart
&lt;br&gt;with a clean state.
&lt;br&gt;&lt;br&gt;I'm not really sure what alternative behavior you're proposing, either?
&lt;br&gt;&lt;br&gt;-- 
&lt;br&gt;Tony Arcieri
&lt;br&gt;Medioh/Nagravision
&lt;br&gt;&lt;p&gt;From forum: &lt;a href=&quot;http://old.nabble.com/Erlang-Questions-f14096.html&quot; embed=&quot;fixTarget[14096]&quot; target=&quot;_top&quot; &gt;Erlang Questions&lt;/a&gt;&lt;/p&gt;</content>
	<link rel="alternate" type="text/html" href="http://old.nabble.com/Why-Beam.smp-crashes-when-memory-is-over--tp26257892p26261578.html" />
</entry>

<entry>
	<id>tag:old.nabble.com,2006:post-26261387</id>
	<title>Re: Why Beam.smp crashes when memory is over?</title>
	<published>2009-11-08T21:08:58Z</published>
	<updated>2009-11-08T21:08:58Z</updated>
	<author>
		<name>Max Lapshin-2</name>
	</author>
	<content type="html">Look, I have a program, that reads MPEG TS stream from network. There
&lt;br&gt;is some bug in my code
&lt;br&gt;and my ts_lander crashes beam. How is it possible to store state of
&lt;br&gt;external HTTP stream??
&lt;br&gt;&lt;br&gt;If Erlang VM wouldn't crash, but only kill the leaking process, I
&lt;br&gt;could buffer stream in other process and feed
&lt;br&gt;new mpeg ts lander after restart. But it is impossible =(
&lt;br&gt;&lt;br&gt;________________________________________________________________
&lt;br&gt;erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;erlang-questions (at) erlang.org
&lt;br&gt;&lt;br&gt;&lt;p&gt;From forum: &lt;a href=&quot;http://old.nabble.com/Erlang-Questions-f14096.html&quot; embed=&quot;fixTarget[14096]&quot; target=&quot;_top&quot; &gt;Erlang Questions&lt;/a&gt;&lt;/p&gt;</content>
	<link rel="alternate" type="text/html" href="http://old.nabble.com/Why-Beam.smp-crashes-when-memory-is-over--tp26257892p26261387.html" />
</entry>

<entry>
	<id>tag:old.nabble.com,2006:post-26261326</id>
	<title>Re: Why Beam.smp crashes when memory is over?</title>
	<published>2009-11-08T20:56:38Z</published>
	<updated>2009-11-08T20:56:38Z</updated>
	<author>
		<name>Max Lapshin-2</name>
	</author>
	<content type="html">I understand your arguments. Yet, It would be great to have
&lt;br&gt;instrument, that tells supervisor, that child
&lt;br&gt;is eating too much memory. Look, if we are speaking about reliable
&lt;br&gt;platform, than it is better to have some
&lt;br&gt;predictable behaviour.
&lt;br&gt;&lt;br&gt;Perhaps some startup options, like memory threshold for OOM killer?
&lt;br&gt;Supervisor will never grow up to 20 GB,
&lt;br&gt;but our rabbitmq production instance error_logger used to grow up to 20GB+
&lt;br&gt;&lt;br&gt;________________________________________________________________
&lt;br&gt;erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;erlang-questions (at) erlang.org
&lt;br&gt;&lt;br&gt;&lt;p&gt;From forum: &lt;a href=&quot;http://old.nabble.com/Erlang-Questions-f14096.html&quot; embed=&quot;fixTarget[14096]&quot; target=&quot;_top&quot; &gt;Erlang Questions&lt;/a&gt;&lt;/p&gt;</content>
	<link rel="alternate" type="text/html" href="http://old.nabble.com/Why-Beam.smp-crashes-when-memory-is-over--tp26257892p26261326.html" />
</entry>

<entry>
	<id>tag:old.nabble.com,2006:post-26259262</id>
	<title>Re: Dialyzer problem on OSX 10.6 (Erlang R13B02-1)</title>
	<published>2009-11-08T15:35:12Z</published>
	<updated>2009-11-08T15:35:12Z</updated>
	<author>
		<name>Tamas Nagy-3</name>
	</author>
	<content type="html">Hi Kostis,
&lt;br&gt;&lt;br&gt;This is what all I get:
&lt;br&gt;$ dialyzer --build_plt -r /usr/local/Cellar/erlang/R13B02-1/lib/erlang/ 
&lt;br&gt;lib/erts-5.7.3/ebin/ /usr/local/Cellar/erlang/R13B02-1/lib/erlang/lib/ 
&lt;br&gt;kernel-2.13.3/ebin/ /usr/local/Cellar/erlang/R13B02-1/lib/erlang/lib/ 
&lt;br&gt;stdlib-1.16.3/ebin/
&lt;br&gt;&amp;nbsp; &amp;nbsp;Creating PLT /Users/lestat/.dialyzer_plt ...
&lt;br&gt;&lt;br&gt;I will try to rebuild erlang with disabling hipe to see if that helps.
&lt;br&gt;&lt;br&gt;I am happy to run some tests/traces you would like to see the results &amp;nbsp;
&lt;br&gt;of to help.
&lt;br&gt;&lt;br&gt;Regards,
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Tamas
&lt;br&gt;&lt;br&gt;Tamas Nagy
&lt;br&gt;Erlang Training &amp; Consulting
&lt;br&gt;&lt;a href=&quot;http://www.erlang-consulting.com&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang-consulting.com&lt;/a&gt;&lt;br&gt;&lt;br&gt;On 8 Nov 2009, at 19:52, Kostis Sagonas wrote:
&lt;br&gt;&lt;div class='shrinkable-quote'&gt;&lt;br&gt;&amp;gt; Tamas Nagy wrote:
&lt;br&gt;&amp;gt;&amp;gt; Hi,
&lt;br&gt;&amp;gt;&amp;gt; Am I the only one who cannot build a plt under OSX 10.6 in &amp;nbsp;R13B02-1?
&lt;br&gt;&amp;gt;&amp;gt; No matter what applications I specify for the initial plt it just &amp;nbsp;
&lt;br&gt;&amp;gt;&amp;gt; hangs eating processing power but not producing anything.
&lt;br&gt;&amp;gt;&amp;gt; Erlang was installed with homebrew, but that shouldn't matter. Or &amp;nbsp;
&lt;br&gt;&amp;gt;&amp;gt; maybe it does. (beam is compiled for 64 bit)
&lt;br&gt;&amp;gt;&amp;gt; Here is the command I used:
&lt;br&gt;&amp;gt;&amp;gt; dialyzer --build_plt -r /usr/local/Cellar/erlang/R13B02-1/lib/ 
&lt;br&gt;&amp;gt;&amp;gt; erlang/lib/erts-5.7.3/ebin/ /usr/local/Cellar/erlang/R13B02-1/lib/ 
&lt;br&gt;&amp;gt;&amp;gt; erlang/lib/kernel-2.13.3/ebin/ /usr/local/Cellar/erlang/R13B02-1/ 
&lt;br&gt;&amp;gt;&amp;gt; lib/erlang/lib/stdlib-1.16.3/ebin/
&lt;br&gt;&amp;gt;&amp;gt; I gave waiting for it to finish after ~1 hour (on an old type white &amp;nbsp;
&lt;br&gt;&amp;gt;&amp;gt; MacBook (MacBook2,1) with 2GB of RAM).
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; None of the dialyzer developers has access to such a machine to see &amp;nbsp;
&lt;br&gt;&amp;gt; what's happening. &amp;nbsp;Perhaps somebody else in that list might want to &amp;nbsp;
&lt;br&gt;&amp;gt; report whether this is reproducible or not.
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; However, perhaps the following might help: when building the PLT, do &amp;nbsp;
&lt;br&gt;&amp;gt; you see a message:
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; 	Compiling some key modules to native code...
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; If so, can you disable hipe (64-bit Mac is not a platform we have &amp;nbsp;
&lt;br&gt;&amp;gt; ever tested due to no access to such a machine) to see whether this &amp;nbsp;
&lt;br&gt;&amp;gt; may be the culprit?
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; Kostis
&lt;/div&gt;&lt;br&gt;&lt;br&gt;________________________________________________________________
&lt;br&gt;erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;erlang-questions (at) erlang.org
&lt;br&gt;&lt;br&gt;&lt;p&gt;From forum: &lt;a href=&quot;http://old.nabble.com/Erlang-Questions-f14096.html&quot; embed=&quot;fixTarget[14096]&quot; target=&quot;_top&quot; &gt;Erlang Questions&lt;/a&gt;&lt;/p&gt;</content>
	<link rel="alternate" type="text/html" href="http://old.nabble.com/Dialyzer-problem-on-OSX-10.6-%28Erlang-R13B02-1%29-tp26256992p26259262.html" />
</entry>

<entry>
	<id>tag:old.nabble.com,2006:post-26259181</id>
	<title>Re: Why Beam.smp crashes when memory is over?</title>
	<published>2009-11-08T15:25:17Z</published>
	<updated>2009-11-08T15:25:17Z</updated>
	<author>
		<name>Tony Arcieri</name>
	</author>
	<content type="html">On Sun, Nov 8, 2009 at 1:57 PM, Jayson Vantuyl &amp;lt;&lt;a href=&quot;http://old.nabble.com/user/SendEmail.jtp?type=post&amp;post=26259181&amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;kagato@...&lt;/a&gt;&amp;gt; wrote:
&lt;br&gt;&lt;br&gt;&amp;gt; In general, I believe the heartbeat functionality (i.e. erl -heart) is
&lt;br&gt;&amp;gt; supposed to handle this by letting it crash and restarting the whole
&lt;br&gt;&amp;gt; application.
&lt;br&gt;&lt;br&gt;&lt;br&gt;Yes, the design philosophy of Erlang is that your application should be
&lt;br&gt;stateless aside from things residing in dets tables or other external,
&lt;br&gt;stateful resources.
&lt;br&gt;&lt;br&gt;Following the fail early, fail often approach, Erlang recovers from an out
&lt;br&gt;of memory condition by crashing the entire Erlang intrepreter, restarting it
&lt;br&gt;via heartbeat, and reloading your application.
&lt;br&gt;&lt;br&gt;-- 
&lt;br&gt;Tony Arcieri
&lt;br&gt;Medioh/Nagravision
&lt;br&gt;&lt;p&gt;From forum: &lt;a href=&quot;http://old.nabble.com/Erlang-Questions-f14096.html&quot; embed=&quot;fixTarget[14096]&quot; target=&quot;_top&quot; &gt;Erlang Questions&lt;/a&gt;&lt;/p&gt;</content>
	<link rel="alternate" type="text/html" href="http://old.nabble.com/Why-Beam.smp-crashes-when-memory-is-over--tp26257892p26259181.html" />
</entry>

<entry>
	<id>tag:old.nabble.com,2006:post-26259029</id>
	<title>some questions about beepbeep</title>
	<published>2009-11-08T14:04:34Z</published>
	<updated>2009-11-08T14:04:34Z</updated>
	<author>
		<name>Pablo Platt</name>
	</author>
	<content type="html">Hi,
&lt;br&gt;&lt;br&gt;I'm trying to understand beepbeep web framework and ewgi.
&lt;br&gt;I like the ideas behind it.
&lt;br&gt;&lt;br&gt;Is there a mailing list because I couldn't find one.
&lt;br&gt;Does anyone using it and can comment about it?
&lt;br&gt;&lt;br&gt;Does it support arbitrary url dispatching like django and webmachine?
&lt;br&gt;I only saw examples like login_controller that handles /login/some/path
&lt;br&gt;I want to dispatch /admin/pages/15 to the admin_pages_controller.
&lt;br&gt;And sometimes you need to dispatch /user/15/album/12 to album_controller(user, album)
&lt;br&gt;&lt;br&gt;Is there a form validation module?
&lt;br&gt;&lt;br&gt;Thanks
&lt;br&gt;&lt;br&gt;&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;p&gt;From forum: &lt;a href=&quot;http://old.nabble.com/Erlang-Questions-f14096.html&quot; embed=&quot;fixTarget[14096]&quot; target=&quot;_top&quot; &gt;Erlang Questions&lt;/a&gt;&lt;/p&gt;</content>
	<link rel="alternate" type="text/html" href="http://old.nabble.com/some-questions-about-beepbeep-tp26259029p26259029.html" />
</entry>

<entry>
	<id>tag:old.nabble.com,2006:post-26258507</id>
	<title>Re: Exceptions and gen_server</title>
	<published>2009-11-08T14:01:58Z</published>
	<updated>2009-11-08T14:01:58Z</updated>
	<author>
		<name>Anton Krasovsky</name>
	</author>
	<content type="html">Thanks for clarifying that, especially throw vs error part!
&lt;br&gt;&lt;br&gt;&lt;br&gt;Regards,
&lt;br&gt;Anton
&lt;br&gt;&lt;br&gt;On Sun, Nov 8, 2009 at 6:47 PM, Robert Virding &amp;lt;&lt;a href=&quot;http://old.nabble.com/user/SendEmail.jtp?type=post&amp;post=26258507&amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;rvirding@...&lt;/a&gt;&amp;gt; wrote:
&lt;div class='shrinkable-quote'&gt;&lt;br&gt;&amp;gt; There have been a number of different suggestions as to how you could
&lt;br&gt;&amp;gt; program this. I think the main thing for you to decide is *HOW* you want to
&lt;br&gt;&amp;gt; see the error, then it is relatively easy for you to program it. For
&lt;br&gt;&amp;gt; example:
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; - First off: do you want the error to crash the server or not? If so is
&lt;br&gt;&amp;gt; links and exit signals a good enough way for you to see the error?
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; - If the server is to live, how should your app see the error? Two valid
&lt;br&gt;&amp;gt; suggestions which have been given here are:
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; 1. Signal the error using exit/2. This &amp;quot;simulates&amp;quot; the exit signals as if
&lt;br&gt;&amp;gt; the server had crashed.
&lt;br&gt;&amp;gt; 2. Return an error value which either: returns an error value to the caller;
&lt;br&gt;&amp;gt; or generates an error using erlang:error/1. Which is best for you depends on
&lt;br&gt;&amp;gt; your app.
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; All these solutions are easy to program so the main problem is for you to
&lt;br&gt;&amp;gt; decide which is best for your app.
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; One thing I would *NOT* do is use throw/1 to signal error! Throw is for
&lt;br&gt;&amp;gt; non-local returns not errors. Using it for errors will just lead to
&lt;br&gt;&amp;gt; confusion and maybe errors if other parts of app assume it is a non-local
&lt;br&gt;&amp;gt; return. As try can differentiate between throw, exit and error it is
&lt;br&gt;&amp;gt; important that they are used for the right thing.
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; Robert
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; P.S. I would LOVE to change catch now so it only catches throws, but I don't
&lt;br&gt;&amp;gt; think it would be possible. :-(
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; 2009/11/6 Anton Krasovsky &amp;lt;&lt;a href=&quot;http://old.nabble.com/user/SendEmail.jtp?type=post&amp;post=26258507&amp;i=1&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;anton.krasovsky@...&lt;/a&gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt; What would be the standard way of returning/throwing an exception in a
&lt;br&gt;&amp;gt;&amp;gt; result to a gen_server:call?
&lt;br&gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt; Would something like that be reasonable:
&lt;br&gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt; a() -&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt; case gen_server:call(..., a) of
&lt;br&gt;&amp;gt;&amp;gt;    {ok, Value} -&amp;gt; Value;
&lt;br&gt;&amp;gt;&amp;gt;    {error, Error} -&amp;gt; throw({error, Error})
&lt;br&gt;&amp;gt;&amp;gt; end
&lt;br&gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt; and
&lt;br&gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt; handle_call(a, ...) -&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt; case ... of
&lt;br&gt;&amp;gt;&amp;gt;    {ok, Value} -&amp;gt; {reply, {ok, Value} , State};
&lt;br&gt;&amp;gt;&amp;gt;    {error, Error} -&amp;gt; {reply, {error, Error} , State}
&lt;br&gt;&amp;gt;&amp;gt; end
&lt;br&gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt; Regards,
&lt;br&gt;&amp;gt;&amp;gt; Anton
&lt;br&gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;&amp;gt; ________________________________________________________________
&lt;br&gt;&amp;gt;&amp;gt; erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;&amp;gt;&amp;gt; erlang-questions (at) erlang.org
&lt;br&gt;&amp;gt;&amp;gt;
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt;
&lt;/div&gt;&lt;br&gt;________________________________________________________________
&lt;br&gt;erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;erlang-questions (at) erlang.org
&lt;br&gt;&lt;br&gt;&lt;p&gt;From forum: &lt;a href=&quot;http://old.nabble.com/Erlang-Questions-f14096.html&quot; embed=&quot;fixTarget[14096]&quot; target=&quot;_top&quot; &gt;Erlang Questions&lt;/a&gt;&lt;/p&gt;</content>
	<link rel="alternate" type="text/html" href="http://old.nabble.com/Exceptions-and-gen_server-tp26234344p26258507.html" />
</entry>

<entry>
	<id>tag:old.nabble.com,2006:post-26258155</id>
	<title>Re: Why Beam.smp crashes when memory is over?</title>
	<published>2009-11-08T13:26:43Z</published>
	<updated>2009-11-08T13:26:43Z</updated>
	<author>
		<name>Jayson Vantuyl-2</name>
	</author>
	<content type="html">Erlang needs to allocate memory in any number of situations. &amp;nbsp;For &amp;nbsp;
&lt;br&gt;example, assume that Erlang tried to tell your code. &amp;nbsp;Should it &amp;nbsp;
&lt;br&gt;generate a message? &amp;nbsp;Should it call a function? &amp;nbsp;Should it create an &amp;nbsp;
&lt;br&gt;exception? &amp;nbsp;Guess what all of these have in common? &amp;nbsp;They allocate &amp;nbsp;
&lt;br&gt;memory (which isn't there).
&lt;br&gt;&lt;br&gt;You can try to work around this. &amp;nbsp;You can have reserved memory just &amp;nbsp;
&lt;br&gt;for this. &amp;nbsp;However, there's still no clue on where it should happen. &amp;nbsp; 
&lt;br&gt;There is not a very good chance that this error will happen in the &amp;nbsp;
&lt;br&gt;process that has all of the memory allocated. &amp;nbsp;If you take the Linux &amp;nbsp;
&lt;br&gt;OOM approach, you would have to scan all of the processes, weigh them, &amp;nbsp;
&lt;br&gt;mix in some randomness, and message it. &amp;nbsp;There's no memory for it do &amp;nbsp;
&lt;br&gt;think much about the problem. &amp;nbsp;Even if you killed it, that would just &amp;nbsp;
&lt;br&gt;trigger the supervisor to restart it, even though we may not have &amp;nbsp;
&lt;br&gt;actually stopped the memory leak.
&lt;br&gt;&lt;br&gt;Worse, this means that an &amp;quot;out of memory error&amp;quot; can happen anywhere &amp;nbsp;
&lt;br&gt;and must be handled everywhere, even the supervisors. &amp;nbsp;Patching the &amp;nbsp;
&lt;br&gt;supervisors to reliably handle this would be insane. &amp;nbsp;Suddenly, &amp;nbsp;
&lt;br&gt;reliability under load becomes impossible to guarantee.
&lt;br&gt;&lt;br&gt;Even if you emulate Linux and provide an OOM-killer (i.e. kill &amp;nbsp;
&lt;br&gt;processes based on randomness + heuristics to detect runaway &amp;nbsp;
&lt;br&gt;processes), you introduce tons of random behavior into the VM, when a &amp;nbsp;
&lt;br&gt;VM restart would be recognizable, loggable, and generally easier to &amp;nbsp;
&lt;br&gt;debug.
&lt;br&gt;&lt;br&gt;Exposing those errors creates an ugly situation. &amp;nbsp;This extra error &amp;nbsp;
&lt;br&gt;handling would cause an explosion of corner cases, decreases in &amp;nbsp;
&lt;br&gt;reliability, and volumes of code (i.e. where bugs live). &amp;nbsp;Inside of &amp;nbsp;
&lt;br&gt;Erlang, the philosophy is to use supervisors and writing daemons to be &amp;nbsp;
&lt;br&gt;able to recover from a restart. &amp;nbsp;Heartbeat gives the same behavior for &amp;nbsp;
&lt;br&gt;the entire VM. &amp;nbsp;It's a philosophical design choice to try to handle &amp;nbsp;
&lt;br&gt;critical faults rather than mask critical faults. &amp;nbsp;It's really better &amp;nbsp;
&lt;br&gt;than trying to handle this.
&lt;br&gt;&lt;br&gt;It's seems obvious that there should be a better way to handle OOM, &amp;nbsp;
&lt;br&gt;but it's is all devilishly difficult to do in any meaningfully &amp;nbsp;
&lt;br&gt;portable (or useful) way.
&lt;br&gt;&lt;br&gt;On Nov 8, 2009, at 1:02 PM, Max Lapshin wrote:
&lt;br&gt;&lt;div class='shrinkable-quote'&gt;&lt;br&gt;&amp;gt; On Sun, Nov 8, 2009 at 11:57 PM, Jayson Vantuyl &amp;lt;&lt;a href=&quot;http://old.nabble.com/user/SendEmail.jtp?type=post&amp;post=26258155&amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;kagato@...&lt;/a&gt;&amp;gt; &amp;nbsp;
&lt;br&gt;&amp;gt; wrote:
&lt;br&gt;&amp;gt;&amp;gt; From within Erlang, I don't believe so.
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; And what are the problems? OS never crashes when memory is over, OOM
&lt;br&gt;&amp;gt; killer does the job well.
&lt;br&gt;&amp;gt; Why should die Erlang VM?
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; ________________________________________________________________
&lt;br&gt;&amp;gt; erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;&amp;gt; erlang-questions (at) erlang.org
&lt;br&gt;&amp;gt;
&lt;/div&gt;&lt;br&gt;-- 
&lt;br&gt;Jayson Vantuyl
&lt;br&gt;&lt;a href=&quot;http://old.nabble.com/user/SendEmail.jtp?type=post&amp;post=26258155&amp;i=1&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;kagato@...&lt;/a&gt;
&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;________________________________________________________________
&lt;br&gt;erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;erlang-questions (at) erlang.org
&lt;br&gt;&lt;br&gt;&lt;p&gt;From forum: &lt;a href=&quot;http://old.nabble.com/Erlang-Questions-f14096.html&quot; embed=&quot;fixTarget[14096]&quot; target=&quot;_top&quot; &gt;Erlang Questions&lt;/a&gt;&lt;/p&gt;</content>
	<link rel="alternate" type="text/html" href="http://old.nabble.com/Why-Beam.smp-crashes-when-memory-is-over--tp26257892p26258155.html" />
</entry>

<entry>
	<id>tag:old.nabble.com,2006:post-26257949</id>
	<title>Re: Why Beam.smp crashes when memory is over?</title>
	<published>2009-11-08T13:02:31Z</published>
	<updated>2009-11-08T13:02:31Z</updated>
	<author>
		<name>Max Lapshin-2</name>
	</author>
	<content type="html">On Sun, Nov 8, 2009 at 11:57 PM, Jayson Vantuyl &amp;lt;&lt;a href=&quot;http://old.nabble.com/user/SendEmail.jtp?type=post&amp;post=26257949&amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;kagato@...&lt;/a&gt;&amp;gt; wrote:
&lt;br&gt;&amp;gt; From within Erlang, I don't believe so.
&lt;br&gt;&lt;br&gt;And what are the problems? OS never crashes when memory is over, OOM
&lt;br&gt;killer does the job well.
&lt;br&gt;Why should die Erlang VM?
&lt;br&gt;&lt;br&gt;________________________________________________________________
&lt;br&gt;erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;erlang-questions (at) erlang.org
&lt;br&gt;&lt;br&gt;&lt;p&gt;From forum: &lt;a href=&quot;http://old.nabble.com/Erlang-Questions-f14096.html&quot; embed=&quot;fixTarget[14096]&quot; target=&quot;_top&quot; &gt;Erlang Questions&lt;/a&gt;&lt;/p&gt;</content>
	<link rel="alternate" type="text/html" href="http://old.nabble.com/Why-Beam.smp-crashes-when-memory-is-over--tp26257892p26257949.html" />
</entry>

<entry>
	<id>tag:old.nabble.com,2006:post-26257923</id>
	<title>Re: Why Beam.smp crashes when memory is over?</title>
	<published>2009-11-08T12:57:45Z</published>
	<updated>2009-11-08T12:57:45Z</updated>
	<author>
		<name>Jayson Vantuyl-2</name>
	</author>
	<content type="html">&amp;nbsp;From within Erlang, I don't believe so.
&lt;br&gt;&lt;br&gt;&amp;nbsp;From outside, maybe, with the right debugger.
&lt;br&gt;&lt;br&gt;In general, I believe the heartbeat functionality (i.e. erl -heart) is &amp;nbsp;
&lt;br&gt;supposed to handle this by letting it crash and restarting the whole &amp;nbsp;
&lt;br&gt;application.
&lt;br&gt;&lt;br&gt;On Nov 8, 2009, at 12:56 PM, Max Lapshin wrote:
&lt;br&gt;&lt;div class='shrinkable-quote'&gt;&lt;br&gt;&amp;gt; Why does Erlang crashes, when physical memory is over?
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; Error is:
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; beam.smp(5454,0xb01aa000) malloc: *** mmap(size=41943040) failed &amp;nbsp;
&lt;br&gt;&amp;gt; (error code=12)
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; *** error: can't allocate region
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; *** set a breakpoint in
&lt;br&gt;&amp;gt; malloc_error_break to debug
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; Isn't it possible to intercept this error and stop erlang process,
&lt;br&gt;&amp;gt; that requests memory?
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; ________________________________________________________________
&lt;br&gt;&amp;gt; erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;&amp;gt; erlang-questions (at) erlang.org
&lt;/div&gt;&lt;br&gt;&lt;br&gt;-- 
&lt;br&gt;Jayson Vantuyl
&lt;br&gt;&lt;a href=&quot;http://old.nabble.com/user/SendEmail.jtp?type=post&amp;post=26257923&amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;kagato@...&lt;/a&gt;
&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;p&gt;From forum: &lt;a href=&quot;http://old.nabble.com/Erlang-Questions-f14096.html&quot; embed=&quot;fixTarget[14096]&quot; target=&quot;_top&quot; &gt;Erlang Questions&lt;/a&gt;&lt;/p&gt;</content>
	<link rel="alternate" type="text/html" href="http://old.nabble.com/Why-Beam.smp-crashes-when-memory-is-over--tp26257892p26257923.html" />
</entry>

<entry>
	<id>tag:old.nabble.com,2006:post-26257892</id>
	<title>Why Beam.smp crashes when memory is over?</title>
	<published>2009-11-08T12:56:05Z</published>
	<updated>2009-11-08T12:56:05Z</updated>
	<author>
		<name>Max Lapshin-2</name>
	</author>
	<content type="html">Why does Erlang crashes, when physical memory is over?
&lt;br&gt;&lt;br&gt;Error is:
&lt;br&gt;&lt;br&gt;beam.smp(5454,0xb01aa000) malloc: *** mmap(size=41943040) failed (error code=12)
&lt;br&gt;&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;*** error: can't allocate region
&lt;br&gt;&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;*** set a breakpoint in
&lt;br&gt;malloc_error_break to debug
&lt;br&gt;&lt;br&gt;&lt;br&gt;Isn't it possible to intercept this error and stop erlang process,
&lt;br&gt;that requests memory?
&lt;br&gt;&lt;br&gt;________________________________________________________________
&lt;br&gt;erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;erlang-questions (at) erlang.org
&lt;br&gt;&lt;br&gt;&lt;p&gt;From forum: &lt;a href=&quot;http://old.nabble.com/Erlang-Questions-f14096.html&quot; embed=&quot;fixTarget[14096]&quot; target=&quot;_top&quot; &gt;Erlang Questions&lt;/a&gt;&lt;/p&gt;</content>
	<link rel="alternate" type="text/html" href="http://old.nabble.com/Why-Beam.smp-crashes-when-memory-is-over--tp26257892p26257892.html" />
</entry>

<entry>
	<id>tag:old.nabble.com,2006:post-26257285</id>
	<title>Re: Dialyzer problem on OSX 10.6 (Erlang R13B02-1)</title>
	<published>2009-11-08T11:52:12Z</published>
	<updated>2009-11-08T11:52:12Z</updated>
	<author>
		<name>Kostis Sagonas-2</name>
	</author>
	<content type="html">Tamas Nagy wrote:
&lt;div class='shrinkable-quote'&gt;&lt;br&gt;&amp;gt; Hi,
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; Am I the only one who cannot build a plt under OSX 10.6 in &amp;nbsp;R13B02-1?
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; No matter what applications I specify for the initial plt it just hangs 
&lt;br&gt;&amp;gt; eating processing power but not producing anything.
&lt;br&gt;&amp;gt; Erlang was installed with homebrew, but that shouldn't matter. Or maybe 
&lt;br&gt;&amp;gt; it does. (beam is compiled for 64 bit)
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; Here is the command I used:
&lt;br&gt;&amp;gt; dialyzer --build_plt -r 
&lt;br&gt;&amp;gt; /usr/local/Cellar/erlang/R13B02-1/lib/erlang/lib/erts-5.7.3/ebin/ 
&lt;br&gt;&amp;gt; /usr/local/Cellar/erlang/R13B02-1/lib/erlang/lib/kernel-2.13.3/ebin/ 
&lt;br&gt;&amp;gt; /usr/local/Cellar/erlang/R13B02-1/lib/erlang/lib/stdlib-1.16.3/ebin/
&lt;br&gt;&amp;gt; 
&lt;br&gt;&amp;gt; I gave waiting for it to finish after ~1 hour (on an old type white 
&lt;br&gt;&amp;gt; MacBook (MacBook2,1) with 2GB of RAM).
&lt;/div&gt;&lt;br&gt;None of the dialyzer developers has access to such a machine to see 
&lt;br&gt;what's happening. &amp;nbsp;Perhaps somebody else in that list might want to 
&lt;br&gt;report whether this is reproducible or not.
&lt;br&gt;&lt;br&gt;However, perhaps the following might help: when building the PLT, do you 
&lt;br&gt;see a message:
&lt;br&gt;&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Compiling some key modules to native code...
&lt;br&gt;&lt;br&gt;If so, can you disable hipe (64-bit Mac is not a platform we have ever 
&lt;br&gt;tested due to no access to such a machine) to see whether this may be 
&lt;br&gt;the culprit?
&lt;br&gt;&lt;br&gt;Kostis
&lt;br&gt;&lt;br&gt;________________________________________________________________
&lt;br&gt;erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;erlang-questions (at) erlang.org
&lt;br&gt;&lt;br&gt;&lt;p&gt;From forum: &lt;a href=&quot;http://old.nabble.com/Erlang-Questions-f14096.html&quot; embed=&quot;fixTarget[14096]&quot; target=&quot;_top&quot; &gt;Erlang Questions&lt;/a&gt;&lt;/p&gt;</content>
	<link rel="alternate" type="text/html" href="http://old.nabble.com/Dialyzer-problem-on-OSX-10.6-%28Erlang-R13B02-1%29-tp26256992p26257285.html" />
</entry>

<entry>
	<id>tag:old.nabble.com,2006:post-26256992</id>
	<title>Dialyzer problem on OSX 10.6 (Erlang R13B02-1)</title>
	<published>2009-11-08T11:23:36Z</published>
	<updated>2009-11-08T11:23:36Z</updated>
	<author>
		<name>Tamas Nagy-3</name>
	</author>
	<content type="html">Hi,
&lt;br&gt;&lt;br&gt;Am I the only one who cannot build a plt under OSX 10.6 in &amp;nbsp;R13B02-1?
&lt;br&gt;&lt;br&gt;No matter what applications I specify for the initial plt it just &amp;nbsp;
&lt;br&gt;hangs eating processing power but not producing anything.
&lt;br&gt;Erlang was installed with homebrew, but that shouldn't matter. Or &amp;nbsp;
&lt;br&gt;maybe it does. (beam is compiled for 64 bit)
&lt;br&gt;&lt;br&gt;Here is the command I used:
&lt;br&gt;dialyzer --build_plt -r /usr/local/Cellar/erlang/R13B02-1/lib/erlang/ 
&lt;br&gt;lib/erts-5.7.3/ebin/ /usr/local/Cellar/erlang/R13B02-1/lib/erlang/lib/ 
&lt;br&gt;kernel-2.13.3/ebin/ /usr/local/Cellar/erlang/R13B02-1/lib/erlang/lib/ 
&lt;br&gt;stdlib-1.16.3/ebin/
&lt;br&gt;&lt;br&gt;I gave waiting for it to finish after ~1 hour (on an old type white &amp;nbsp;
&lt;br&gt;MacBook (MacBook2,1) with 2GB of RAM).
&lt;br&gt;&lt;br&gt;The info I get from the dialyzer seems to suggest that it still &amp;nbsp;
&lt;br&gt;assumes that erts version is 5.7 can the problem be around there?
&lt;br&gt;&lt;br&gt;&amp;nbsp; &amp;nbsp;Checking whether the PLT /Users/lestat/.dialyzer_plt is up-to- 
&lt;br&gt;date...dialyzer: Could not find the PLT: /Users/lestat/.dialyzer_plt
&lt;br&gt;Use the options:
&lt;br&gt;&amp;nbsp; &amp;nbsp; --build_plt &amp;nbsp; to build a new one; or
&lt;br&gt;&amp;nbsp; &amp;nbsp; --add_to_plt &amp;nbsp;to add to an existing PLT
&lt;br&gt;For example (in an installed Erlang/OTP system):
&lt;br&gt;&amp;nbsp; &amp;nbsp; dialyzer --build_plt -r $ERL_TOP/lib/erts-5.7/ebin\
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $ERL_TOP/lib/kernel/ebin\
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $ERL_TOP/lib/stdlib/ebin\
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $ERL_TOP/lib/mnesia/ebin\
&lt;br&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $ERL_TOP/lib/crypto/ebin
&lt;br&gt;Note that building a PLT such as the above may take 20 mins or so
&lt;br&gt;&lt;br&gt;If I try to use a plt generated on another machine (on Ubuntu there &amp;nbsp;
&lt;br&gt;does not seem to be a problem) it seems to work.
&lt;br&gt;&lt;br&gt;P.S.: I've tried rebuilding erlang with and without disable-debug flag &amp;nbsp;
&lt;br&gt;as well to no avail.
&lt;br&gt;&lt;br&gt;Tamas Nagy
&lt;br&gt;Erlang Training &amp; Consulting
&lt;br&gt;&lt;a href=&quot;http://www.erlang-consulting.com&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang-consulting.com&lt;/a&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;________________________________________________________________
&lt;br&gt;erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;erlang-questions (at) erlang.org
&lt;br&gt;&lt;br&gt;&lt;p&gt;From forum: &lt;a href=&quot;http://old.nabble.com/Erlang-Questions-f14096.html&quot; embed=&quot;fixTarget[14096]&quot; target=&quot;_top&quot; &gt;Erlang Questions&lt;/a&gt;&lt;/p&gt;</content>
	<link rel="alternate" type="text/html" href="http://old.nabble.com/Dialyzer-problem-on-OSX-10.6-%28Erlang-R13B02-1%29-tp26256992p26256992.html" />
</entry>

<entry>
	<id>tag:old.nabble.com,2006:post-26256657</id>
	<title>Re: Exceptions and gen_server</title>
	<published>2009-11-08T10:47:29Z</published>
	<updated>2009-11-08T10:47:29Z</updated>
	<author>
		<name>Robert Virding</name>
	</author>
	<content type="html">There have been a number of different suggestions as to how you could
&lt;br&gt;program this. I think the main thing for you to decide is *HOW* you want to
&lt;br&gt;see the error, then it is relatively easy for you to program it. For
&lt;br&gt;example:
&lt;br&gt;&lt;br&gt;- First off: do you want the error to crash the server or not? If so is
&lt;br&gt;links and exit signals a good enough way for you to see the error?
&lt;br&gt;&lt;br&gt;- If the server is to live, how should your app see the error? Two valid
&lt;br&gt;suggestions which have been given here are:
&lt;br&gt;&lt;br&gt;1. Signal the error using exit/2. This &amp;quot;simulates&amp;quot; the exit signals as if
&lt;br&gt;the server had crashed.
&lt;br&gt;2. Return an error value which either: returns an error value to the caller;
&lt;br&gt;or generates an error using erlang:error/1. Which is best for you depends on
&lt;br&gt;your app.
&lt;br&gt;&lt;br&gt;All these solutions are easy to program so the main problem is for you to
&lt;br&gt;decide which is best for your app.
&lt;br&gt;&lt;br&gt;One thing I would *NOT* do is use throw/1 to signal error! Throw is for
&lt;br&gt;non-local returns not errors. Using it for errors will just lead to
&lt;br&gt;confusion and maybe errors if other parts of app assume it is a non-local
&lt;br&gt;return. As try can differentiate between throw, exit and error it is
&lt;br&gt;important that they are used for the right thing.
&lt;br&gt;&lt;br&gt;Robert
&lt;br&gt;&lt;br&gt;P.S. I would LOVE to change catch now so it only catches throws, but I don't
&lt;br&gt;think it would be possible. :-(
&lt;br&gt;&lt;br&gt;2009/11/6 Anton Krasovsky &amp;lt;&lt;a href=&quot;http://old.nabble.com/user/SendEmail.jtp?type=post&amp;post=26256657&amp;i=0&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;anton.krasovsky@...&lt;/a&gt;&amp;gt;
&lt;br&gt;&lt;div class='shrinkable-quote'&gt;&lt;br&gt;&amp;gt; What would be the standard way of returning/throwing an exception in a
&lt;br&gt;&amp;gt; result to a gen_server:call?
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; Would something like that be reasonable:
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; a() -&amp;gt;
&lt;br&gt;&amp;gt; case gen_server:call(..., a) of
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp;{ok, Value} -&amp;gt; Value;
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp;{error, Error} -&amp;gt; throw({error, Error})
&lt;br&gt;&amp;gt; end
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; and
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; handle_call(a, ...) -&amp;gt;
&lt;br&gt;&amp;gt; case ... of
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp;{ok, Value} -&amp;gt; {reply, {ok, Value} , State};
&lt;br&gt;&amp;gt; &amp;nbsp; &amp;nbsp;{error, Error} -&amp;gt; {reply, {error, Error} , State}
&lt;br&gt;&amp;gt; end
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; Regards,
&lt;br&gt;&amp;gt; Anton
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt; ________________________________________________________________
&lt;br&gt;&amp;gt; erlang-questions mailing list. See &lt;a href=&quot;http://www.erlang.org/faq.html&quot; target=&quot;_top&quot; rel=&quot;nofollow&quot;&gt;http://www.erlang.org/faq.html&lt;/a&gt;&lt;br&gt;&amp;gt; erlang-questions (at) erlang.org
&lt;br&gt;&amp;gt;
&lt;br&gt;&amp;gt;
&lt;br&gt;&lt;/div&gt;&lt;p&gt;From forum: &lt;a href=&quot;http://old.nabble.com/Erlang-Questions-f14096.html&quot; embed=&quot;fixTarget[14096]&quot; target=&quot;_top&quot; &gt;Erlang Questions&lt;/a&gt;&lt;/p&gt;</content>
	<link rel="alternate" type="text/html" href="http://old.nabble.com/Exceptions-and-gen_server-tp26234344p26256657.html" />
</entry>

</feed>
