Zbr's days.

About :: TODO :: Blog :: RSS :: Old blog :: Projects :: GIT :: Gallery :: Notes

Thu, 09 Nov 2006

POSIX threading model vs. Erlang threads.


I decided to check if this benchmark of different threading models is correct.
So I've installed Erlang on my Debian Etch desktop (Intel Core Duo 3.4 Ghz (speeded up to 3.7 Ghz), 2 GB of RAM) and tried this Erlang application. It was compiled fine, but failed to execute.
So I've read some FAQs and initial tutorials about Erlang and ended up removing some bits of initialization, since my version of Erlang failed to translate string to number, so I hardcoded required number by hand into the program.
I also compiled this (1) C++ example and this (2) and performed a comparison.

Basically all those programs do is to create 500 threads and exchange 3000 messages between them one-by-one.

Results are quite deplorable for POSIX threads and C++:

  Erlang                   : 0.443 seconds
  C++/POSIX NPTL threads 1 : 4.374 seconds
  C++/POSIX NPTL threads 2 : 0.190 seconds
i.e. C++ application which uses POSIX NPTL threads is about 10 (!) times slower than native Erlang threads, but if thread start/stop functions are written in assembler (if I did not forget it completely), C++ variant becomes 2 times faster than Erlang's one, which seems to be either real magic, or some bug.

I understand that Erlang has completely differet thread model (i.e. it is part of it's virtual machine, but not system as a whole), but there is major issue to think about.

Eventually I created own application, which uses NPTL POSIX threads, which I compared to above (this (1)).
Above numbers are the best numbers reported by time test, so I put gettimeofday() inside main() in both C++ and my C versions and run them 13 times.
Here are averaged results:
  C++/POSIX NPTL threads 1                        : 5083343 usecs
  C/POSIX NPTL threads                            : 4821212 usecs
  C++/POSIX NPTL threads 1 (-fomit-frame-pointer) : 4738057 usecs
  C/POSIX NPTL threads (-fomit-frame-pointer)     : 4430010 usecs
Sources are available here.
Compilation options were: -pipe -Wall -O3 -lpthread -fomit-frame-pointer

This is definitely an issue to think about...

/devel/other :: Link / Comments ()