Often times you will need to increase the maximum number of file descriptors in order to achieve proper functionality of your application. Perhaps you have a database or have run into the “Too many open files” error. In this tutorial, we will go over increasing this value and other ulimits. But first, what is a Linux ulimit?
A ulimit or user limit in Linux is a restriction placed on a user’s access to certain resources. You can use the command ulimit -a
to view them, this will give you a list of the ulimit values you can set, as well as their value. It is important to note that there are two types of limits, soft and hard.
A hard limit is the maximum allowed to the user. It is set by the root user and acts as the hard ceiling for that value. The user will be unable to have a limit higher than this unless it is changed by the root user. There are a few ways to update this value, but the most common way is by updating the /etc/security/limits.conf file. In most situations, it is best to not update this value.
A soft limit is the current maximum for the user. The user is able to change this at any time, either through setrlimit(2) or the ulimit command. Often times, you will only need to set this value, as very few situations call for resources above the hard limit.
The best method for permanently updating soft limits and hard limits is via the /etc/security/limits.conf file. In this file, you can include the new soft limit defaults for a user, or update the hard limits. The format in which you insert your updates into this file is simple, it is just <domain> <type> <item> <value>
. So, if you wanted to update the default file limit for the user apache, it would look like this.
apache soft nofile 5000
Now, all you would have to do is reboot the system, and the user apache’s file descriptor limit would default to 5000.
The easiest way to temporarily update a soft limit is with the ulimit command. If you wanted to set your file descriptor limit to 5000 for the duration of your shell session, you can use this command.
ulimit -S -n 5000
The -S flag signals that you are temporarily updating the soft limit value, and the -n flag states you wish to change the value for file-descriptors. You can also update hard limits using this method, just swap out the -S with -H. However, you can only set a lower value.
Mockery is an awesome tool that offers the ability to generate mocks from Go interfaces.…
Testify is a testing library that makes writing tests for your Go code easy. It…
Certmagic is a Golang library which allows to user to easily and automatically setup HTTPS…
The Boost C++ libraries are a set of free peer-reviewed C++ libraries. They are intended…
Served is a C++ library for easy creation of highly performant web servers. It presents…
This website uses cookies.