distributed-systems-energy-efficiency
Distributed social media backend showcasing energy efficiency techniques
https://github.com/tobias-pe/distributed-systems-energy-efficiency
Science Score: 44.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (11.2%) to scientific vocabulary
Keywords
Repository
Distributed social media backend showcasing energy efficiency techniques
Basic Info
Statistics
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
- Releases: 0
Topics
Metadata Files
README.md
Optimization of Energy Efficiency in Distributed Systems
This distributed application and its infrastructure are set up to experiment with and measure different energy optimization techniques. The domain for the application is a social media platform, which includes a variety of computation types to demonstrate tasks performed by distributed systems in real scenarios.
This project is part of a Master's thesis in Computer Science🎓
Overview Architecture 🏗️

Swagger API documentation for each service exposing REST endpoints can be found at:
- http://localhost:PORT/swagger-ui/index.html
- Through the gateway at http://localhost:8080/xyservice/swagger-ui/index.html
Tech Stack 📚
Services
- Language: Java with SpringBoot
- Messaging: RabbitMQ
- Relational Database: Postgres
- Cache: Redis
- Service Discovery: Eureka
- Gateway: spring-cloud-starter-gateway
- Load Testing: Test scenarios written in Python using Locust and Poetry as Dependency Manager
Monitoring
- Dashboard: Grafana
- Power Measurement:
- Service Metrics: Prometheus
- Ops Metrics: kube-prometheus
- Dashboard: Grafana
- Tracing: Zipkin
Ops
- Containerization: Docker & Docker-Compose
- Translation to Kubernetes Configs: Kompose
- Kubernetes Flavor: MicroK8s
Energy Efficiency Practices 🔌⚡
- Caching
- Bulk Fetching
- Concurrent Programming
- Reduce Network Package Size
- Lazy Fetching
- Asynchronous Communication (RPC)
- Set Configuration Parameters Optimally
- Lower Fidelity
- Scaling of Modular Architecture
Analysis of the Demo Application 🧪
Base App

Experiment 1: Implement Caching
- Objective: Reduce energy consumption of the most energy-intensive services by implementing a caching mechanism for frequently requested data.
- Approach: Added Redis caching to minimize frequent requests from the
feedserviceto thepostserviceandstatisticservice. - Results:
- Performance: Significant improvement in response times and stability across various user loads, with the application handling higher request rates without failures.
- Energy Efficiency: Increased energy efficiency, especially for services that benefited from reduced redundant work. The base app's energy efficiency was potentially inflated due to unnecessary work, making the optimized version's efficiency gains more meaningful.
- Resource Usage: Decreased container scaling due to lower workload, improving energy efficiency further.

Experiment 2: Increase Resource Utilization
- Objective: Improve resource utilization to increase throughput, reduce response times, and enhance energy efficiency by optimizing various aspects of the application.
Approach: Implemented several optimization techniques including:
- Concurrent Programming & Bulk Fetching: Enhanced RabbitMQ listeners with a minimum of 2 and a maximum of 4 threads, enabled bulk fetching of up to 10 messages, and introduced child transactions with retry logic.
- Parallelization: Enabled parallel processing in the
notificationserviceandfeedserviceto handle data more efficiently and reduce processing time. - Database & Transactional Improvements: Adjusted database operations and transactional handling to reduce failures and optimize performance.
- Virtual Threads: Introduced Java virtual threads for lightweight concurrency, improving resource utilization and reducing memory footprint.
- Timeout Adjustments: Reduced connection timeouts for the
gatewayandfeedserviceto minimize busy waiting and retrying. - HPA Configuration Tuning: Refined Horizontal Pod Autoscaler (HPA) settings to better match container resource needs and encourage efficient scaling.
- Feedservice Optimization: Removed excessive data (comments) from posts to decrease network load and improve response times.
Results:
- Performance: Significant increases in throughput and improved response times, with stable performance up to 400 users. The application demonstrated better scalability and managed higher loads efficiently.
- Energy Efficiency: Observed a consistent rise in energy consumption due to higher hardware utilization, but overall energy efficiency improved compared to Experiment 1. Energy efficiency increased up to stage 400, with notable improvements in handling higher user loads.
- Resource Usage: Enhanced container scaling behavior with more dynamic adjustments based on the load. Reduced failures and more efficient resource utilization led to better overall system performance.

