Sei sulla pagina 1di 3

Erlang – High Level Overview

Technology domain:
Erlang falls under the domain of functional programming languages. Therefore it
inherits all features common to functional programming languages.
It’s a declarative languages and declarative languages work on the principle of
trying to describe what should be computed, rather than saying how a value is
calculated which makes Erlang programs short and compact.

Peer technologies:
Currently there are other functional programming languages parallel to Erlang like
F#, LISP, Ocaml etc.
But Erlang has unique characteristics (described below) which gives it an advantage
over other peer functional programming languages.

Erlang characteristics:
Process scalability:
Erlang processes are lightweight because the Erlang virtual machine does not
create an OS thread for every created process. They are created, scheduled, and
handled in the VM, independent of the underlying operating system. As a result,
process creation time is of the order of microseconds and independent of the
number of concurrently existing processes. Compared with Java and C#, where for
every process an underlying OS thread is created, Erlang greatly outperforms both
languages.

Lightweight concurrency model:


Rather than providing threads that share memory, each Erlang process executes in
its own memory space and owns its own heap and stack.
Processes communicate with each other via message passing, where the message
can be any Erlang data value. Message passing is asynchronous, so once a message
is sent, the process can continue processing. Messages are retrieved from the
process mailbox selectively, so it is not necessary to process messages in the order
they are received. This makes the concurrency more robust.
Regardless of the number of concurrent processes in your system, exchanging
messages within the system takes microseconds. All that is involved in message
passing is the copying of data from the memory space of one process to the
memory space of the other, all within the same virtual machine. This differs from
Java and C#, which work with shared memory and OS threads. Even here,
benchmarks shows that Erlang manages outperform other languages.
Avoids shared data:
Shared data leads to many of the synchronization problems and bottlenecks that
arise with many conventional programming languages.
Erlang avoids shared data which makes it the perfect fit for multi-core processors,
and eliminates the possibility of issues like deadlocks.

Robustness:
Erlang has a set of simple but powerful error-handling mechanisms and exception
monitoring constructs, very general library modules have been built, with
robustness designed into their core. The libraries are collectively known as the OTP
(Open Telecom Platform) middleware. By programming for the correct case and
letting these libraries handle the errors, not only are programs shorter and easier to
understand, but they will usually contain fewer bugs.
Erlang processes can be linked together so that if one crashes, the other will be
informed, and then can either handle the crash or choose to crash itself. OTP
provides a number of generic behaviors, such as servers, finite state machines, and
event handlers. These generic behaviors are linked to a supervisor behavior whose
only task is to monitor and handle process termination. OTP puts the idea of links
into a framework whereby a process supervises other workers and supervisors, and
may itself be supervised by yet another process, all in a hierarchical structure.

Built-in distributed computation:


Erlang has distribution incorporated into the language’s syntax and semantics,
allowing systems to be built with location transparency in mind. The default
distribution mode is based on TCP/IP, allowing a node (or Erlang runtime system) on
a heterogeneous network to connect to any other node running on any operating
system. As long as these nodes are connected through a TCP/IP network and the
firewall has been correctly configured, the result is a fully meshed network of nodes,
where all the nodes can communicate with each other.
Erlang programs consist of processes that communicate via message passing.
Initially these processes can all be on one node, but as the syntax of sending a
message within the node is the same as sending it to a remote node, you can easily
distribute your processes across a cluster of computers. With distribution built into
the language, operations such as clustering, load balancing, the addition of
hardware and nodes, communication, and reliability come with very little overhead
and correspondingly little code.

Strong integration capabilities:


There are mechanisms for interworking with C, Java, Ruby, and other programming
languages, including Python, Perl, and Lisp.
High-level libraries allow Erlang nodes to communicate with nodes executing Java or
C, making them appear and behave like distributed Erlang nodes. Other external
languages can be tied in more tightly using drivers that are linked into the Erlang
runtime system itself, as a device driver would be, and sockets can also be used for
communication between Erlang nodes and systems written in other languages using
popular protocols such as HTTP, SNMP, and IIOP.
Production systems that currently use Erlang:
• Amazon SimpleDB, for providing database services as a part of the Amazon
Elastic Compute Cloud (EC2).
• Yahoo social bookmarking service, Delicious, which has more than 5 million
users and 150 million bookmarked URLs.
• Backend of Facebook chat service, handling more than 100 million active
users.
• T-Mobile SMS and authentication systems.
• Motorola call processing products in the public-safety industry.
• Ericsson support nodes, used in GPRS and 3G mobile networks worldwide.

** Case studies of existing systems build with Erlang has proven "five nines"
availability.

Open source Erlang applications:


• RabbitMQ, an AMQP messaging protocol implementation. AMQP is an
emerging standard for high-performance enterprise messaging.
• The CouchDB “schema-less” document-oriented database, providing
scalability across multicore and multiserver clusters.
• The 3D subdivision modeler Wings 3D, used to model and texture polygon
meshes.
• The Ejabberd system, which provides an Extensible Messaging and Presence
Protocol (XMPP) based instant messaging (IM) application server.
• The MochiWeb library that provides support for building lightweight HTTP
servers. It is used to power services such as MochiBot and MochiAds, which
serve dynamically generated content to millions of viewers daily.

Summary:
If the requirement is to build a single threaded application which does a lot of
calculations, a graphics intensive system or client software running on a mobile,
Erlang might not be the best choice.
But if the target system is a high-level, concurrent, robust, soft real-time system
that will scale in line with demand, make full use of multi-core processors, and
integrate with components written in other languages, Erlang should be the choice.

Potrebbero piacerti anche