Refactor configuration management and enhance build process
- Introduced a YAML-based configuration system, allowing for automatic generation of a default `config.yaml` file. - Updated the application to load configuration settings from the YAML file, improving flexibility and ease of use. - Added a Makefile to streamline development tasks, including running the application, testing, and managing dependencies. - Enhanced `.gitignore` to include build artifacts and configuration files. - Removed unused Prometheus metrics and related code to simplify the codebase. - Updated dependencies in `go.mod` and `go.sum` for improved functionality and performance.
This commit is contained in:
224
README.md
224
README.md
@@ -10,30 +10,120 @@ SteamCache2 is a blazing fast download cache for Steam, designed to reduce bandw
|
||||
- Reduces bandwidth usage
|
||||
- Easy to set up and configure aside from dns stuff to trick Steam into using it
|
||||
- Supports multiple clients
|
||||
- **NEW:** YAML configuration system with automatic config generation
|
||||
- **NEW:** Simple Makefile for development workflow
|
||||
- Cross-platform builds (Linux, macOS, Windows)
|
||||
|
||||
## Usage
|
||||
## Quick Start
|
||||
|
||||
1. Start the cache server:
|
||||
```sh
|
||||
./SteamCache2 --memory 1G --disk 10G --disk-path tmp/disk
|
||||
```
|
||||
### First Time Setup
|
||||
|
||||
### Advanced Configuration
|
||||
1. **Clone and build:**
|
||||
```bash
|
||||
git clone <repository-url>
|
||||
cd SteamCache2
|
||||
make # This will run tests and build the application
|
||||
```
|
||||
|
||||
2. **Run the application** (it will create a default config):
|
||||
```bash
|
||||
./steamcache2
|
||||
# or on Windows:
|
||||
steamcache2.exe
|
||||
```
|
||||
|
||||
The application will automatically create a `config.yaml` file with default settings and exit, allowing you to customize it.
|
||||
|
||||
3. **Edit the configuration** (`config.yaml`):
|
||||
```yaml
|
||||
listen_address: :80
|
||||
cache:
|
||||
memory:
|
||||
size: 1GB
|
||||
gc_algorithm: lru
|
||||
disk:
|
||||
size: 10GB
|
||||
path: ./disk
|
||||
gc_algorithm: hybrid
|
||||
upstream: "https://steam.cdn.com" # Set your upstream server
|
||||
```
|
||||
|
||||
4. **Run the application again:**
|
||||
```bash
|
||||
make run # or ./steamcache2
|
||||
```
|
||||
|
||||
### Development Workflow
|
||||
|
||||
```bash
|
||||
# Run all tests and start the application (default target)
|
||||
make
|
||||
|
||||
# Run only tests
|
||||
make test
|
||||
|
||||
# Run with debug logging
|
||||
make run-debug
|
||||
|
||||
# Download dependencies
|
||||
make deps
|
||||
|
||||
# Show available commands
|
||||
make help
|
||||
```
|
||||
|
||||
### Command Line Flags
|
||||
|
||||
While most configuration is done via the YAML file, some runtime options are still available as command-line flags:
|
||||
|
||||
```bash
|
||||
# Use a custom config file
|
||||
./steamcache2 --config /path/to/my-config.yaml
|
||||
|
||||
# Set logging level
|
||||
./steamcache2 --log-level debug --log-format json
|
||||
|
||||
# Set number of worker threads
|
||||
./steamcache2 --threads 8
|
||||
|
||||
# Show help
|
||||
./steamcache2 --help
|
||||
```
|
||||
|
||||
### Configuration
|
||||
|
||||
SteamCache2 uses a YAML configuration file (`config.yaml`) for all settings. Here's a complete configuration example:
|
||||
|
||||
```yaml
|
||||
# Server configuration
|
||||
listen_address: :80
|
||||
|
||||
# Cache configuration
|
||||
cache:
|
||||
# Memory cache settings
|
||||
memory:
|
||||
# Size of memory cache (e.g., "512MB", "1GB", "0" to disable)
|
||||
size: 1GB
|
||||
# Garbage collection algorithm
|
||||
gc_algorithm: lru
|
||||
|
||||
# Disk cache settings
|
||||
disk:
|
||||
# Size of disk cache (e.g., "10GB", "50GB", "0" to disable)
|
||||
size: 10GB
|
||||
# Path to disk cache directory
|
||||
path: ./disk
|
||||
# Garbage collection algorithm
|
||||
gc_algorithm: hybrid
|
||||
|
||||
# Upstream server configuration
|
||||
# The upstream server to proxy requests to
|
||||
upstream: "https://steam.cdn.com"
|
||||
```
|
||||
|
||||
#### Garbage Collection Algorithms
|
||||
|
||||
SteamCache2 supports multiple garbage collection algorithms for both memory and disk caches:
|
||||
|
||||
```sh
|
||||
# Use LFU for memory cache (good for long-running servers)
|
||||
./SteamCache2 --memory 4G --memory-gc lfu --disk 100G --disk-gc lru
|
||||
|
||||
# Use FIFO for predictable eviction (good for testing)
|
||||
./SteamCache2 --memory 2G --memory-gc fifo --disk 50G --disk-gc fifo
|
||||
|
||||
# Use size-based eviction for disk cache
|
||||
./SteamCache2 --memory 1G --disk 200G --disk-gc largest
|
||||
```
|
||||
SteamCache2 supports different garbage collection algorithms for memory and disk caches, allowing you to optimize performance for each storage tier:
|
||||
|
||||
**Available GC Algorithms:**
|
||||
|
||||
@@ -44,13 +134,30 @@ SteamCache2 supports multiple garbage collection algorithms for both memory and
|
||||
- **`smallest`**: Size-based - evicts smallest files first (maximizes cache hit rate)
|
||||
- **`hybrid`**: Combines access time and file size for optimal eviction
|
||||
|
||||
**Recommended Algorithms by Cache Type:**
|
||||
|
||||
**For Memory Cache (Fast, Limited Size):**
|
||||
- **`lru`** - Best overall performance, good balance of speed and hit rate
|
||||
- **`lfu`** - Excellent for gaming cafes where popular games stay cached
|
||||
- **`hybrid`** - Optimal for mixed workloads with varying file sizes
|
||||
|
||||
**For Disk Cache (Slow, Large Size):**
|
||||
- **`hybrid`** - Recommended for optimal performance, balances speed and storage efficiency
|
||||
- **`largest`** - Good for maximizing number of cached files
|
||||
- **`lru`** - Reliable default with good performance
|
||||
|
||||
**Use Cases:**
|
||||
- **LAN Events**: Use `lfu` for memory caches to keep popular games
|
||||
- **Gaming Cafes**: Use `hybrid` for balanced performance
|
||||
- **Gaming Cafes**: Use `lfu` for memory, `hybrid` for disk
|
||||
- **LAN Events**: Use `lfu` for memory, `hybrid` for disk
|
||||
- **Home Use**: Use `lru` for memory, `hybrid` for disk
|
||||
- **Testing**: Use `fifo` for predictable behavior
|
||||
- **Large Files**: Use `largest` to prioritize keeping many small files
|
||||
2. Configure your DNS:
|
||||
- If your on Windows and don't want a whole network implementation (THIS)[#windows-hosts-file-override]
|
||||
- **Large File Storage**: Use `largest` for disk to maximize file count
|
||||
|
||||
### DNS Configuration
|
||||
|
||||
Configure your DNS to direct Steam traffic to your SteamCache2 server:
|
||||
|
||||
- If you're on Windows and don't want a whole network implementation, see the [Windows Hosts File Override](#windows-hosts-file-override) section below.
|
||||
|
||||
### Windows Hosts File Override
|
||||
|
||||
@@ -85,6 +192,77 @@ SteamCache2 supports multiple garbage collection algorithms for both memory and
|
||||
|
||||
This will direct any requests to `lancache.steamcontent.com` to your SteamCache2 server.
|
||||
|
||||
## Building from Source
|
||||
|
||||
### Prerequisites
|
||||
|
||||
- Go 1.19 or later
|
||||
- Make (optional, but recommended)
|
||||
|
||||
### Build Commands
|
||||
|
||||
```bash
|
||||
# Clone the repository
|
||||
git clone <repository-url>
|
||||
cd SteamCache2
|
||||
|
||||
# Download dependencies
|
||||
make deps
|
||||
|
||||
# Run tests
|
||||
make test
|
||||
|
||||
# Build for current platform
|
||||
go build -o steamcache2 .
|
||||
|
||||
# Build for specific platforms
|
||||
GOOS=linux GOARCH=amd64 go build -o steamcache2-linux-amd64 .
|
||||
GOOS=windows GOARCH=amd64 go build -o steamcache2-windows-amd64.exe .
|
||||
```
|
||||
|
||||
### Development
|
||||
|
||||
```bash
|
||||
# Run in development mode with debug logging
|
||||
make run-debug
|
||||
|
||||
# Run all tests and start the application
|
||||
make
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Common Issues
|
||||
|
||||
1. **"Config file not found" on first run**
|
||||
- This is expected! SteamCache2 will automatically create a default `config.yaml` file
|
||||
- Edit the generated config file with your desired settings
|
||||
- Run the application again
|
||||
|
||||
2. **Permission denied when creating config**
|
||||
- Make sure you have write permissions in the current directory
|
||||
- Try running with elevated privileges if necessary
|
||||
|
||||
3. **Port already in use**
|
||||
- Change the `listen_address` in `config.yaml` to a different port (e.g., `:8080`)
|
||||
- Or stop the service using the current port
|
||||
|
||||
4. **High memory usage**
|
||||
- Reduce the memory cache size in `config.yaml`
|
||||
- Consider using disk-only caching by setting `memory.size: "0"`
|
||||
|
||||
5. **Slow disk performance**
|
||||
- Use SSD storage for the disk cache
|
||||
- Consider using a different GC algorithm like `hybrid`
|
||||
- Adjust the disk cache size to match available storage
|
||||
|
||||
### Getting Help
|
||||
|
||||
- Check the logs for detailed error messages
|
||||
- Run with `--log-level debug` for more verbose output
|
||||
- Ensure your upstream server is accessible
|
||||
- Verify DNS configuration is working correctly
|
||||
|
||||
## License
|
||||
|
||||
See the [LICENSE](LICENSE) file for details.
|
||||
|
||||
Reference in New Issue
Block a user