Experiment 3: Communication Efficiency
- Objective: Improve communication efficiency and reduce response times by optimizing data transfer and interservice communication, addressing observed issues from Experiment 2.
Approach:
- Maximum Response Time Limit: Implemented a maximum response time limit of five seconds on all synchronous endpoints using Spring MVC’s
Callablewrapper to handle long-running tasks asynchronously and prevent thread pool exhaustion. - Response Size Optimization: Reduced the page size for the
feedservicefrom 50 to 40 posts and streamlined thenotificationserviceanduserservicecommunication to minimize data transfer. Introduced a new endpoint for user existence checks to return only a boolean value. - AMQP RPC for Interservice Communication: Switched to RabbitMQ’s AMQP RPC for asynchronous communication between domain services to enhance resilience and scalability.
- Optimistic Locking Adjustment: Replaced optimistic locking with direct
UPDATEqueries in the database for handling concurrent changes, reducing version conflicts and improving performance.
- Maximum Response Time Limit: Implemented a maximum response time limit of five seconds on all synchronous endpoints using Spring MVC’s
Results:
- Performance: Improved stability and throughput with no significant drops in requests per second during scale-down phases. Response times were slightly lower at stages 100, 200, and 300 but higher at stages 400 and 500 compared to Experiment 2. The system's scalability improved with fewer collapses in request handling.
- Energy Efficiency: Slight increase in energy consumption at stages 400 and 500, with decreased efficiency at stages 100, 400, and 500. Stages 200 and 300 showed improved energy efficiency compared to Experiment 2. Increased energy consumption was noted in
statisticservice-dbandrabbitmq, likely due to RPC communication and possibly inefficient database operations. - Resource Usage: Notable improvements in system stability and throughput. The
feedserviceandnotificationserviceshowed the most significant gains in efficiency, while thegatewayandstatisticserviceexperienced reductions in energy efficiency.

