This project demonstrates the process of identifying and resolving performance bottlenecks in a Java application. We take a simple event counting program and optimize it for better performance while adhering to 12-factor app principles.
- Identify common performance bottlenecks in Java code
- Apply profiling techniques to pinpoint issues
- Implement optimization strategies to improve application speed
- Demonstrate adherence to 12-factor app methodology
src/main/java/EventCounter.java
: Original version of the applicationsrc/main/java/OptimizedCountEvents.java
: Optimized version of the applicationprofiling_results/
: Directory containing profiling data and analysisdocs/performance_report.pdf
: Detailed report on optimization process and results
- Java Development Kit (JDK) 11 or higher
- VisualVM (for profiling)
-
Compile the Java files:
javac src/main/java/*.java
-
Run the original version:
java -cp src/main/java CountEvents
-
Run the optimized version:
java -cp src/main/java OptimizedCountEvents
To profile the application using VisualVM:
- Start VisualVM
- Run the application with the following command:
java -Dcom.sun.management.jmxremote -cp src/main/java CountEvents
- In VisualVM, select the running CountEvents application
- Use the CPU and Memory profiler to analyze performance
- Identify Bottlenecks: Used VisualVM to profile CPU and memory usage
- Code Analysis: Reviewed code for potential improvements
- Implement Optimizations:
- Removed unnecessary file I/O operations
- Optimized memory usage by replacing large arrays with running sums
- Improved time calculations
- Enhanced event tracking logic
- Verify Improvements: Re-profiled the optimized code to confirm performance gains
- Significant reduction in CPU usage
- Decreased memory allocation
- Improved overall execution time
- Better adherence to 12-factor app principles
This project demonstrates several 12-factor app principles:
- Config: Use of environment variables for configuration
- Processes: Stateless and share-nothing architecture
- Disposability: Fast startup and graceful shutdown
- Logs: Output to stdout instead of log files
- Implement dependency management (e.g., Maven or Gradle)
- Set up CI/CD pipeline for automated testing and deployment
- Containerize the application for better dev/prod parity
I welcome contributions! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE.md file for details.