Fabflix - Team b221 README (public copy) ======================================= Published on xxxmnalx.com by Leyang Cheng. The original lives in a private UCI CS 122B GitHub Classroom repository. Changes from the original: student UCInetIDs removed and one full-width comma normalized; text otherwise unchanged. Image links (./img/...) point to files in that repository and are not reproduced here. ##Team b221 Project 5 (current) - #### Project 5 Video Demo Link: https://youtu.be/858L0gIJwhU # Service Endpoints ## 1. Login Service Service name: fabflix-login-service This service handles authentication requests and creates Redis-backed sessions. Hosted endpoints: /api/login /api/dashboard/login Description: /api/login Handles customer login requests. Validates customer credentials against the database, creates a Redis-backed session, and returns a session cookie named `redisSessionId`. /api/dashboard/login Handles employee/admin login requests for the dashboard. After successful authentication, it creates a Redis-backed employee session and returns a session cookie named `redisEmployeeSessionId`. Session TTL: 24 hours (refreshed on valid requests). ## 2. Movies Service Service name: fabflix-movies-service This service handles all application functionality other than login. Hosted endpoints include: Movie browsing /api/index /api/movie-list /api/single-movie /api/single-star /api/genres Search / autocomplete /api/movie-suggestion Shopping cart /api/cart /api/checkout /api/confirmation Dashboard management /api/dashboard/add-movie /api/dashboard/add-star /api/dashboard/metadata State / helper endpoint /api/movie-list-state Static frontend pages /login.html /index.html /movie-list.html /single-movie.html /single-star.html /cart.html /checkout.html /confirmation.html Authentication / filtering `LoginFilter` is mapped to `/*` and enforces Redis-backed authentication for protected routes. Publicly allowed resources include: - /login.html - /index.html - /index.js - /login.js - /favicon.ico - /api/login - /api/dashboard/login - /_dashboard/login.html Requests to dashboard routes (`/_dashboard` or `/api/dashboard`) are validated using the employee session cookie `redisEmployeeSessionId`. Other protected application routes are validated using the customer session cookie `redisSessionId`. In addition, `SearchTimingFilter` is applied to `/api/movie-list`. ## 3. Redis Service Service name: redis-service Redis is used as a shared session store between the login and movies services. Internal endpoint: redis-service:6379 Purpose: Stores session data for both customer and employee authentication. Customer session format: session: -> JSON session object Example: { "username": "user@example.com", "customerId": 5, "loginTime": "2026/03/14 10:30:00" } Employee session format: employee_session: -> JSON session object Example: { "email": "admin@example.com", "loginTime": "2026/03/14 10:35:00" } On each authenticated request, the session TTL is refreshed to 24 hours. This allows both services to validate user authentication across different pods. **Leyang Cheng**: - Run Fabflix in a Docker container - Set up a Kubernetes (K8s) cluster on AWS - Run Fabflix on the cluster: write fabflix.yaml and ingress.yaml - Revise Fabflix using a multi-service architecture - video recording **Songhao Gao**: - help running Fabflix on the cluster - Revise Fabflix using a multi-service architecture - Debugging project - Readme editing # Team b221 Project 4 (achieved) - # General - #### Team#: b221 - #### Names: Leyang Cheng, Songhao Gao - #### Project 4 Video Demo Link: - Part1: https://youtu.be/-eZbG0KvR84 - Part2: https://youtu.be/c_92zldu0Bk - #### Instruction of deployment: - #### Collaborations and Work Distribution: - Leyang Cheng: - MySQL Master-Slave replication setup, Fuzzy Search, AutoComplete, Demo Video - Songhao Gao: - Connection pooling implementation, Task 5 JMeter Testing, demo video - # Extra Credit Fuzzy Search - #### Design: - The goal is to return relevant movies based on query that input from user and compare with the title inside the database. We already have full-text search from last project thus based on that, we UNION with two new strategies: LIKE and edrec from Flamingo lib. The LIKE is for substring matching and the edrec is to handle misspellings. Instrad of using ed or edth, we use edrec because consider that movies title is usually not only one word like "A Love Story", when a user type love they might want to get the resut of movies relate to love. When they misspelling to Lovee, they might still want to see the movies relate to Love like "A Love Story". In this case, edth("Lovee","A Love Story",2) is comparing between Lovee and a whole title and is defintely larger than 2. Thus, We use edrec to compare "Lovee" with each word inside the title. - Also, we implement dynamic threshold for edrec that short queries <= 4 chars use threshold 1. medium use 2, longer >= 8 use 3 to enhance performance and usablitiy. - #### Implementation: - We implement the Fuzzy Search in SQL query in MoveTitleSuggestion.java. The SQL use UNION (following instruction) to connect three strategy (full text, LIKE, edrec). We also implement for the main search through sql query in movies.MovieListServlet.java. We use the edrec from Flamingo toolkit. - # Connection Pooling - #### Include the filename/path of all code/configuration files in GitHub of using JDBC Connection Pooling. - `WebContent/META-INF/context.xml` - `src/movies.AddMovieServlet.java` - `src/movies.AddStarServlet.java` - `src/movies.CheckoutServlet.java` - `src/movies.CartServlet.java` - `src/movies.ConfirmationServlet.java` - `src/login.DashboardLoginServlet.java` - `src/movies.GenreServlet.java` - `src/login.LoginServlet.java` - `src/movies.MetadataServlet.java` - `src/movies.MovieListServlet.java` - `src/movies.MovieTitleSuggestion.java` - `src/movies.SingleMovieServlet.java` - `src/movies.SingleStarServlet.java` - #### Explain how Connection Pooling is utilized in the Fabflix code. - In `context.xml`, two JDBC connection pools are defined using org.apache.tomcat.jdbc.pool.DataSourceFactory: jdbc/masterdb and jdbc/slavedb - each pool configured with maxTotal = 100 and maxIdle = 30. - Servlets obtain a DataSource via lookup in their init()method and call dataSurce.getConnection() per request. - Connetction return to the pool when closed. - #### Explain how Connection Pooling works with two backend SQL. - `jdbc/masterdb` points to the Master MySQL instance and `jdbc/slavedb` points to the Slave MySQL instance. - Each Tomcat backend runs the same context.xml with both pools. Write operation would loop up masterdb and read operation servlets would loop up slavedb. - # Master/Slave - #### Include the filename/path of all code/configuration files in GitHub of routing queries to Master/Slave SQL. - Write (masterdb): `src/movies.AddMovieServlet.java`, `src/movies.AddStarServlet.java`, `src/movies.CheckoutServlet.java` - Read (slavedb): `src/movies.CartServlet.java`, `src/movies.ConfirmationServlet.java`, `src/login.DashboardLoginServlet.java`, `src/movies.GenreServlet.java`, `src/login.LoginServlet.java`, `src/movies.MetadataServlet.java`, `src/movies.MovieListServlet.java`, `src/movies.MovieTitleSuggestion.java`, `src/movies.SingleMovieServlet.java`, `src/movies.SingleStarServlet.java` - #### How read/write requests were routed to Master/Slave SQL? - Servlets that perform INSERT operation would use masterdb and SELECT operation would use slavedb - Master replicated data to the Slave via MySQL binary log replication. so Slave would able to be up to date. - # JMeter TS/TJ Time Logs - #### Instructions of how to use the `log_processing.*` script to process the JMeter logs. - All TS/TJ logs generated during JMeter testing are stored in: - /var/log/tomcat10/fabflix_search_timing.log - For submission, we copied the logs into the repository under: - logs/.log - To compute the average TS and TJ values: - python3 log_processing.py logs/.log - Example: - python3 log_processing.py logs/single_instance_http_10threads.log - # JMeter TS/TJ Time Measurement Report | **Single-instance Version Test Plan** | **Graph Results Screenshot** | **Average Query Time(ms)** | **Average Search Servlet Time(ms)** | **Average JDBC Time(ms)** | **Analysis** | |------------------------------------------------|------------------------------|----------------------------|-------------------------------------|---------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | Case 1: HTTP/1 thread | ![](./img/single_case1.png) | 769.12 | 753.58 | 753.47 | Query time is slightly higher than servlet time due to network latency and client-side overhead. TS and TJ are nearly identical, indicating that most of the time is spent in JDBC execution | | Case 2: HTTP/10 threads | ![](./img/single_case2.png) | 7393.55 | 7374.76 | 7374.65 | The servlet time and JDBC time are almost identical, indicating that nearly all request processing time is spent executing database queries. | | Case 3: HTTPS/10 threads | ![](./img/single_case3.png) | 7415.29 | 7393.49 | 7392.89 | The servlet time and JDBC time are nearly identical, indicating that almost all processing time is spent in database query execution. | | Case 4: HTTP/10 threads/No connection pooling | ![](./img/single_case4.png) | 13113.38 | 13093.10 | 13092.17 | In the no-pooling configuration, the average query time increased to 13113 ms, compared to 7415 ms with connection pooling enabled. This significant performance degradation occurs because each request creates and closes a new database connection, which introduces expensive connection setup overhead. | | **Scaled Version Test Plan** | **Graph Results Screenshot** | **Average Query Time(ms)** | **Average Search Servlet Time(ms)** | **Average JDBC Time(ms)** | **Analysis** | |------------------------------------------------|------------------------------|----------------------------|-------------------------------------|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | Case 1: HTTP/1 thread | ![](./img/scaled_case1.png) | 13003.16 | 12982.30 | 12982.08 | The servlet and JDBC times are almost identical, indicating that most of the request processing time is spent in database execution. Compared to the single-instance no-pooling configuration (~13113 ms), the performance improvement is minimal. This shows that horizontal scaling alone does not eliminate the overhead of creating new database connections for each request. | | Case 2: HTTP/10 threads | ![](./img/scaled_case2.png) | 12963.80 | 12943.19 | 12943.01 | The servlet time and JDBC time remain almost identical, confirming that database execution and connection setup dominate request latency. | | Case 3: HTTP/10 threads/No connection pooling | ![](./img/scaled_case3.png) | 7573.70 | 7553.60 | 7553.05 | In the scaled configuration without connection pooling, the average response time decreased to 7574 ms, compared to 13113 ms in the single-instance no-pooling setup. Therefore, while scaling improves throughput, it does not fundamentally resolve database performance limitations. | - # timing_logs_file: (./aws_timing_logs/) # Team b221 Project 3 (achieved) ## List of file use prep statement movies.GenreServlet.java movies.CartServlet.java movies.SingleStarServlet.java movies.ConfirmationServlet.java movies.AddStarServlet.java login.LoginServlet.java movies.MovieListServlet.java movies.SingleMovieServlet.java PaymentServlet.java movies.AddMovieServlet.java ## CSV Loading Performance Report ### Baseline (Naive Implementation) Per-row SELECT to check duplicates Per-row SELECT for foreign key existence Per-row INSERT [LoadGenres] csv_package/genres.csv ms= 284 [LoadStars] csv_package/stars.csv ms=384525 [LoadMovies] csv_package/movies.csv ms= 77163 [LoadRatings] csv_package/ratings.csv ms= 1087 [LoadGenresInMovies] csv_package/genres_in_movies.csv ms=6357 [LoadStarsInMovies] csv_package/stars_in_movies.csv ms=38171 TOTAL(ms) = 507772 = 8.46 mins ### Optimization1 since there is no space requirement, I choose to trade space for time that store in memory at once to avoid per-row SELECT check per row SELECT is wasting time due to tons of round trip, also shows in high CPU usage (in my case is up to about 85%) Specifically: I preload the data before actually loading the csv data into db for checking [LoadGenres] csv_package/genres.csv ms= 155 [LoadStars] csv_package/stars.csv ms=4264 [LoadMovies] csv_package/movies.csv ms= 2553 [LoadRatings] csv_package/ratings.csv ms= 398 [LoadGenresInMovies] csv_package/genres_in_movies.csv ms=2178 [LoadStarsInMovies] csv_package/stars_in_movies.csv ms=10499 TOTAL(ms) = 21498 = 21.5s ### Optimization2 To further reduce the roundtrips, instead of sending sql command to DB per row, collect enough amount of commands and send in batch would largely reduce roundtrips Thus, I implement the send in batc h for those csv that contain large amount of data and frequently send commands to DB [LoadGenres] csv_package/genres.csv ms= 118 [LoadStars] csv_package/stars.csv ms=722 [LoadMovies] csv_package/movies.csv ms= 486 [LoadRatings] csv_package/ratings.csv ms= 100 [LoadGenresInMovies] csv_package/genres_in_movies.csv ms=336 [LoadStarsInMovies] csv_package/stars_in_movies.csv ms=1323 TOTAL(ms) = 4736 see loader_report_opt2 ## Contribution Project3: **Leyang Cheng**: reCAPTCHA (dashboard login) Data Loading: CSV, report data recording the demonstration video and testing to detect bugs HTTPS implementing **Songhao Gao**: reCAPTCHA (customer login) create and implement Employee Dashboard: html js css (add star, add movies) Password Encryption: update user password, implement encryption Full-text Search: Full-text search on the movies title field # Team b221 Project 2 (achieved) ## Substring Matching Design In Project 2, substring matching is implemented on the Movie List Page search functionality. **Backend Design** Substring matching is handled in movies.MovieListServlet using SQL LIKE queries with wildcards: **Title search:** m.title LIKE %keyword% **Director search:** m.director LIKE %keyword% **Star name search:** s.name LIKE %keyword% This allows users to retrieve movies even if the search keyword is only a substring of the full title, director name, or star name. PreparedStatements are used to safely pass user input and prevent SQL injection. **Case Handling** For browsing by title prefix, case-insensitive matching is applied using: UPPER(m.title) LIKE 'PREFIX%' A special * prefix is supported to browse titles starting with non-alphanumeric characters using SQL REGEXP. ## Contribution Project2: **Leyang Cheng**: create and implement 'Login Page', create login filter servlet, js html create and implement 'Shopping Cart' (servlet, js, html) create and implement 'cartpage payment' and 'confirmation page' (servlet, js, html) recording the demonstration video and testing to detect bugs **Songhao Gao**: extend Movie List Page (sorting, pagination, prev/next, page size control) implement movies searching and browsing (genre, title prefix, substring matching) extend Single Movie Page (all genres, all stars, rating, hyperlinks) extend Single Star Page (all movies with sorting and hyperlinks) implement session-based jump functionality to preserve movies list state Writing report # Team b221 Project 1 (achieved) ## demo video URL: https://youtu.be/vTqszc7_obk ## Contribution Project 1: **Leyang Cheng**: create and implement 'single star page' (servlet, js, html) create and implement 'movies list page' (servlet, js, html) Writing report **Songhao Gao**: create and implement 'create_table.sql' create and implement 'single movies page' (servlet, js, html) recording the demonstration video and testing to detect bugs beuatify single movies page with css