Skip to Main Content
Parallel and Concurrent Programming in Haskell
book

Parallel and Concurrent Programming in Haskell

by Simon Marlow
July 2013
Intermediate to advanced content levelIntermediate to advanced
322 pages
8h 43m
English
O'Reilly Media, Inc.
Content preview from Parallel and Concurrent Programming in Haskell

Chapter 12. Concurrent Network Servers

Server-type applications that communicate with many clients simultaneously demand both a high degree of concurrency and high performance from the I/O subsystem. A good web server should be able to handle hundreds of thousands of concurrent connections and service tens of thousands of requests per second.

Ideally, we would like to write these kinds of applications using threads. A thread is the right abstraction. It allows the developer to focus on programming the interaction with a single client and then to lift this interaction to multiple clients by simply forking many instances of the single-client interaction in separate threads. In this chapter, we explore this idea by developing a series of server applications, starting from a trivial server with no interaction between clients, then adding some shared state, and finally building a chat server with state and inter-client interaction.

Along the way, we will need to draw on many of the concepts from previous chapters. We’ll discuss the design of the server using both MVar and STM, how to handle failure, and building groups of threads using the abstractions introduced in Symmetric Concurrency Combinators.

A Trivial Server

In this section, we will consider how to build a simple network server with the following behavior:

  • The server accepts connections from clients on port 44444.
  • If a client sends an integer n, then the service responds with the value of 2n.
  • If a client sends the string "end" ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Haskell High Performance Programming

Haskell High Performance Programming

Samuli Thomasson
Haskell Cookbook

Haskell Cookbook

Yogesh Sajanikar
Haskell in Depth

Haskell in Depth

Vitaly Bragilevsky

Publisher Resources

ISBN: 9781449335939Supplemental ContentErrata Page