|
| 1 | +# ADR-002: Use Docker for All Services Including UDP Tracker |
| 2 | + |
| 3 | +## Status |
| 4 | + |
| 5 | +Accepted |
| 6 | + |
| 7 | +## Date |
| 8 | + |
| 9 | +2025-01-07 |
| 10 | + |
| 11 | +## Context |
| 12 | + |
| 13 | +The Torrust Tracker Demo repository provides a complete deployment environment for |
| 14 | +the Torrust Tracker, including the UDP tracker component, HTTP tracker, REST API, |
| 15 | +and supporting services (Prometheus, Grafana, MySQL/SQLite). |
| 16 | + |
| 17 | +### Performance Considerations |
| 18 | + |
| 19 | +UDP tracker performance is critical for BitTorrent operations, and several |
| 20 | +performance optimization approaches were considered: |
| 21 | + |
| 22 | +1. **Host Network Mode**: Running UDP tracker containers with `--network=host` |
| 23 | + to avoid Docker networking overhead |
| 24 | +2. **Connection Tracking Disable**: Disabling `nf_conntrack` to reduce kernel |
| 25 | + overhead for UDP packet processing |
| 26 | +3. **Source Compilation**: Running the tracker binary directly on the host |
| 27 | + instead of using Docker containers |
| 28 | + |
| 29 | +### Technical Challenges Identified |
| 30 | + |
| 31 | +During investigation of performance optimizations, several issues were encountered: |
| 32 | + |
| 33 | +1. **Connection Tracking vs Docker**: Docker networking appears to rely on |
| 34 | + connection tracking (`nf_conntrack`) for proper packet routing. Disabling |
| 35 | + connection tracking while using Docker containers resulted in networking |
| 36 | + issues. |
| 37 | + |
| 38 | +2. **Host Mode Limitations**: While host networking mode worked, it created |
| 39 | + complications with service orchestration and port management in the demo |
| 40 | + environment. |
| 41 | + |
| 42 | +3. **Complexity vs Benefit**: Performance optimizations added significant |
| 43 | + complexity to the deployment process and infrastructure management. |
| 44 | + |
| 45 | +### Related Issues |
| 46 | + |
| 47 | +This decision addresses problems documented in previous GitHub issues: |
| 48 | + |
| 49 | +- [torrust/torrust-demo#27](https://github.com/torrust/torrust-demo/issues/27): |
| 50 | + Improve tracker performance by adjusting docker network configuration |
| 51 | +- [torrust/torrust-demo#72](https://github.com/torrust/torrust-demo/issues/72): |
| 52 | + Fix nf_conntrack table overflow causing UDP packet drops |
| 53 | + |
| 54 | +## Decision |
| 55 | + |
| 56 | +**Use Docker containers for all services in the Torrust Tracker Demo, including |
| 57 | +the UDP tracker, without host networking mode or connection tracking modifications.** |
| 58 | + |
| 59 | +## Rationale |
| 60 | + |
| 61 | +### Primary Goals Alignment |
| 62 | + |
| 63 | +The Torrust Tracker Demo repository has specific primary objectives: |
| 64 | + |
| 65 | +1. **Demo Environment Setup**: Provide a complete, working demonstration of |
| 66 | + Torrust Tracker functionality |
| 67 | +2. **Frequent Updates**: Update the demo environment regularly, ideally with |
| 68 | + every tracker release |
| 69 | +3. **Declarative Infrastructure**: Maintain Infrastructure as Code approach |
| 70 | + for reproducible deployments |
| 71 | +4. **Documentation Generation**: Serve as a reference implementation for |
| 72 | + deployment procedures |
| 73 | + |
| 74 | +### Performance vs Simplicity Trade-off |
| 75 | + |
| 76 | +While Docker networking may introduce some performance overhead compared to |
| 77 | +native host networking, the benefits outweigh the costs for this use case: |
| 78 | + |
| 79 | +**Benefits of Docker Approach:** |
| 80 | + |
| 81 | +- **Consistency**: All services use the same orchestration method |
| 82 | +- **Simplicity**: Single Docker Compose configuration manages all services |
| 83 | +- **Reproducibility**: Identical behavior across different environments |
| 84 | +- **Maintenance**: Easier updates and dependency management |
| 85 | +- **Documentation**: Clearer examples for users to follow |
| 86 | +- **Testing**: Simplified CI/CD and local testing procedures |
| 87 | + |
| 88 | +**Performance Considerations:** |
| 89 | + |
| 90 | +- The demo environment prioritizes functionality demonstration over peak performance |
| 91 | +- Users requiring maximum performance can reference this implementation and |
| 92 | + optimize for their specific production needs |
| 93 | +- Performance optimizations can be documented separately without complicating |
| 94 | + the base demo |
| 95 | + |
| 96 | +### Future Performance Documentation |
| 97 | + |
| 98 | +Performance optimization will be addressed through: |
| 99 | + |
| 100 | +1. **Dedicated Documentation**: Separate guides for production performance tuning |
| 101 | +2. **Configuration Examples**: Performance-focused configuration templates |
| 102 | +3. **Best Practices**: Documentation of optimization techniques and trade-offs |
| 103 | +4. **Potential Repositories**: Specialized repositories focused on high-performance |
| 104 | + deployments |
| 105 | + |
| 106 | +## Consequences |
| 107 | + |
| 108 | +### Positive Consequences |
| 109 | + |
| 110 | +- **Simplified Deployment**: Single orchestration method for all services |
| 111 | +- **Better Documentation**: Clear, consistent examples for users |
| 112 | +- **Easier Maintenance**: Streamlined update procedures |
| 113 | +- **Improved Testing**: Consistent test environments |
| 114 | +- **Faster Development**: Reduced complexity in infrastructure management |
| 115 | + |
| 116 | +### Negative Consequences |
| 117 | + |
| 118 | +- **Performance Overhead**: Some UDP tracker performance impact from Docker networking |
| 119 | +- **Resource Usage**: Additional container overhead compared to native binaries |
| 120 | +- **Networking Complexity**: Docker networking abstractions may obscure network issues |
| 121 | + |
| 122 | +### Mitigation Strategies |
| 123 | + |
| 124 | +1. **Clear Documentation**: Document the performance trade-offs explicitly |
| 125 | +2. **Performance Guidelines**: Provide separate documentation for production |
| 126 | + performance optimization |
| 127 | +3. **Configuration Examples**: Include performance-tuned configuration examples |
| 128 | +4. **Monitoring**: Include comprehensive monitoring to identify performance issues |
| 129 | + |
| 130 | +### Future Considerations |
| 131 | + |
| 132 | +- Monitor for significant performance issues in demo environment |
| 133 | +- Re-evaluate if Docker networking becomes a major limitation |
| 134 | +- Consider hybrid approaches for specific production use cases |
| 135 | +- Provide migration guides for users who need maximum performance |
| 136 | + |
| 137 | +## Alternatives Considered |
| 138 | + |
| 139 | +### Alternative 1: Host Network Mode |
| 140 | + |
| 141 | +**Description**: Run UDP tracker with `--network=host` |
| 142 | + |
| 143 | +**Pros**: |
| 144 | + |
| 145 | +- Better network performance |
| 146 | +- Reduced networking overhead |
| 147 | +- Direct access to host network interfaces |
| 148 | + |
| 149 | +**Cons**: |
| 150 | + |
| 151 | +- Port conflicts with host services |
| 152 | +- Reduced container isolation |
| 153 | +- Complications with service discovery |
| 154 | +- More complex firewall configuration |
| 155 | + |
| 156 | +**Decision**: Rejected due to increased complexity and orchestration challenges |
| 157 | + |
| 158 | +### Alternative 2: Native Binary Deployment |
| 159 | + |
| 160 | +**Description**: Compile and run tracker binary directly on host |
| 161 | + |
| 162 | +**Pros**: |
| 163 | + |
| 164 | +- Maximum performance |
| 165 | +- No container overhead |
| 166 | +- Direct kernel network access |
| 167 | + |
| 168 | +**Cons**: |
| 169 | + |
| 170 | +- Complex dependency management |
| 171 | +- Platform-specific build requirements |
| 172 | +- Reduced deployment consistency |
| 173 | +- More complex update procedures |
| 174 | +- Breaking changes to current infrastructure |
| 175 | + |
| 176 | +**Decision**: Rejected due to complexity and maintenance burden |
| 177 | + |
| 178 | +### Alternative 3: Hybrid Approach |
| 179 | + |
| 180 | +**Description**: Use Docker for supporting services, native binary for tracker |
| 181 | + |
| 182 | +**Pros**: |
| 183 | + |
| 184 | +- Performance optimization for critical component |
| 185 | +- Maintained orchestration for supporting services |
| 186 | + |
| 187 | +**Cons**: |
| 188 | + |
| 189 | +- Increased complexity |
| 190 | +- Mixed deployment methods |
| 191 | +- More complex CI/CD pipelines |
| 192 | +- Inconsistent documentation examples |
| 193 | + |
| 194 | +**Decision**: Rejected due to increased complexity and mixed approaches |
| 195 | + |
| 196 | +### Alternative 4: Conditional Deployment |
| 197 | + |
| 198 | +**Description**: Support both Docker and native deployment modes |
| 199 | + |
| 200 | +**Pros**: |
| 201 | + |
| 202 | +- User choice for performance vs simplicity |
| 203 | +- Flexibility for different use cases |
| 204 | + |
| 205 | +**Cons**: |
| 206 | + |
| 207 | +- Significant maintenance burden |
| 208 | +- Complex documentation |
| 209 | +- Multiple testing matrices |
| 210 | +- Potential for configuration drift |
| 211 | + |
| 212 | +**Decision**: Rejected due to maintenance complexity |
| 213 | + |
| 214 | +## References |
| 215 | + |
| 216 | +- [Torrust Tracker Documentation](https://docs.rs/torrust-tracker/) |
| 217 | +- [GitHub Issue #27: Docker Network Configuration](https://github.com/torrust/torrust-demo/issues/27) |
| 218 | +- [GitHub Issue #72: nf_conntrack Overflow](https://github.com/torrust/torrust-demo/issues/72) |
0 commit comments