Shows simple examples of increasing concurrency levels with Elixir.
- Install a Docker client such as Docker for Mac.
git clone [email protected]:AbleTech/concurrency.git
cd concurrency
cp .container-sample.env .container.env
cp .envrc-sample .envrc
docker-compose up -d
docker-compose exec elixir bash
You need to have completed the Getting Started steps, and should have a bash
shell prompt within the Elixir container. Each of these examples process the 100,000 address records stored within the addresses
table.
SequentialFunctions
Queries the addresses
table, streams the records and looks for longest/shortest/etc addresses.
Performs each of the searches sequentially.
Command: time mix run -e Concurrency.Functions.SequentialFunctions.run
Time: about 5 secs
ConcurrentFunctions
Queries the addresses
table, streams the records and looks for longest/shortest/etc addresses.
Performs each of the searches concurrently.
Command: time mix run -e Concurrency.Functions.ConcurrentFunctions.run
Time: about 3 secs
SequentialProcessor
Queries the addresses
table, loads all the records, and then processes each line sequentially.
Command: time mix run -e Concurrency.Processor.SequentialProcessor.run
Time: about 3 mins
SequentialStreamProcessor
Queries the addresses
table, streams the records, and processes each line sequentially.
Command: time mix run -e Concurrency.Processor.SequentialStreamProcessor.run
Time: about 2 mins
ConcurrentProcessor
Queries the addresses
table, loads all the records, and then processes each line concurrently.
Command: time mix run -e Concurrency.Processor.ConcurrentProcessor.run
Time: about 1 mins
Use the time
command to compare execution times. For example:
time mix run -e Concurrency.Functions.ConcurrentFunctions.run
real 0m2.898s
user 0m4.050s
sys 0m0.860s
This example shows that the execution time was approx 2.9 seconds, but the amount of consumed CPU time was closer to 4 seconds.