Sitemap
The Ordinary Programmer

The Ordinary Programmer is for coders who embrace simplicity and practicality. We share real-world tips, project stories, and tech insights for developers at every level. You don’t need to be a superstar — just a programmer who loves to learn and build helpful software.

Mac: Set Maximum Connection and Port Parameters

2 min readSep 4, 2024

--

Press enter or click to view image in full size
Photo by Douglas Lopes on Unsplash

Maximum Connections Limit

The maximum number of connections limit refers to the limit of the maximum number of files (file descriptors) that the system can open, which is divided into global and per-process types:

Global

## The system's default maximum number of connections limit is 2147483647
$ sysctl kern.maxfiles
kern.maxfiles: 2147483647
## Set the system's maximum number of connections from 49152 to 1048600
$ sudo sysctl -w kern.maxfiles=1048600

Per-Process

# The default maximum number of connections per process is 61440
$ sysctl kern.maxfilesperproc
kern.maxfilesperproc: 61440
# Set the per-process connection limit from 24576 to 1048576, the maximum number of connections per process must be less than or equal to the global connection limit
$ sudo sysctl -w kern.maxfilesperproc=1048576

To make permanent changes, add the following content to /etc/sysctl.conf

kern.maxfiles=20480 
kern.maxfilesperproc=18000

This file may need to be created manually.

Ulimit Command

$ ulimit -n 4864 #### Display the maximum number of files that the current shell can open, the default value is: 4864, this value is always…

--

--

The Ordinary Programmer
The Ordinary Programmer

Published in The Ordinary Programmer

The Ordinary Programmer is for coders who embrace simplicity and practicality. We share real-world tips, project stories, and tech insights for developers at every level. You don’t need to be a superstar — just a programmer who loves to learn and build helpful software.

huizhou92
huizhou92

Written by huizhou92

Golang backend engineer. Specializes in cloud, data, and security. Lifelong learner. Efficiency enthusiast.