SpotiAPIs represents my thesis project
for the master’s degree
in Computer Engineering.
The goal of this elaborate is
to study sensitivity to optimize performance.
The project contains seven branches with different limits and reservations of CPUs and memory :
- branch
develop: no limit for use of CPUs or memory - branch
dev-0.005CPUs: CPUs limit to 0.005 and 0.0020 of reversations. - branch
dev-200M: memory limit to 200M - branch
dev-2CPUs: CPUs limit to 2 and 1 of reservation - branch
dev-200M-0.5CPUs: Memory limit to 200M and 0.5 CPUs - branch
dev-LIMITMDSDB: both microservicemsspotiapiand the databasespotiapidbare limited with: 1CPUs and 250M of memory - branch
master: follow develop, it rapresents a stable version. It contains all the results
This is the MASTER BRANCH
-
MSSpotiApi: a microservice through the APIs, inside that, it is possible to write and read on a relational database, MySQL. These endpoints have metrics associated with them, such as response time. It is built by reworking the open source system of APIs offered by Spotify. -
SpotiAPIDB: it is a relational database, MySQL. It is read and written by the microservice. It allows data persistence. -
Prometheus: Prometheus collects the metrics exposed by the microservice using a pull mode -
Grafana: Grafana is a web application for interactive data visualization and analysis. -
LoadGenerator: The load generator is used to generate load on the microservice to test it for performance and scalability It also fetches the metrics from prometheus and stores them persistently in the mongodb database, in particular collections. -
SensitivityAnalyzer: this element deals with analyzing the sensitivity of the metric collected to optimize performance
- IntelliJ Idea
- PyCharm
- Spotify for developers
- Spring Boot
- Prometheus
- Grafana
- Docker
- docker-compose
- MySQL
- MongoDB
- Python
- Sensitivity
- Linear Regression
- Polynomial Regression
Now describe the all elements inside the projects and create a guide to deploy those elements.
It is recommended to use
-
IntelliJ Idea for the spring boot project.
-
PyCharm for the load generator and sensitivity analyzer.
- Install Docker
- Install docker-compose
The microservice MSSpotiAPIs, the MySQL database SPOTIAPIDB, Prometheus, Grafana are containerized, through the use of docker containers.
These are the steps to execute them:
If you want to executes all branches, after switch, you need to follow these steps:
-
Open IntelliJ Idea
-
Open the
MSSpotiAPIsproject -
Execute these commands:
- maven clean - maven build -
Execute Docker
-
Open terminal into the folder of MSSpotiAPIs
-
Digit these commands:
- docker compose build - docker compose up
It is strongly recommended to install MongoDBCompass
Sometimes after a restart of the pc you can observe this error:
"connect ECONNREFUSED 127.0.0.1:27017” error message
To resolve this error, open you terminal and digits these commands:
sudo rm -rf /tmp/mongodb-27017.sock
brew services restart
mongodb-community@'version_number'
It is a Spring Boot projects with maven build.
It is used the model-view-controller pattern.
This microservice has the aim to write and read
on a MySQL database: SPOTIAPIDB.
On each endpoint, the response time metric is tracked, through the possibility offered by spring boot to create customized annotations. This metric, exposed in a particular endpoint:
GET localhost:8080/actuator/prometheusThis endpoint is offered by maven dependency micrometer.
It will then be pulled by prometheus as a Gauge metric.
-
findallartist:GET localhost:8080/artist/findallartist/{page_size}
Parameter Type Description page_sizeIntegerRequired number of artists returned -
findartistbyname:GET localhost:8080/artist/findartistbyname/{name}
Parameter Type Description nameStringRequired name of artist returned -
/addartist:POST localhost:8080/artist/addartist
REQUESTBODY:Parameter Type Description idStringRequired id of artist nameStringRequired name of artist followersIntegerRequired followers of artist genresJsonRequired genres of artist popularityStringRequired popularity of artist uriStringRequired uri of artist { "id": "120102e0dedededdededee1ec", "name": "artista", "followers": 544411021, "genres": [ { "name":"genere1" }, { "name":"genere2" } ], "popularity":"1200031930", "uri":"http:spotify:etc" }
-
findallalbums:GET localhost:8080/album/findallalbums/{page_size}
Parameter Type Description page_sizeIntegerRequired number of albums returned -
findalbumbyname:GET localhost:8080/album/findalbumbyname/{name}
Parameter Type Description nameStringRequired name of album returned -
findalbumbynameartist:GET localhost:8080/album/findalbumbynameartist/{name}
Parameter Type Description nameStringRequired name of artist who has these albums -
findalbumbynameoftrack:GET localhost:8080/album/findalbumbynameoftrack/{name}
Parameter Type Description nameStringRequired name of track included in album -
addalbum:POST localhost:8080/album/addalbum
REQUESTBODY:Parameter Type Description idStringRequired id of album nameStringRequired name of album release_dateStringRequired release date of the album total_trackIntegerRequired total tracks of the album album_typeStringRequired album type of the album uriStringRequired uri of album artistsJsonRequired artists of the album { "id": "111dddeede3", "name": "album", "release_date": "12/02/2020", "total_track": 1, "album_type": "album", "uri": "http:spotify:", "artists": [ { "id": "120102deee01222es13", "name": "artista1", "followers": 544411021, "genres": [ { "id": 3, "name": "genere1" }, { "id": 4, "name": "genere2" } ], "popularity": "1200031930", "uri": "http:spotify:" } { "id": "120102deee01222es1334", "name": "artista2", "followers": 544411021, "genres": [ { "id": 3, "name": "genere1" }, { "id": 4, "name": "genere2" } ], "popularity": "1200031930", "uri": "http:spotify:" } ] }
-
findalltracks:GET localhost:8080/track/findalltracks/{page_size}
Parameter Type Description page_sizeIntegerRequired number of tracks returned -
findtrackbyname:GET localhost:8080/track/findtrackbyname/{name}
Parameter Type Description nameStringRequired name of track returned -
findtracksofalbum:GET localhost:8080/track/findtrackbyname/{name}
Parameter Type Description nameStringRequired name of album which contains the tracks returned -
/addtrack:POST localhost:8080/track/addtrack
REQUESTBODY:Parameter Type Description idStringRequired id of track nameStringRequired name of track duration_msIntegerRequired duration in ms of the track release_dateStringRequired release date of the track uriStringRequired uri of track albumJsonRequired album of the track artistsJsonRequired artists of the track { "id": "111dddeede3", "name": "track", "duration_ms": 2700, "release_date": "12/02/2020", "uri": "http:spotify:", album: { "id": "111dddeede3", "name": "album", "release_date": "12/02/2020", "total_track": 1, "album_type": "album", "uri": "http:spotify:", "artists": [ { "id": "120102deee01222es13", "name": "artista1", "followers": 544411021, "genres": [ { "id": 3, "name": "genere1" }, { "id": 4, "name": "genere2" } ], "popularity": "1200031930", "uri": "http:spotify:" } { "id": "120102deee01222es1334", "name": "artista2", "followers": 544411021, "genres": [ { "id": 3, "name": "genere1" }, { "id": 4, "name": "genere2" } ], "popularity": "1200031930", "uri": "http:spotify:" } ] } "artists": [ { "id": "120102deee01222es13", "name": "artista1", "followers": 544411021, "genres": [ { "id": 3, "name": "genere1" }, { "id": 4, "name": "genere2" } ], "popularity": "1200031930", "uri": "http:spotify:" } { "id": "120102deee01222es1334", "name": "artista2", "followers": 544411021, "genres": [ { "id": 3, "name": "genere1" }, { "id": 4, "name": "genere2" } ], "popularity": "1200031930", "uri": "http:spotify:" } ] }
You can find the configuration file of Prometheus, Prometheus.yaml, inside the MSSpotiAPIs folder.
You can find the configuration of Grafana inside the docker-compose.yml file. In the first login you add to insert this follow commands:
- username: admin
- password: admin
SPOTIAPIDB is a relational database MYSQL.
It contains these entities with these relationship:

