Skip to content

pasanjaya/distributed-com

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Distributed Prime System

The distributed logic for your 1 to 2^63 - 1 primality pipeline is fully implemented! Here is a summary of the executed work.

Implemented Components

1. The Worker (Prime Checker)

The worker node uses the efficient Miller-Rabin primality test which is incredibly fast for checking incredibly large integers like those near 2^63.

Unlike traditional request-response short-lived sockets, this server retains persistent, long-lived open sockets allowing the generator to continuously barrage it with test values without incurring thousands of TCP handshake costs. It can be spawned in as many terminal windows as you need to parallelize the load:

# Terminal 1
python3 prime_checker.py --port 8001
# Terminal 2
python3 prime_checker.py --port 8002
# Terminal 3 ... etc
python3 prime_checker.py --port 8003

2. The Load Balancer / Client (Generator)

The Generator coordinates everything while respecting the sequence limit of $2^{63} - 1$. It maintains a single synchronized counter lock. It opens concurrent asynchronous TCP streams out to every port supplied in CHECKER_ENDPOINTS. It pipes sequential integers up to the maximum limit, sending a new problem out the second a worker responds back. The JSON response string is flushed directly to responses.log.

3. Docker Wrapping

The Dockerfile provides a container to house the generator. To run the load balancer from Docker (pointing into your host terminal workers), use:

# Build
docker build -t prime-generator .

# Run on MacOS
mkdir -p logs
docker run --rm \
  -v $(pwd)/logs:/app/logs \
  -e LOG_FILE=/app/logs/responses.log \
  -e CHECKER_ENDPOINTS="host.docker.internal:8001,host.docker.internal:8002" \
  prime-generator

About

Inter service communication tryout

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors