A Fibonacci Server
Learn about the Fibonacci series and its processing in Elixir.
We'll cover the following
Introduction
Let’s round out this chapter with an example program. Given a list of , our task is to calculate , where is the Fibonacci number. The Fibonacci sequence starts from 0, 1. Each subsequent number is the sum of the preceding two numbers in the sequence. We chose this not because it’s something we all do every day but because the naive calculation of Fibonacci numbers from 10 to 37 takes a measurable number of seconds on typical computers.
Implementation
The twist is that we’ll write our program to calculate different Fibonacci numbers in parallel. To do this, we’ll write a trivial server process that does the calculation and a scheduler that assigns work to a calculation process when it becomes free. The following diagram shows the message flow.
Get hands-on with 1400+ tech skills courses.