Run Locally 🏃
Application and Infrastructure
Requirements:
- Java 21 with Maven
- Docker to start infrastructure containers
Option 1: JetBrains RunConfigs
Use the RunConfigs in JetBrains: Services Tab --> Run all`` Or start the services through the defined run configs in the top left dropdown. Various run configurations are available for Docker, JUnit, SpringBoot, and Shell scripts.
Option 2: Docker
Start everything using docker-compose and the images published in the GitHub registry:
bash
docker compose -f docker/docker-compose.yml up
(Optional) For building the services into local docker containers:
bash
./scripts/spring-build-and-tag-images.sh
Option 3: Maven
Start the services using the Maven SpringBoot plugin (ensure the working directory for each service is the project root):
bash
mvn spring-boot:run -pl gateway
mvn spring-boot:run -pl servicediscovery
mvn spring-boot:run -pl userservice
...
That's it! All Docker files will be pulled, started, and waited for automatically, thanks to Docker Compose Support in Spring Boot.
Load Tests
Requirements:
- Python 3.10
- Poetry
bash
poetry install
poetry shell
locust --host http://localhost:8080 --processes 4
Deployment 🚀
Requirements:
- A Kubernetes cluster
- kube-prometheus on the cluster to measure resource usage
- Kepler on the cluster to measure energy consumption
- (Optionally) Kompose if you want to change configurations in Docker Compose and regenerate the kubeconfigs
Apply the deployment to your cluster:
bash
kubectl apply -f ./kubernetes/
Regenerate & apply all kubeconfig files:
bash
./scripts/deploy-kubernetes.sh
Known Issues 🦺
- If the Prometheus service from prometheus-operator/kube-prometheus can't be scraped by the Grafana instance, adjust the network policies.
- Locust running from a single host can run out of connections if the user count raises too high.
Author ✍️
Owner
- Name: Tobias Peslalz
- Login: Tobias-Pe
- Kind: user
- Repositories: 2
- Profile: https://github.com/Tobias-Pe
Citation (CITATION.cff)
cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
- family-names: "Peslalz"
given-names: "Tobias Leonhard Joschka"
license: MIT
keywords:
- Software
- Sustainability
- Green Software
- Energy efficiency
- Optimization
- Kubernetes
- Microservices
- Distributed Systems
- Monitoring tools
title: "Optimization of Energy Efficiency in Distributed Systems - Experiment"
repository-code: "https://github.com/Tobias-Pe/distributed-systems-energy-efficiency"
url: "https://github.com/Tobias-Pe/distributed-systems-energy-efficiency"
date-released: 2024-11-06
preferred-citation:
type: generic
authors:
- family-names: "Peslalz"
given-names: "Tobias Leonhard Joschka"
month: 11
title: "Experimental Analysis of Optimization Techniques for Energy Efficiency in Distributed Systems"
thesis-type: "Mastersthesis"
pages: 119
url: "https://opus4.kobv.de/opus4-hm/frontdoor/index/index/docId/573"
year: 2024
GitHub Events
Total
- Push event: 2
Last Year
- Push event: 2
Dependencies
- actions/checkout v3 composite
- actions/setup-java v3 composite
- advanced-security/maven-dependency-submission-action 571e99aab1055c2e71a1e2309b9691de18d6b7d6 composite
- docker/build-push-action v5 composite
- docker/login-action v3 composite
- docker/setup-buildx-action v2 composite
- actions/checkout v4 composite
- actions/setup-java v4 composite
- github/codeql-action/analyze v3 composite
- github/codeql-action/autobuild v3 composite
- github/codeql-action/init v3 composite
- ghcr.io/tobias-pe/microservices_energyefficiency/gateway latest
- ghcr.io/tobias-pe/microservices_energyefficiency/servicediscovery latest
- ghcr.io/tobias-pe/microservices_energyefficiency/userservice latest
- grafana/grafana 10.0.12 build
- prom/prometheus v2.50.1 build
- org.springframework.cloud:spring-cloud-starter-gateway
- org.springframework.cloud:spring-cloud-starter-netflix-eureka-client
- org.projectlombok:lombok
- org.springframework.boot:spring-boot-docker-compose
- org.springframework.boot:spring-boot-starter-actuator
- org.springframework.cloud:spring-cloud-starter
- org.springframework.boot:spring-boot-starter-test test
- org.springframework.cloud:spring-cloud-starter-netflix-eureka-server
- org.springframework.boot:spring-boot-starter-web
- org.springframework.cloud:spring-cloud-starter-netflix-eureka-client
- quay.io/ricardbejarano/snmp_exporter 0.25.0 build
- org.postgresql:postgresql
- org.springframework.boot:spring-boot-starter-data-jpa
- org.springframework.boot:spring-boot-starter-web
- org.springframework.cloud:spring-cloud-starter-netflix-eureka-client
- com.h2database:h2 test
- blinker 1.8.2
- brotli 1.1.0
- certifi 2024.2.2
- cffi 1.16.0
- charset-normalizer 3.3.2
- click 8.1.7
- colorama 0.4.6
- configargparse 1.7
- flask 3.0.3
- flask-cors 4.0.1
- flask-login 0.6.3
- gevent 24.2.1
- geventhttpclient 2.2.1
- greenlet 3.0.3
- idna 3.7
- itsdangerous 2.2.0
- jinja2 3.1.4
- locust 2.27.0
- markupsafe 2.1.5
- msgpack 1.0.8
- psutil 5.9.8
- pycparser 2.22
- pywin32 306
- pyzmq 26.0.3
- random-username 1.0.2
- requests 2.31.0
- setuptools 69.5.1
- urllib3 2.2.1
- werkzeug 3.0.3
- zope-event 5.0
- zope-interface 6.3
- locust ^2.27.0
- python ^3.12
- random-username ^1.0.2