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










