<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.0.12-alpha" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Erlang processes vs. Java threads</title>
	<link>http://www.lshift.net/blog/2006/09/10/erlang-processes-vs-java-threads</link>
	<description>What happens at LShift</description>
	<pubDate>Sat, 11 Oct 2008 23:35:11 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.12-alpha</generator>

	<item>
		<title>by: tonyg</title>
		<link>http://www.lshift.net/blog/2006/09/10/erlang-processes-vs-java-threads#comment-108442</link>
		<pubDate>Thu, 03 Jul 2008 16:44:33 +0000</pubDate>
		<guid>http://www.lshift.net/blog/2006/09/10/erlang-processes-vs-java-threads#comment-108442</guid>
					<description>&lt;p&gt;((I accidentally deleted a bunch of comments I didn't mean to delete today, so I'm having to repost them manually:))&lt;/p&gt;

&lt;p&gt;VB wrote:&lt;/p&gt;

&lt;p&gt;To ChrisH:&lt;/p&gt;

&lt;p&gt;“Thousands of active agents interacting with each other” so what, no problem, don’t create an OS thread per agent, Erlang isn’t !!”&lt;/p&gt;

&lt;p&gt;How would you model the agent then? With a state machine?
This is going to be a hell.&lt;/p&gt;

&lt;p&gt;By the way, Erlang is not about green threads but about share-nothing, side-effectlessness, concurrency and composability. It’s just better suitable for concurrency than Java, that’s it.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>((I accidentally deleted a bunch of comments I didn&#8217;t mean to delete today, so I&#8217;m having to repost them manually:))</p>
<p>VB wrote:</p>
<p>To ChrisH:</p>
<p>“Thousands of active agents interacting with each other” so what, no problem, don’t create an OS thread per agent, Erlang isn’t !!”</p>
<p>How would you model the agent then? With a state machine?<br />
This is going to be a hell.</p>
<p>By the way, Erlang is not about green threads but about share-nothing, side-effectlessness, concurrency and composability. It’s just better suitable for concurrency than Java, that’s it.</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: ChrisH</title>
		<link>http://www.lshift.net/blog/2006/09/10/erlang-processes-vs-java-threads#comment-89569</link>
		<pubDate>Thu, 03 Apr 2008 13:43:22 +0000</pubDate>
		<guid>http://www.lshift.net/blog/2006/09/10/erlang-processes-vs-java-threads#comment-89569</guid>
					<description>&lt;p&gt;Denis is correct, Tony none of your arguments hold water.&lt;/p&gt;

&lt;p&gt;Your basically arguing green threads vs native threads not Java vs Erlang, both of which I believe come in various threading flavours.&lt;/p&gt;

&lt;p&gt;The thread limits, memory etc is an OS thing , not Java vary your JVM you'll get different results e.g. an early JVM will most likely  green thread and with bad coding like yours possibly beat the new JVM on a single core .&lt;/p&gt;

&lt;p&gt;Yes a badly written Java app, particularly on a very old JVM (not too old mind as the very old ones tend to be green threaded and that would give Java a chance) on a single core machine can be beaten by a green thread App even Visual Basic .&lt;/p&gt;

&lt;p&gt;... but surprise if you use modern Java or allow threading pooling and/or combine with multicore and your Erlang looks like its in big trouble.&lt;/p&gt;

&lt;p&gt;"Thousands of active agents interacting with each other" so what, no problem, don't create an OS thread per agent, Erlang isn't !! it just makes a representation of a thread, Java can do that.&lt;/p&gt;

&lt;p&gt;PS Note in no way am I commenting on the elegance of the languages purely on the benchmarks.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Denis is correct, Tony none of your arguments hold water.</p>
<p>Your basically arguing green threads vs native threads not Java vs Erlang, both of which I believe come in various threading flavours.</p>
<p>The thread limits, memory etc is an OS thing , not Java vary your JVM you&#8217;ll get different results e.g. an early JVM will most likely  green thread and with bad coding like yours possibly beat the new JVM on a single core .</p>
<p>Yes a badly written Java app, particularly on a very old JVM (not too old mind as the very old ones tend to be green threaded and that would give Java a chance) on a single core machine can be beaten by a green thread App even Visual Basic .</p>
<p>&#8230; but surprise if you use modern Java or allow threading pooling and/or combine with multicore and your Erlang looks like its in big trouble.</p>
<p>&#8220;Thousands of active agents interacting with each other&#8221; so what, no problem, don&#8217;t create an OS thread per agent, Erlang isn&#8217;t !! it just makes a representation of a thread, Java can do that.</p>
<p>PS Note in no way am I commenting on the elegance of the languages purely on the benchmarks.</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Rodrigo B. de Oliveira</title>
		<link>http://www.lshift.net/blog/2006/09/10/erlang-processes-vs-java-threads#comment-88954</link>
		<pubDate>Fri, 28 Mar 2008 19:55:09 +0000</pubDate>
		<guid>http://www.lshift.net/blog/2006/09/10/erlang-processes-vs-java-threads#comment-88954</guid>
					<description>&lt;p&gt;@Denis, think simulation. Thousands of active agents interacting with each other.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>@Denis, think simulation. Thousands of active agents interacting with each other.</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Denis</title>
		<link>http://www.lshift.net/blog/2006/09/10/erlang-processes-vs-java-threads#comment-23459</link>
		<pubDate>Thu, 14 Dec 2006 13:29:05 +0000</pubDate>
		<guid>http://www.lshift.net/blog/2006/09/10/erlang-processes-vs-java-threads#comment-23459</guid>
					<description>&lt;p&gt;Tonyg, I got your point, but most of examples where we need to run 100k of concurrent activities are invented around slow IO. The most frequent case is the web server with massive number of keepalive concurrent users.&lt;/p&gt;

&lt;p&gt;Such tasks are solved in Java by using the non blocking IO and a single thread which does actual processing. With modern framework such progamming style is either completely transparent to program or very simple to use. See AsyncWeb &#38; the Grizzly/Glassfish.&lt;/p&gt;

&lt;p&gt;Also, I think that the thread pool is extremally helpful &#38; provides simplicity identical to thread spawning in 90% of cases.&lt;/p&gt;

&lt;p&gt;Actually Java used to had a number of lightweighted thread implementations like famous green threads or JRockit thinthreads. All of them was invented to cope slow Linux threading before kernel 2.6 &#38; NPTL and dropped immediately after kernel 2.6 was adopted. Simply because there are no real business cases for Java there such kind of lightweight processes are useful.&lt;/p&gt;

&lt;p&gt;Could you please give me the real world sample of task which is not a subject to solve via simple thread pool and is not IO bound?&lt;/p&gt;

&lt;p&gt;Also, why Erlang has slow message passing in SMP configuration? The reason is the lack of good scheduler which can't place dependant processes in the single OS thread?&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Tonyg, I got your point, but most of examples where we need to run 100k of concurrent activities are invented around slow IO. The most frequent case is the web server with massive number of keepalive concurrent users.</p>
<p>Such tasks are solved in Java by using the non blocking IO and a single thread which does actual processing. With modern framework such progamming style is either completely transparent to program or very simple to use. See AsyncWeb &amp; the Grizzly/Glassfish.</p>
<p>Also, I think that the thread pool is extremally helpful &amp; provides simplicity identical to thread spawning in 90% of cases.</p>
<p>Actually Java used to had a number of lightweighted thread implementations like famous green threads or JRockit thinthreads. All of them was invented to cope slow Linux threading before kernel 2.6 &amp; NPTL and dropped immediately after kernel 2.6 was adopted. Simply because there are no real business cases for Java there such kind of lightweight processes are useful.</p>
<p>Could you please give me the real world sample of task which is not a subject to solve via simple thread pool and is not IO bound?</p>
<p>Also, why Erlang has slow message passing in SMP configuration? The reason is the lack of good scheduler which can&#8217;t place dependant processes in the single OS thread?</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: tonyg</title>
		<link>http://www.lshift.net/blog/2006/09/10/erlang-processes-vs-java-threads#comment-23444</link>
		<pubDate>Thu, 14 Dec 2006 12:49:47 +0000</pubDate>
		<guid>http://www.lshift.net/blog/2006/09/10/erlang-processes-vs-java-threads#comment-23444</guid>
					<description>&lt;p&gt;Denis, see my comment number 7 above. Beware of the Turing tarpit! If you need to support, say, 100,000 genuinely concurrent activities, you have two options: using the threads provided by the language, or modelling threads using a hand-rolled CPS transform. Java's native threads don't scale for one reason (heavyweight JVM implementation), as we see above for one axis of measurement, and pseudothreading-by-CPS doesn't scale for another (human fallibility, poor compositionality). The test I wrote was a simple way of gauging how an Erlangish style of programming might perform in Java. The point I'm interested in is that Erlang's lightweight threads make programming highly concurrent systems natural, in a way that Java's threads never will (modulo possible-but-unlikely wholesale revisions of the language).&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Denis, see my comment number 7 above. Beware of the Turing tarpit! If you need to support, say, 100,000 genuinely concurrent activities, you have two options: using the threads provided by the language, or modelling threads using a hand-rolled CPS transform. Java&#8217;s native threads don&#8217;t scale for one reason (heavyweight JVM implementation), as we see above for one axis of measurement, and pseudothreading-by-CPS doesn&#8217;t scale for another (human fallibility, poor compositionality). The test I wrote was a simple way of gauging how an Erlangish style of programming might perform in Java. The point I&#8217;m interested in is that Erlang&#8217;s lightweight threads make programming highly concurrent systems natural, in a way that Java&#8217;s threads never will (modulo possible-but-unlikely wholesale revisions of the language).</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Denis</title>
		<link>http://www.lshift.net/blog/2006/09/10/erlang-processes-vs-java-threads#comment-23412</link>
		<pubDate>Thu, 14 Dec 2006 10:10:15 +0000</pubDate>
		<guid>http://www.lshift.net/blog/2006/09/10/erlang-processes-vs-java-threads#comment-23412</guid>
					<description>&lt;p&gt;Tonyg, yeah, I do understand that. But is it required (by some good reason) to create new threads each time?&lt;/p&gt;

&lt;p&gt;I mean that in Java in order to achieve high performance developers do use pool of workers which actually does the same work as if there will be a lot of threads spawned.&lt;/p&gt;

&lt;p&gt;I believe that there is no practical task which could not be solved with pool of workers, if the worker is blocked by network IO we can always use the non-blocking IO.&lt;/p&gt;

&lt;p&gt;So, I mean that actually Java can do better then Erlang on concurrent programming if it's used properly, keeping in mind it's limitations and advantages.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Tonyg, yeah, I do understand that. But is it required (by some good reason) to create new threads each time?</p>
<p>I mean that in Java in order to achieve high performance developers do use pool of workers which actually does the same work as if there will be a lot of threads spawned.</p>
<p>I believe that there is no practical task which could not be solved with pool of workers, if the worker is blocked by network IO we can always use the non-blocking IO.</p>
<p>So, I mean that actually Java can do better then Erlang on concurrent programming if it&#8217;s used properly, keeping in mind it&#8217;s limitations and advantages.</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: tonyg</title>
		<link>http://www.lshift.net/blog/2006/09/10/erlang-processes-vs-java-threads#comment-22904</link>
		<pubDate>Wed, 13 Dec 2006 18:46:38 +0000</pubDate>
		<guid>http://www.lshift.net/blog/2006/09/10/erlang-processes-vs-java-threads#comment-22904</guid>
					<description>&lt;p&gt;Denis, you've missed the point: I'm measuring how many thread creations and teardowns per second the system tops out at, not how many messages per second the system can send with a fixed pool of workers. Note the indirectness of the recursion in the run() method - it spawns a whole new thread for each step of the recursion.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Denis, you&#8217;ve missed the point: I&#8217;m measuring how many thread creations and teardowns per second the system tops out at, not how many messages per second the system can send with a fixed pool of workers. Note the indirectness of the recursion in the run() method - it spawns a whole new thread for each step of the recursion.</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Denis</title>
		<link>http://www.lshift.net/blog/2006/09/10/erlang-processes-vs-java-threads#comment-22846</link>
		<pubDate>Wed, 13 Dec 2006 15:35:22 +0000</pubDate>
		<guid>http://www.lshift.net/blog/2006/09/10/erlang-processes-vs-java-threads#comment-22846</guid>
					<description>&lt;p&gt;Come on, no Java developer writes code like that. &lt;/p&gt;

&lt;p&gt;import java.util.concurrent.*;&lt;/p&gt;

&lt;p&gt;public class Test25 extends Thread {
    public static Executor executor;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;public static void main(String[] args) throws InterruptedException {
    int M = Integer.parseInt(args.length &#62; 0 ? args[0] : "1");
    int N = Integer.parseInt(args.length &#62; 1 ? args[1] : "1000000");
    executor = Executors.newFixedThreadPool(M);
    int NpM = N / M;
    BlockingQueue queue = new ArrayBlockingQueue(1000 * 1000);
    long startTime = System.currentTimeMillis();
    for (int i = 0; i &#60; M; i++) executor.execute(new Body(queue, NpM));
    for (int i = 0; i &#60; N; i++) queue.take();
    long stopTime = System.currentTimeMillis();
    System.out.println((NpM * M) / ((stopTime - startTime) / 1000.0));
}

public static class Body implements Runnable {
    BlockingQueue queue;
    int count;
    public Body(BlockingQueue queue, int count) {
        this.queue = queue; this.count = count;
    }
    public void run() {
        try {
            for (int i = 0; i &#60; count; i++) queue.put(this);
        } catch (InterruptedException ex) {
            ex.printStackTrace();
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;Makes 1.5mln/sec on 3ghz P4 (windows xp)
It uses a thread pool and a loop instead of recursion.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Come on, no Java developer writes code like that. </p>
<p>import java.util.concurrent.*;</p>
<p>public class Test25 extends Thread {<br />
    public static Executor executor;</p>
<pre><code>public static void main(String[] args) throws InterruptedException {
    int M = Integer.parseInt(args.length &gt; 0 ? args[0] : "1");
    int N = Integer.parseInt(args.length &gt; 1 ? args[1] : "1000000");
    executor = Executors.newFixedThreadPool(M);
    int NpM = N / M;
    BlockingQueue queue = new ArrayBlockingQueue(1000 * 1000);
    long startTime = System.currentTimeMillis();
    for (int i = 0; i &lt; M; i++) executor.execute(new Body(queue, NpM));
    for (int i = 0; i &lt; N; i++) queue.take();
    long stopTime = System.currentTimeMillis();
    System.out.println((NpM * M) / ((stopTime - startTime) / 1000.0));
}

public static class Body implements Runnable {
    BlockingQueue queue;
    int count;
    public Body(BlockingQueue queue, int count) {
        this.queue = queue; this.count = count;
    }
    public void run() {
        try {
            for (int i = 0; i &lt; count; i++) queue.put(this);
        } catch (InterruptedException ex) {
            ex.printStackTrace();
        }
    }
}
</code></pre>
<p>}</p>
<p>Makes 1.5mln/sec on 3ghz P4 (windows xp)<br />
It uses a thread pool and a loop instead of recursion.</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Bryce Leo</title>
		<link>http://www.lshift.net/blog/2006/09/10/erlang-processes-vs-java-threads#comment-11341</link>
		<pubDate>Tue, 10 Oct 2006 05:27:43 +0000</pubDate>
		<guid>http://www.lshift.net/blog/2006/09/10/erlang-processes-vs-java-threads#comment-11341</guid>
					<description>&lt;p&gt;&lt;em&gt;blink&lt;/em&gt; &lt;em&gt;blink&lt;/em&gt;... &lt;em&gt;blink&lt;/em&gt;
Sun Workstation, Opteron 150, 1gig ram, Redhat
Java:27055
Erlang. 1.03332e+6&lt;/p&gt;

&lt;p&gt;1 million something?&lt;/p&gt;

&lt;p&gt;Goodness.... And you'd figure that a Sun workstation would be where java would somehow be champ.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p><em>blink</em> <em>blink</em>&#8230; <em>blink</em><br />
Sun Workstation, Opteron 150, 1gig ram, Redhat<br />
Java:27055<br />
Erlang. 1.03332e+6</p>
<p>1 million something?</p>
<p>Goodness&#8230;. And you&#8217;d figure that a Sun workstation would be where java would somehow be champ.</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: badger</title>
		<link>http://www.lshift.net/blog/2006/09/10/erlang-processes-vs-java-threads#comment-10010</link>
		<pubDate>Wed, 13 Sep 2006 21:08:47 +0000</pubDate>
		<guid>http://www.lshift.net/blog/2006/09/10/erlang-processes-vs-java-threads#comment-10010</guid>
					<description>&lt;p&gt;@tony:  Cool.  I'll read up on java.util.concurrent.BlockingQueue in the meantime.  You're right about concurrency in Java, java.util.concurrent is truly a horror!  ;)&lt;/p&gt;

&lt;p&gt;@julian: The most recent version of Erlang is SMP aware.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>@tony:  Cool.  I&#8217;ll read up on java.util.concurrent.BlockingQueue in the meantime.  You&#8217;re right about concurrency in Java, java.util.concurrent is truly a horror!  ;)</p>
<p>@julian: The most recent version of Erlang is SMP aware.</p>
]]></content:encoded>
				</item>
</channel>
</rss>
