concept server in category erlang

appears as: servers, server, server, A server, servers, The server
Erlang and OTP in Action

This is an excerpt from Manning's book Erlang and OTP in Action.

Consider a web server: it receives requests for web pages, and for each request it needs to do some work that involves finding the data for the page and either transmitting it back to the place the request came from (sometimes split into many chunks, sent one at a time) or replying with an error message in case of failure. Clearly, each request has little to do with any other; but if the server accepts only one at a time and doesn’t start handling the next request until the previous is finished, there will quickly be thousands of requests on queue if the web site is popular.

If the server instead can begin handling requests as soon as they arrive, each in a separate process, there will be no queue, and most requests will take about the same time from start to finish. The state encapsulated by each process is then the specific URL for the request, who to reply to, and how far it has come in the handling as yet. When the request is finished, the process disappears, cleanly forgetting about the request and recycling the memory. If a bug causes one request to crash, only that process dies, while all the others keep working happily.

Server = {tr_server, {tr_server, start_link, []},
          permanent, 2000, worker, [tr_server]}
Figure 9.1. The current, simple architecture of the cache application. Each cache is local to the server it runs on. Because the load balancer distributes work between the servers, the caches need to become distributed as well if they’re to store the session data.

To match the examples in this book, the module name should be jp_server, and the server should be a locally registered process with the same name as the module. Create a basic application named json_parser to contain this module, complete with the usual jp_app and jp_sup modules, as well as a front-end API module named json_parser that calls the corresponding functions in jp_server.