Databases Reference
In-Depth Information
We've already discussed how difficult it is to maintain consistent memory state on
multithreaded and parallel systems. Whenever you have multiple threads executing
on systems, you need to consider the consequences of what happens when two threads
are both trying to update shared resources. There are several ways that computer sys-
tems share memory-resident variables. The most common way is to create stringent
rules requiring all shared memory to be controlled by locking and unlocking func-
tions. Any thread that wants to access global values must set a lock, make a change,
and then unset the lock. Locks are difficult to reset if there are errors. Locking in dis-
tributed systems has been called one of the most difficult problems in all of computer
science. Erlang solves this problem by avoiding locking altogether.
Erlang uses a different pattern called actor , illustrated in figure 10.14.
The actor model is similar to the way that people work together to solve problems.
When people work together on tasks, our brains don't need to share neurons or
access shared memory. We work together by talking, chatting, or sending email—all
forms of message passing . Erlang actors work in the same way. When you program in
Erlang, you don't worry about setting locks on shared memory. You write actors that
communicate with the rest of the world through message passing. Each actor has a
queue of messages that it reads to perform work. When it needs to communicate with
other actors, it sends them messages. Actors can also create new actors.
By using this actor model, Erlang programs work well on a single processor, and
they also have the ability to scale their tasks over many processing nodes by sending
messages to processors on remote nodes. This single messaging model provides many
benefits for including high availability and the ability to recover gracefully from both
network and hardware errors.
Erlang also provides a large library of modules called OTP that make distributed
computing problems much easier.
Actor
Message queue
Actor
Message queue
Actor
Message queue
Actor
Message queue
Figure 10.14 Erlang uses an actor model, where each process has agents
that can only read messages, write messages, and create new processes.
When you use the Erlang actor model, your software can run on a single
processor or thousands of servers without any change to your code.
 
Search WWH ::




Custom Search