Benefit from concurrent programming (s)?

Recently, I am trying to plunge into the world of parallel programming. at the beginning, I thought that the only reason for multi-core processors is improved program performance. but now I'm not so sure ...

Considering the fact that the multithreading of writing multithreaded programs in most languages ​​is heterogeneous, many tend to recommend the use of specially designed languages ​​such as Erlang or Clojure as the language of choice for parallel computing. Erlang certainly makes writing parallel programs easier, but is it worth it?

I searched for some of the Erlang programs during the shootout (yes, I know that microbenchmark does not say anything ...) and was surprised that many single-core C programs even outperform the quad-core Erlang programs.

so my questions are: what are the advantages of languages ​​like Erlang, Clojure, etc.? why should I use a language that makes writing a multi-core program easier when single-core C / Java programs are even faster?

(I forgot to mention that these issues are only related to multi-core machines, distributed computing is something else, and I see the benefits of Erlangs here)

+7
source share
2 answers

As soon as the best answers begin, it depends on what you are trying to do, and in this case it depends on what you are trying to do (at the hardware level).

There are currently some good machines available with 32 + cpus on them. To use all of these cpus requires either:

  • You are writing a multithreaded program in your chosen language.
  • You write one single-threaded program and run many instances that all exchange in some way (to share the workload) to solve your problem.

Often 1 is much easier to do than 2.

If you look at the “future of equipment”, it seems that there is a tendency toward faster rather than faster. So to say, ParaCCC (imaginary language) is 10 times slower than C, but you have a machine with 512 processors on it that ParaCCC can use (for our problem). In theory, the ParaCCC program will run 51 times faster than the C program. Without rewriting. Plus C, as a rule, does not know its time to market, where, since this is another boast of these new languages.

Also, you probably don't think that most programs that do any amount of I / O end up being multi-threaded, since you tend to use different threads for I / O than processing, and you don't want one slow the client slows you down (obviously C can do this, but a multi-threaded model usually looks a lot nicer).

As for Erlang, I asked the following question here: How many processors are needed before Erlang is faster than single-threaded Java , the answers to which have much more details and arguments in this direction ...

+6
source

Clojure is a good choice just for this compromise. It does not impose as many restrictions on you as in erlang, in fact you can always rewrite sections that need more performance in a changeable imperative style (still in clojure, albeit ugly), if you like, and get Java speed. However, correctness and concurrency guarantees you faster time to market than C and java for any fairly complex problem, and we all know that development time costs more than the cost of hardware.

The idea of ​​clojure is that constructs (immutability, transactions) make it easier to talk about concurrency.

+3
source

All Articles