This repository is a primality testing service built with RabbitMQ and Elixir. A primality test is used to determine whether a number is prime or composite. For very large numbers, primality testing can require a nontrivial amount of time; thus, this system has been designed to be scalable by allowing end users to spin up multiple worker nodes who can handle the heavy lifting each within its own isolated process. The results are then forwarded to a logger that appends the workers' results to a CSV file.
The above diagram displays the system architecture. P is a producer that sends a request to determine the primality of a number. These requests are stored in Q1 and are forwarded to workers (W1,..,Wn) as they become available. When a worker node has finished determining the primality of the number, it sends a request to write the result to the log file. These requests are stored in Q2 and are forwarded to the logger (L) as it becomes available.
Note that it would also be feasible to have as many producers (P1,..,Pn) and loggers (L1,..,Ln) as desirable; however, for this example, we are reducing complexity and scaling only the workers where the bulk of the processing occurs.
Start RabbitMQ with Docker (you may need sudo):
$ docker run -it --rm --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:4-managementInitialize logger to write to file:
$ mix run lib/log.exs > results.logInitialize worker(s):
$ mix run lib/worker.exsSend a message:
$ mix run lib/producer.exs