Sendfile Optimization
Learning Focus
By the end of this lesson you will understand what sendfile is and when to enable it for static file delivery.
What Sendfile Does
sendfile is a Linux kernel system call that transfers file data directly from disk to network socket without copying through user space. This is faster for large static file downloads because the kernel handles the transfer internally.
Normal vs Sendfile Transfer
| Step | Normal Transfer | With Sendfile |
|---|---|---|
| 1 | Read file from disk to user space | Kernel reads and sends directly |
| 2 | Copy from user space to kernel | (Skipped) |
| 3 | Kernel sends to network | Kernel sends to network |
| Result | Two copies, more CPU | One copy, less CPU |
When to Use Sendfile
- ✅ Large static file downloads (PDFs, ZIPs, media)
- ✅ High-volume static file serving
- ⚠️ Validate with your filesystem and container environment
- ❌ Not useful for small files or dynamic content
Configuration
Sendfile is typically enabled by default in OpenLiteSpeed. Check in Server Configuration → Tuning in WebAdmin.
Key Takeaways
- Sendfile reduces CPU usage for large static file transfers by keeping data in kernel space.
- It is useful for download-heavy sites but has minimal impact on small files.
- Validate behavior in container environments where filesystem behavior may differ.
What's Next
- Return to the Performance Optimization module for the complete overview.