Chapter 14. Distributed Programming
Up until now, we have been considering programs that run on a single
machine, while possibly making use of multiple processors to exploit
parallelism. But there is a far more plentiful source of parallelism: running a program on multiple machines
simultaneously. We call this distributed programming, and
Haskell supports it through a framework called distributed-process.[50]
Aside from the obvious advantages of multimachine parallelism, there are other reasons to write distributed programs. For example:
- A distributed server can make more efficient use of network resources by moving the servers closer to the clients. We will see an example of this in A Distributed Chat Server.
- A distributed program can exploit a heterogeneous environment, where certain resources are available only to certain machines. An example of this might be a cluster of machines with local disks, where a large data structure is spread across the disks and we wish to run our computation on the machine that has the appropriate part of the data structure on its local disk.
So what should distributed programming look like from the programmer’s
perspective? Should it look like Concurrent Haskell, with forkIO,
MVar, and STM? In fact, there are some good reasons to treat
distributed computation very differently from computation on a
shared-memory multicore:
- There is a realistic possibility of partial hardware failure: that is, some of the machines involved in a computation may go ...