Skip to content

nskins/primality

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Primality

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.

Architecture

Architecture diagram

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.

Instructions

Start RabbitMQ with Docker (you may need sudo):

$ docker run -it --rm --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:4-management

Initialize logger to write to file:

$ mix run lib/log.exs > results.log

Initialize worker(s):

$ mix run lib/worker.exs

Send a message:

$ mix run lib/producer.exs

About

Primality testing service built w/ RabbitMQ + Elixir

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages