-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
61ec643
commit 750d7aa
Showing
1 changed file
with
78 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,94 +1,115 @@ | ||
### player | ||
# 🎮 Player Module ![Version](https://img.shields.io/badge/version-1.0-blue) ![License](https://img.shields.io/badge/license-MIT-green) | ||
|
||
> A high-performance distributed player data management system utilizing multi-tier caching for optimal data consistency and access efficiency. | ||
--- | ||
|
||
## 📚 Table of Contents | ||
|
||
- [Introduction](#introduction) | ||
- [Automation](#automation) | ||
- [Key Components](#key-components) | ||
- [Data Processes](#data-processes) | ||
- [Performance Optimizations](#performance-optimizations) | ||
- [Summary](#summary) | ||
- [License](#license) | ||
|
||
--- | ||
|
||
## 📝 Introduction | ||
|
||
This module is designed for processing player data within a distributed environment, employing L1 (Caffeine) and L2 (Redis) caches to ensure data consistency and efficient access. | ||
|
||
# HOLY FUCK | ||
# THIS README It's really UGLY, someone will rewrite it, really | ||
--- | ||
|
||
## 🤖 Automation | ||
|
||
Automates the management and synchronization of player data across multiple layers, including caches and databases, ensuring seamless data flow and integrity. | ||
|
||
### automation | ||
--- | ||
|
||
We automate the management and synchronization of player data across multiple layers, including caches and databases. | ||
## 🔑 Key Components | ||
|
||
### key components | ||
### 🏗️ LegacyPlayerDataService | ||
|
||
#### legacyplayerdataservice | ||
- **Description**: A composite object that can be instantiated indefinitely, each instance having its own dedicated connections: | ||
- **Redis Connection**: For L2 caching layer. | ||
- **MongoDB Connection**: For persistent storage. | ||
- **Redis Streams Connection**: For inter-server communication. | ||
- **🔗 Redis Connection**: For L2 caching layer. | ||
- **💾 MongoDB Connection**: For persistent storage. | ||
- **🔄 Redis Streams Connection**: For inter-server communication. | ||
|
||
### 🗄️ Caching Layers | ||
|
||
#### caching layers | ||
- **L1 Cache (Caffeine)**: In-memory cache designed for online player data, offering ultra-fast data access. | ||
- **L2 Cache (Redis)**: Secondary caching layer meant for persistent storage of player data, providing a centralized view. | ||
|
||
### player data query process | ||
--- | ||
|
||
1. **Check L1 Cache**: | ||
- **Note**: This layer is optimized for online players and is not queried for offline data. | ||
## 🔄 Data Processes | ||
|
||
2. **Query L2 Cache (Redis)**: | ||
- **Cache Hit**: | ||
- Retrieve data from L2. | ||
- Store the retrieved data in L1 for faster future access. | ||
- Return data to the requester. | ||
- **Cache Miss**: | ||
- Proceed to query the MongoDB database. | ||
### 📊 Player Data Query Process | ||
|
||
1. **Check L1 Cache**: | ||
- **Note**: Optimized for online players; not queried for offline data. | ||
2. **Query L2 Cache (Redis)**: | ||
- **Cache Hit**: Retrieve data, store in L1, return to requester. | ||
- **Cache Miss**: Query MongoDB. | ||
3. **Query Database (MongoDB)**: | ||
- **Success**: | ||
- Retrieve player data from the database. | ||
- Store this data in L1 for quick future access. | ||
- Return the data to the requester. | ||
- **No Data Found**: | ||
- Create a new player record and store it directly in L1. | ||
- **Success**: Retrieve, store in L1, return data. | ||
- **No Data Found**: Create new record, store in L1. | ||
|
||
### player logout process | ||
### 🚪 Player Logout Process | ||
|
||
1. **Retrieve All Instances**: Gather all instances of `LegacyPlayerDataService`. | ||
2. **Compare L1 and L2 Cache**: | ||
- **If Consistent**: No changes are needed. | ||
- **If Inconsistent**: Update the L2 cache with data from the L1 cache. | ||
3. **Remove Player Data**: Delete the player’s data from the L1 cache to maintain its integrity. | ||
- **Consistent**: No changes needed. | ||
- **Inconsistent**: Update L2 with L1 data. | ||
3. **Remove Player Data**: Delete from L1 to maintain integrity. | ||
|
||
### data synchronization | ||
### 🔄 Data Synchronization | ||
|
||
1. **Synchronize L1 to L2**: Transfer all current data from the L1 caches to the L2 cache. | ||
2. **Persist L2 Data to Database**: Save data from the L2 cache into MongoDB for persistent storage. | ||
1. **Synchronize L1 to L2**: Transfer all data from L1 to L2. | ||
2. **Persist L2 Data to Database**: Save L2 data into MongoDB. | ||
|
||
### player data modification process | ||
### ✏️ Player Data Modification Process | ||
|
||
1. **Publish Update Tasks Using Redis Stream**: | ||
- Send update tasks via Redis Stream to ensure distributed synchronization. | ||
- Directly update the content in the L2 cache. | ||
- **If the L2 Cache Misses the Data**: Update it in the database instead. | ||
|
||
- Ensure distributed synchronization. | ||
- Update L2 cache directly. | ||
- **L2 Cache Miss**: Update database. | ||
2. **Process on Each Server**: | ||
- **If Player is Online**: Retrieve the updated data from the L2 cache and synchronize it to the L1 cache. | ||
- **Online Player**: Sync updated data from L2 to L1. | ||
|
||
### player data acquisition process | ||
### 📥 Player Data Acquisition Process | ||
|
||
1. **L1 L2 data synchronization**: Use Redis Stream to synchronize all server L1 L2 caches. | ||
2. **Search**: Search directly in the L2 cache, and if it does not hit, search in the database | ||
1. **L1 L2 Data Synchronization**: Use Redis Stream for synchronization. | ||
2. **Search**: Directly in L2; if miss, search database. | ||
|
||
### performance optimizations | ||
--- | ||
|
||
- **L1 Cache**: | ||
- Retains data indefinitely for active players, enabling rapid access without expiration management. | ||
## ⚙️ Performance Optimizations | ||
|
||
- **L2 Cache**: | ||
- Functions as long-term storage with configurable expiration policies to manage stale data. | ||
- **L1 Cache**: Indefinite retention for active players, rapid access. | ||
- **L2 Cache**: Long-term storage with expiration policies. | ||
- **Database**: Accessed mainly on cache misses, reducing load. | ||
|
||
- **Database**: | ||
- Accessed mainly when the data is not found in either cache, minimizing database load and enhancing performance. | ||
--- | ||
|
||
### summary | ||
## 📜 Summary | ||
|
||
This architecture utilizes a multi-tier caching strategy for efficient player data management: | ||
- **L1 Cache (Caffeine)**: Speedy access for online players. | ||
- **L2 Cache (Redis)**: Centralized caching of persistent data. | ||
- **Database (MongoDB)**: Main storage for cache misses. | ||
- **Redis Streams**: Real-time server synchronization. | ||
- **LegacyPlayerDataService**: Dedicated connections for Redis, MongoDB, and Redis Streams. | ||
|
||
In conclusion, this design maximizes data retrieval efficiency, ensures consistency across distributed servers, and optimizes overall performance, delivering a seamless experience for players. | ||
|
||
--- | ||
|
||
## 📄 License | ||
|
||
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. | ||
|
||
|
||
- **L1 Cache (Caffeine)**: Provides speedy access for online players. | ||
- **L2 Cache (Redis)**: Centralized caching of persistent player data. | ||
- **Database (MongoDB)**: Acts as the main storage when cache misses occur. | ||
- **Redis Streams**: Enables real-time synchronization between servers for consistent data. | ||
- **LegacyPlayerDataService**: Instantiable composite objects with dedicated connections for Redis, MongoDB, and Redis Streams. | ||
|
||
In conclusion, this design maximizes data retrieval efficiency, ensures consistency across distributed servers, and optimizes overall performance, thereby delivering a seamless experience for players. |