macOS Sierra: ulimit maxproc only 2500?

TL;DR

  • The method for increasing max. processes per user described in the tutorial the OP referenced is both dangerous and ineffective. Do not do it that way. If you need more user processes, enable Server Performance Mode as described here.
  • "What is this number, why exactly 1064?" See Why is macOS limited to 1064 or 2088 processes?
  • "Why am I limited in user processes anyway?" Because the system can only run a limited number of processes at once, the system limits users to a lower number of processes so that the system itself remains able to run processes, for example one to display a warning that you have run out of of processes.

Details

The articles the OP linked to are DANGEROUS because they install configurations that allow a single user to crash the computer by filling up the process table, meaning they can create as many processes as the system will allow (well, probably minus 2 or so reserved for root, which was a kind of protection against this in the old days when 2 processes were enough for a system administrator to get in and fix problems). They also install those configurations in a way for which there is no automatic or easy rollback once you forget that you set them or how you set them, and they may interfere with future default increases when you upgrade to a new OS version. More importantly, they do not really achieve what they claim to achieve with regard to increasing the number of processes a user can run.

The default hard limit for kern.maxproc (the maximum total number of processes that can run at one time systemwide) under OS X is 1064. The limit was 566 until OS X Lion, at which point it was increased to 1064 for computers with 3 GiB or more of memory. The limit was increased again in High Sierra for computers with 12 GiB or more memory (exact formula is detailed in the description of serverperfmode here.) and increased again in Catalina (and my guess is it will be increased again in Big Sur). (See Why is macOS limited to 1064 or 2088 processes? for more details about where the specific numbers like 1064 came from.) Although you can change the number while the system is running, it does not take immediate effect; you have to set it during the boot process to take effect and at that point the kernel will not go above 1064 (or whatever limit you are already seeing).

You can set kern.maxprocperuid (the maximum number of processes a single user can have running at one time) to a higher number, even higher than kern.maxproc, but having it too high risks having an out-of-control process crash the entire machine by filling up the process table. That is why the default maxprocperuid is 709 which is 2/3 of 1064: to ensure a single user cannot take up all the processes.

Server Performance Mode

Before High Sierra, the only way to increase kern.maxproc above 1064 is to have at least 16 GiB of memory installed and the to turn on "Server Performance Mode", which reconfigures the kernel to operate like a server rather than an interactive workstation. Starting with High Sierra you can increase kern.maxproc by adding more memory, but still, short of adding memory, the only way to increase it is by turning on "Server Performance Mode". In that mode, kern.maxproc is set to floor(system_memory/8 GiB) * 2500. You also get much higher limits on many other parameters, like max open files and max network connections. You get these higher limits automatically, without having to create or modify files like the linked articles tell you to.

If sysctl kern.maxproc returns kern.maxproc: 1064 (or any multiple of 532 or 1044) then you know you do not have server performance mode turned on. To turn it on, execute this command line in the terminal:

sudo nvram boot-args="serverperfmode=1 $(nvram boot-args 2>/dev/null | cut -f 2-)"

and reboot. That setting will persist and your computer will remain in server mode until you clear NVRAM completely or turn Server Performance Mode off by executing

sudo nvram boot-args="$(nvram boot-args 2>/dev/null | sed -e $'s/boot-args\t//;s/serverperfmode=1//')"

Turning on Server Performance Mode is safer and easier than trying to change individual kernel parameters by editing configuration files, and it has the added advantage of working where those other things will not. And unlike editing configuration files, is also automatically rolled back when you clear NVRAM, which is a standard part of restoring a misconfigured computer to a standard and sane configuration.

You can read more about this Fix “fork: resource temporarily unavailable” on OS X.