Skip to content

Latest commit

 

History

History
59 lines (43 loc) · 2.37 KB

README.md

File metadata and controls

59 lines (43 loc) · 2.37 KB

Prime as a Service

Build

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.

Algorithm

Implemented algorithms :

Architecture

Architecture

Endpoints

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.

Deploy

  1. Clone this repository
    $ git clone https://github.com/Nezz7/prime-as-service.git
  2. Change the current working directory
    $ cd /prime-as-a-service
  3. Create the docker image : server-image
    $ docker build -t server-image .
  4. Initialize the swarm
    $ docker swarm init
    Don't forget to save the token.
  5. Deploy the stack to the swarm
    $ docker stack deploy --compose-file docker-compose.yml $SERVICE_NAME
  6. Check that it’s running
    $ docker stack services $SERVICE_NAME

Performance

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