Compiling Erlang – A “personal” experience

Posted by marian on October 27, 2009

To respond to all the questions that I have received last day I will make some clarifications.
First of all, one of the jobs were I use Erlang is Distributed programming. More specifically I am building an application that changes a lot (while I am trying to develop some algorithms, and from this comes the desire to use a functional language)  which needs to perform a humangous number of floating point operations (yes C is a better language, Octave is very good for doing math, and MPI is what academia uses, BUT I decided to use Erlang to do this job although I read some articles regarding some limitations of  its floating point operations).

So I needed to optimize in some way the floating point precision of Erlang. To the reader it might look like this is nonsense. Why do you use Erlang ? Answer: because it is easy to learn, it is a functional language, you can think in higher order constructs (well suited when you are doing a proof of a concept), you have a concurency model at you disposal (communication is done using message passing),  you think more and code less (well you encode more in your head and write less), and if someone asks you : why didn’t you use the Abstract Factory, Object pool, Singleton,  Adapter, Composite, Decorator, Flyweight, Iterator, Memento patterns, I can answer with satisfaction: it is functional programming, not OOP, so these patterns are provided by the language constructs.

Therefore I looked some ways to adapt the environment in which I develop, to what I need. Furthermore, let me bring up the fact that Slackware users have to compile almost everything. The argument might be that they want to squize every bit of performance from their system.

The following question comes up: “If I compile myself the Erlang VM, will the performance of my system increase ?”. It depends. I am sure that the Erlang team does its best to provide the highest performance while maintaining the portability, by not making any assumptions about the underlying hardware.  And usually, portability is more important than performance. Besides, what will you think that will happen if some software developer makes a program that has its highest performance on the Intel platform ? Do you think that AMD, and Sun will be happy ? Or vice-sersa, Sun’s Niagara vs. Intel’s processors.

This is the user’s job: to adapt what is provided to him (for free) to its needs. And so I did. So should everybody do. Do you have a server motherboard ? If yes, did you know that it has I/O processors ?  Would somebody develop an “read call” version that uses specifically the instructions of the I/O  processor? It seems not, the basic strategy is: “I/O in Erlang is slow”, but what can you do about it ?

So the least I could do was to compile Erlang with the Intels compiler, to tell the processor to use a more strict model when performing divisions and square roots, to speed up the floating point operations (with a trade-off towards precission) and the memory transfer.

So, if you use Erlang for I/O bound oprations for some sort (parsing XML, using it as a gateway for some sort of services)  this kind of optimization does not improve the performance at all.  You should look for other types of optimizations.

Regarding the tests that I performed, the comparison was made with the CC=gcc, no other arguments provided. The ./configure will uses the Makefile’s provided optimization level (-O3, -O2). Please note that it is not always wise to optimise everything, since for example unrolling loops increases the code size. So the

icc -gcc-version=420  -mssse3 -ip -par-threshold=50 -fp-model strict -prec-div -prec-sqrt -pc80 -opt-streaming-stores always -par-threshold=50 -par-runtime-control -par-schedule-static-balanced -static-libgcc -static-intel

can be interpreted as follows:

  • “I will provide you”  parameters that correspond to the gcc  version 4 (again, please note that I do NOT give optimization directives such as -O3 or -O2, firstly because are specified in the Makefiles, and secondly because I think that the Erlang team has performed extensive profiling to see were optimization enhances performence or not).
  • “If you can” please increase the precision of sqrt and div
  • “Use the existing resources as well as you can” (-mssse3)
  • “My threads are memory bound”, and every one of them has what to do (do not steal data from neighboring threads, just do your work !)

Last but not least “Open a Bash console …”, yes I really meant it. I do not insult anyone’s intelligence. This might be crucial detail. I remember that back some time, while I was working at a project I was setting the path to a program using Bash style, while I was working in a C shell and I didn’t know what was going on (I know the prompt is different, but somebody tried to make a joke by compiling the source code and altering the prompt). Secondly, if somebody searches Google, one might see that not setting the path, or not setting it correctly is an often mistake.

About Java and Distributed Systems

Posted by marian on October 24, 2009

It is rely weird when people refuse to learn anything new or reuse something old.

Late this day I have received an email about a workshop in Distributed Computing. Lets establish the context first. In my hometown the is a project undergoing which has as objective the creation of a local computer cluster. And, in this context it just happens that a company wants to promote a product in Distributed Computing .

The company is called Actieeon, and its website is http://proactive.inria.fr/. They say that they are Open Source, but of course they have an Enterprise Solution that you can license.

I am eager to see what will they say at the workshop, and if I could mange to stop laughing. I must admit that they have a beautiful source code, well documented, but to build a Distributed System in Java seems to be a rather stupid thing to do.

Let me explain miself. In my faculty, at the Distributed Systems course we of course study Java as a language for Distributed programming. This is not because it is very good, but because nobody wants to try something new or use something old. Probably our parents heard about C, Fortran or Ada, languages  that were used succesfully for parallel and distributed computing. But we do not know anything about them, we must know the all mighty Java, an universal panaceea for our computing problems. Ohh, and there is also Erlang which “is a language designed concurrency in mind”.

The basic question is: why would you need an Object Oriented Language when you need raw power ? Probably there is nobody to do distributed computing with something other that OOP concepts. I would prefer a functional languag like Haskel or Erlang:  they provide a clear demarcation between what should be executed sequentially and what should be executed in parallel. The Java solution is to provide some function calls, to some “objects”, to perform “something” in parallel. The resulting code cannot be something else than ugly. But, we use OOP principles, and “some” say that this is good practice.

Some say that Java is very portable, and it is,realy it is, but only when you print on the console “Hello world”.

But when you want to do input/output and run computationally intensive programs, well you would have to write a chron scripts for killing the Java Virtual machine. Of course, some may say that for example JRockit Java VM can be used for powering highly demanding websites; and it is true, it is well suited for the MVC pattern, but it isn’t a language to use in a distributed system.

First of all a Distributed System is a heterogeneous one. Clusters have a large variaty of Operating System, ranging from AIX, Solaris, RedHat, Ubuntu server. Cheap solutions also use NetBsd; try running Sun’s Java VM on that one; the whole system needs around 90 MB to run, but when you start Java, hmm arround 300 MB.

So we’ve covered Java’s ugly code, large memory consumption, portability; now lets see about how others deal with these issues. Which componany has as main bussines distributed computing ? Answer: Google, job searching. Some say that they use a combination of C, Python and Java. I would say that they generally use Python, and do all the dirty things at the C level. Python has low memory consumtion, it is a glue language and can work along with other languages relatively well. Of course, there is Jython the Java version of Python, but, realy, I don’t think they are using it.

Next we have Erricson and the telecommunication world. Do they use Java ? It seems that there are some niche companies that are testing the field, but Erricson uses Erlang. Their purpose is the creation of a fault tolerant environment for providing services such emargency call. How are exceptions treated by those at Erricson ?

Is there a fault on the system ? If yes, automatically kill the process or if it is something extremly serious kill the Virtual Machine on the corresponding node and then restart it, while relying on the existing redundancy. In Java you must catch tens of expetions and handle them. Wouldn’t it be simpler to just kill the process that makes the computation ? Well, you can’t since it is an OOP language:  it doesn’t have fault tollerance, there is no mechanism for killing and restaring the VM, it does not have lightweight processes you could kill if they do something nasty, but it has a hightly complex garbage collector that has the job of making some room in the excesivelly large memory that it is needed.