Prime as a Service is a REST API implemented in Go that provides some of the basic functionalities using prime numbers. This service was deployed using a Docker Swarm cluster and monitored with Grafana and Prometheus.
Implemented algorithms :
Path | Type | Description |
---|---|---|
/primes/lower&upper | GET | Return a list of prime numbers between lower and upper inclusive. |
/prime-factors/n | GET | Return a list of prime facotrs of n and their power. |
/number-of-divisors/n | GET | Return the number of divisors of n. |
/metrics | GET | Return the metrics provided by Prometheus. |
- Clone this repository
$ git clone https://github.com/Nezz7/prime-as-service.git
- Change the current working directory
$ cd /prime-as-a-service
- Create the docker image : server-image
$ docker build -t server-image .
- Initialize the swarm
$ docker swarm init
Don't forget to save the token. - Deploy the stack to the swarm
$ docker stack deploy --compose-file docker-compose.yml $SERVICE_NAME
- Check that it’s running
$ docker stack services $SERVICE_NAME
Performance depends on the size of max number. But as an example, it needs about 0.4 ms to produce the first 1,000,000 prime numbers.
$ go test -bench .
goos: linux
goarch: amd64
BenchmarkPrimesInRange-2 2359 491736 ns/op
PASS
ok github.com/Nezz7/Prime-as-a-Service 1.240s