Number of open files

Linux platforms impose an upper limit on the number of concurrent files a user may have open. This number is reported for the current user and session with the ulimit -n command:

user@localhost:~$ ulimit -n

Neo4j will also report the current setting for number of file descriptors in the debug.log with a message like the following:

2019-01-02 13:39:27.003+0000 INFO [o.n.i.d.DiagnosticsManager] Max number of file descriptors: 10000

The usual default is 1024 and is often not enough. We recommend setting this to 40000 to ensure Neo4j works correctly. We previously learned how to monitor linux open file usage, now let’s see how to change this.

It is possible to set the limit with the ulimit -n command, but only for the root user, and it only affects the current session, so it’s not permanent. Also, it will not affect your processes that are already running.

The actual way to raise your file limits consists of editing three files:

  • /etc/security/limits.conf needs to have these lines in it:
neo4j  soft  nofile  40000
neo4j  hard  nofile  40000
  • /etc/pam.d/common-session needs to have this line in it:
session required
  • /etc/pam.d/common-session-noninteractive also needs to have this line in it:
session required

Keep in mind that limits can be easily modified by anything responsible for execution of your processes. If running ulimit -n (with the correct user) is giving you the number you just set, but cat /proc/{process_id}/limits is still printing the low number, you almost certainly have a process manager, an init script, or something similar overriding your limits. One last thing worth noting is that processes inherit the limits of the parent process.

In some cases, you also need to edit /etc/systemd/system.conf and /etc/systemd/user.conf in order for your limit configuration to persist.

You can also take a look at our official documentation on Setting the number of open files

Lastly, if you need to set the maximum open files on a Debian instalation, take a look at the article How do I set max open files for Debian installs