[erlang-questions] Erlang port speed

Ulf Wiger <>
Sat May 30 14:51:20 CEST 2009


One major difference between the two approaches is
that your C program does a blocking read on the 
port file descriptor, whereas the Erlang version is
non-blocking by default.

(If I mis-read your C program during my 10-second
scan, I apologize.)

BR,
Ulf W

----- "Patrick Mahoney" <> wrote:

> On Fri, May 29, 2009 at 12:04:46PM -0400, Colin Z wrote:
> > 
> > Ping-ponging 1 million times takes about 160 seconds between Erlang
> and C# .
> > I'm benchmarking using the statistics module. I'm not doing any
> io:fwrites,
> > etc.
> > 
> > Between the two C# processes it takes about 15 seconds.
> > 
> 
> I wrote a crummy benchmark that sends "ping" and "pong" back and
> forth
> under Linux using both a C program and an Erlang program to drive the
> same "simple_port.c" port.  My Erlang program is much closer to C
> than
> your example, but is still about 30% slower for 1 million ping/pong.
> 
> Here's the result with a C program controling "simple_port.c":
> 
> $ time ./port_control
> ping/pong 1000000 times
> 
> real    0m16.570s
> user    0m11.017s
> sys     0m5.188s
> 
> And here's the result of an erlang program controlling
> "simple_port.c":
> 
> Erlang R13A (erts-5.7) [source] [smp:2:2] [rq:2] [async-threads:0]
> [hipe] [kernel-poll:false]
> 
> Eshell V5.7  (abort with ^G)
> 1> c(port_control).
> {ok,port_control}
> 2> port_control:test().
> ping/poing 1000000 times
> 20.681763s
> ok
> 3> port_control:test().
> ping/poing 1000000 times
> 21.058769s
> ok
> 
> I don't have time to test on a win32 machine (and the C control
> program
> would have to to significantly changed to compile under win32;
> erts/emulator/sys/win32/sys.c might be helpful here).
> 
> I recall a long time ago (unrelated to erlang) hearing about poor
> pipe
> performance in win32.  I also notice that the "gs" gui library
> included
> in the Erlang source, specifically gstk_port_handler.erl and
> gstk.tcl,
> uses a socket rather than stdin/stdout pipes when run in windows.  I
> don't see any obvious comments, but I wonder if socket performance is
> much better than pipes under win32.
> 
> If this is indeed the reason, then perhaps the documentation should
> mention it and possibly provide an example using sockets.
> 
> 
> 
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org

-- 
Ulf Wiger
CTO, Erlang Training & Consulting Ltd.
http://www.erlang-consulting.com


More information about the erlang-questions mailing list