To execute the load generator is necessary to follow this steps:
- Install library time
- Install library pymongo to do query to MongoDB
- Install library prometheus-api-client to do PromQL query to prometheus
- Install library requests to do http-request
- Install library spotipy to connect to microservice of spotify
- Use python-version 3.8
After that you can run the load generator.
To execute the Sensitive Analyzer is necessary to follow this steps:
- Install library pymongo to do query to MongoDB
- Install library numpy
- Install library pandas to create pandas-dataframe
- Install library matplotlib to plot the results
- Install library sklearn to make linear and polynomial regressions
- Use python-version 3.8
Sensitive Analyzer fetches the metrics saved by Load Generator. It shuffles the datasets(metrics), and it generates the models.
After that it implements a linear regression while before the dataset is divided into train and test sets.
After the linear regression, you can observe a polynomial regression to the all dataset. The measures reported are:
- r2_score
- intercept
- Mean Square Error MSE
If you see a measure of response times, that deviates or in excess or in defect from the surrounding ones. It is possible to visualize the number of times with which a response time is repeated in relation to the defined artist number. In the folders utils you can find the results obtained by my execution.
It is a database inside a document-based database MongoDB. It contains different collections. Every collection contains, differents metrics depending on different observed endpoints
- Github: @francescococo
- Website: francescococo.com
- Linkedin: Francesco Maria Coco
