Skip to main content

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

StepNormal TransferWith Sendfile
1Read file from disk to user spaceKernel reads and sends directly
2Copy from user space to kernel(Skipped)
3Kernel sends to networkKernel sends to network
ResultTwo copies, more CPUOne 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 ConfigurationTuning 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