Cloudflare Worker Limits and Quotas
This document outlines the limits and quotas that apply to FoxCloud when running on Cloudflare Workers.
Free Tier Limits
Execution Limits
- CPU Time: 10 ms per request (can be limiting for complex operations)
- Memory: 128 MB
- Execution Timeout: 30 seconds per request
- Concurrent Subrequests: 6 per request
- Total Subrequests: 1,000 per day
Data Transfer Limits
- Outbound Data Transfer: 100,000 requests per day
- Inbound Data Transfer: No specific limit
- KV Storage: 1 GB (if using Workers KV)
Request Limits
- Requests: 100,000 per day
- Request Size: 128 KB maximum
- Response Size: 128 KB maximum
Paid Tier Limits (Bundled)
Execution Limits
- CPU Time: 30 ms per request
- Memory: 128 MB
- Execution Timeout: 30 seconds per request
- Concurrent Subrequests: 6 per request
- Total Subrequests: 10,000 per day
Data Transfer Limits
- Outbound Data Transfer: 10 million requests per month
- Inbound Data Transfer: No specific limit
- KV Storage: 1 GB (if using Workers KV)
Paid Tier Limits (Unbound)
Execution Limits
- CPU Time: 30 ms per request
- Memory: 128 MB
- Execution Timeout: 30 seconds per request
- Concurrent Subrequests: 6 per request
- Total Subrequests: 100,000 per day
Data Transfer Limits
- Outbound Data Transfer: 100 million requests per month
- Inbound Data Transfer: No specific limit
- KV Storage: 1 GB (if using Workers KV)
Implications for FoxCloud
WebSocket Connections
- Each WebSocket connection consumes CPU time and memory
- Long-lived connections may hit execution timeout limits
- Consider connection duration when designing proxy behavior
Proxy Requests
- Each proxy request counts as a subrequest
- High-volume proxy usage may hit subrequest limits
- Consider caching strategies to reduce subrequests
Data Transfer
- Large data transfers may be limited by request/response size limits
- WebSocket data transfer is subject to these limits
- Consider data compression for large transfers
Optimization Strategies
CPU Usage Optimization
- Minimize Processing: Reduce unnecessary computations
- Efficient Algorithms: Use optimized algorithms for proxy operations
- Caching: Cache frequently accessed data
- Lazy Loading: Load resources only when needed
Memory Optimization
- Object Reuse: Reuse objects instead of creating new ones
- Memory Cleanup: Clean up unused variables and objects
- Stream Processing: Process data in streams rather than loading all at once
- Efficient Data Structures: Use appropriate data structures for the task
Request Optimization
- Batching: Batch multiple operations when possible
- Caching: Cache responses to reduce repeated requests
- Compression: Use compression for large data transfers
- Connection Reuse: Reuse connections when possible
Monitoring Usage
Built-in Monitoring
- Cloudflare Dashboard provides usage statistics
- Monitor requests, CPU time, and errors
- Set up alerts for quota limits
Custom Monitoring
- Implement custom logging for detailed metrics
- Track proxy usage by UUID
- Monitor connection durations
- Log errors and exceptions
Scaling Considerations
Traffic Spikes
- Free tier may not handle traffic spikes well
- Consider upgrading to paid tiers for production use
- Implement rate limiting to prevent abuse
- Use multiple proxy servers for load distribution
User Growth
- Plan for increased usage as user base grows
- Monitor quota usage regularly
- Upgrade tiers as needed
- Consider architectural changes for high scale
Best Practices for Staying Within Limits
Efficient Proxy Implementation
- Minimize Handshake Overhead: Optimize WebSocket connection establishment
- Efficient Data Forwarding: Use streaming for data transfer
- Connection Pooling: Reuse connections when possible
- Error Handling: Handle errors efficiently to avoid resource waste
Resource Management
- Memory Management: Clean up resources promptly
- CPU Usage: Optimize critical paths
- Subrequest Management: Minimize unnecessary subrequests
- Caching Strategy: Implement effective caching
Monitoring and Alerting
- Usage Tracking: Monitor quota usage regularly
- Performance Metrics: Track response times and error rates
- Alerting: Set up alerts for approaching limits
- Logging: Implement comprehensive logging
Troubleshooting Limit Issues
Identifying Limit Issues
- Check Cloudflare Dashboard for quota usage
- Monitor Worker logs for timeout errors
- Look for “CPU exceeded” or “memory limit” errors
- Monitor response times for degradation
Resolving Limit Issues
- Optimize Code: Reduce CPU and memory usage
- Upgrade Tier: Move to a higher tier if needed
- Implement Caching: Reduce repeated operations
- Load Distribution: Distribute load across multiple Workers
Additional Considerations
Regional Differences
- Limits may vary by region
- Check Cloudflare documentation for region-specific limits
- Consider deploying to multiple regions for better performance
Future Changes
- Cloudflare may change limits over time
- Stay updated with Cloudflare announcements
- Plan for potential limit changes
Special Use Cases
- High-frequency trading applications
- Real-time gaming applications
- Video streaming applications
- These may require special consideration for limits
By understanding and working within these limits, you can ensure a stable and performant FoxCloud deployment on Cloudflare Workers.