liveBook · Manning

Memory bound

As explained in Elixir in Action, Third Edition

A bottleneck is a component or operation whose limited processing capacity constrains the throughput of a larger system.

A performance bottleneck is a component or operation whose limited processing capacity constrains the throughput of a larger system. In concurrent systems, many processes can still depend on one sequential process, forcing requests through a serialized path. section 5.4.1 section 10.3

Identify the constrained process, optimize its internal work first, and parallelize only when faster handling is not possible. Parallelization may improve multicore performance, but it cannot repair a poorly structured algorithm. section 5.4.1

Slow echo server

Five clients send messages concurrently, but one server process sleeps for one second before replying. Responses therefore arrive one by one rather than concurrently; removing the delay improves the bottleneck before splitting work across processes. section 5.4.1

Listing 5.13 Demonstration of a process bottleneck (process_bottleneck.ex)
defmodule Server do
  def start do
    spawn(fn -> loop() end)
  end
 
  def send_msg(server, message) do
    send(server, {self(), message})
 
    receive do
      {:response, response} -> response
    end
  end
 
  defp loop do
    receive do
      {caller, msg} ->
        Process.sleep(1000)               #1
        send(caller, {:response, msg})    #2
    end
 
    loop()
  end
end

Runnable Elixir code demonstrates how one sequential receive-and-reply loop constrains concurrent callers. section 5.4.1

How Elixir in Action, Third Edition covers it

How deep it goes
Explains sequential processing, demonstrates measured impact, and recommends optimization before parallelization.
Examples
Uses a slow echo server and a GenServer key-value store benchmark with one and 10,000 clients.
What it assumes
Assumes familiarity with concurrent processes and message handling while demonstrating their sequential server behavior.
What you can do after
Diagnose bottlenecks with concurrent behavior and benchmarks, then optimize handling or assess process decomposition.
How it connects
Connects processes, message passing, throughput, parallelization, GenServer, ETS tables, and scalability.

Also explained in

Compare how 11 books explain memory bound →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Elixir in Action, Third Edition. The section links point to the parts of the book it draws on.