Varidata News Bulletin
Knowledge Base | Q&A | Latest Technology | IDC Industry News
Varidata Blog

Linux File Descriptor Limits Optimization for High Concurrency

Release Date: 2026-02-28
Steps to optimize Linux file descriptor limits for high concurrency

For developers and system administrators managing Linux-based hosting or colocation environments, encountering the “Too many open files” error is a common frustration—especially in high-concurrency scenarios. This issue stems from Linux file descriptor (FD) limits, which restrict the number of open files, network sockets, and IPC handles a system or process can manage. Mastering Linux file descriptor limits optimization is critical to ensuring system stability, reducing connection drops, and maximizing the performance of your infrastructure. Below is a technical deep dive into identifying, configuring, and validating FD limit optimizations, tailored for technical professionals seeking reliable, production-grade solutions.

What Are Linux File Descriptor (FD) Limits?

In Linux, every open resource—whether a file, network socket, pipe, or device—is assigned a unique integer identifier called a file descriptor. The operating system enforces two core types, each operating at different levels, to prevent resource exhaustion:

  • Soft vs. Hard Limits: The soft limit is a configurable threshold that the system enforces but allows temporary overrides (for privileged users), while the hard limit is a rigid ceiling set by the kernel that cannot be exceeded.
  • Process-Level vs. System-Level Limits: Process-level limits apply to individual processes (e.g., Nginx, Redis, databases), while system-level limits apply to the entire OS, governing the total number of FDs available across all processes.

Default FD limits are often too low for modern high-concurrency use cases—such as web servers handling thousands of concurrent connections, real-time applications, or distributed systems—making optimization a necessity for reliable performance.

Step 1: Check Current FD Limits

Before making any changes, you need to audit your system’s current FD configuration to identify bottlenecks. Use these command-line tools to gather critical information:

  1. Check process-level soft limits: ulimit -n — this returns the current soft limit for the active shell session.
  2. Check system-level global limits: cat /proc/sys/fs/file-max — this shows the total number of FDs the kernel can allocate system-wide.
  3. Check used vs. available FDs: cat /proc/sys/fs/file-nr — the output includes three values: used FDs, free allocated FDs, and the total system limit.
  4. Verify FD exhaustion: If you’re seeing “Too many open files” errors, cross-reference the used FDs from file-nr with the system and process limits to confirm the bottleneck.

Step 2: Temporary FD Optimization (Quick Fix)

For emergency situations or temporary testing, you can adjust the process-level soft limit on the fly. This change takes effect immediately but is not persistent— it will reset after a system reboot or user logout:

  1. Set a temporary soft limit: ulimit -n 65535 — this increases the soft limit to 65535 for the current shell session.
  2. Verify the change: Re-run ulimit -n to confirm the new limit is active.

Note: This method is only suitable for short-term fixes. For production environments, permanent configuration is required to avoid repeated issues.

Step 3: Permanent FD Optimization (Production-Grade)

Permanent optimization requires configuring both user-level and system-level limits, as well as tuning individual services (e.g., Nginx, MySQL) to respect these limits. Follow these steps for a robust, long-term solution:

3.1 User-Level Permanent Configuration

The /etc/security/limits.conf file controls permanent process-level limits for all users or specific users. Edit this file to set consistent soft and hard limits:

  1. Open the configuration file: vim /etc/security/limits.conf
  2. Add the following lines for all users (replace * with a specific username to target individual users):
    * soft nofile 65535
    * hard nofile 65535
    root soft nofile 65535
    root hard nofile 65535
  3. Save and exit the file. The changes will take effect after the user logs out and logs back in.

3.2 System-Level Global Configuration

The /etc/sysctl.conf file manages system-wide kernel parameters, including the total number of FDs available. Adjust this to ensure the system can support the increased process-level limits:

  1. Open the configuration file: vim /etc/sysctl.conf
  2. Add the following line to set the system-wide FD limit (adjust the value based on your workload):
    fs.file-max = 655350
  3. Apply the changes immediately: sysctl -p — this loads the new configuration without a reboot.

3.3 Systemd Service-Specific Optimization

Many modern services (e.g., Nginx, Redis, MySQL) are managed by Systemd. To ensure these services respect your optimized limits, modify their Systemd service files:

  1. Locate the service file (e.g., for Nginx: /etc/systemd/system/nginx.service or /usr/lib/systemd/system/nginx.service).
  2. Add the following line under the [Service] section:
    LimitNOFILE=65535
  3. Reload Systemd and restart the service:
    systemctl daemon-reload
    systemctl restart nginx

Step 4: Verify Optimization Success

After configuring permanent limits, validate that the changes are active and working as expected. Use these steps to confirm:

  1. Verify process-level limits: Log out and log back in, then run ulimit -n — it should return the new soft limit.
  2. Verify system-level limits: Run sysctl fs.file-max — it should return the new system limit.
  3. Verify service-specific limits: For a Systemd-managed service, run systemctl show <service-name> | grep LimitNOFILE — it should display the configured limit.
  4. Monitor FD usage: Use cat /proc/sys/fs/file-nr over time to ensure used FDs do not approach the system or process limits.

Best Practices for FD Optimization

To avoid over-configuration or resource waste, follow these best practices tailored for high-concurrency hosting and colocation environments:

  • Choose reasonable values: A soft/hard limit and system limit works for most mid-to-high concurrency workloads. For extreme use cases (e.g., high-traffic e-commerce, real-time gaming), increase to 100000+.
  • Avoid unlimited limits: Setting FD limits to “unlimited” can lead to uncontrolled resource consumption and system instability. Always set a defined ceiling.
  • Combine with other optimizations: Pair FD limit adjustments with TCP tuning (e.g., socket timeouts, backlog) and kernel optimizations to maximize overall system performance.
  • Test under load: Validate your configuration with load testing tools (e.g., ab, wrk) to ensure the system handles peak concurrency without FD-related errors.

Common Troubleshooting Tips

If your FD optimizations are not working as expected, troubleshoot with these technical steps:

  • Configuration not taking effect: Ensure PAM modules are enabled (check /etc/pam.d/login for session required pam_limits.so), and log out/in to apply user-level changes.
  • Persistent “Too many open files” errors: Check for FD leaks (use lsof -p <pid> to identify processes with excessive open FDs) or misconfigured services.
  • Distro-specific differences: CentOS/RHEL and Ubuntu/Debian may have minor variations in configuration file paths, so adjust accordingly.

Conclusion

Linux file descriptor limits optimization is a foundational step for maintaining high-concurrency, stable Linux systems—whether you’re managing hosting, colocation, or on-premises infrastructure. By understanding the difference between soft/hard and process/system-level limits, configuring permanent settings, and validating your changes, you can eliminate “Too many open files” errors and unlock your system’s full performance potential. Remember to follow best practices, test under load, and combine FD optimization with other kernel and service tuning for a robust, production-ready setup.

Your FREE Trial Starts Here!
Contact our Team for Application of Dedicated Server Service!
Register as a Member to Enjoy Exclusive Benefits Now!
Your FREE Trial Starts here!
Contact our Team for Application of Dedicated Server Service!
Register as a Member to Enjoy Exclusive Benefits Now!
Telegram Skype