When running several exchanges with many currency pairs, the amount of network connections that are
opened simultaneously by margin can become huge. Each connection internally requires margin to create
a so called "file handle". However, the maximum number of simultaneously held file-handles by a single
process is usually limited by the OS. Depending on the exchange implementation, a single
connection/handle for the whole exchange might be sufficient or, in the other extreme, several
connections for each loaded currency pair are required. In addition, log-files that are written
by margin and client-side databases also require a set of "free" file-handles.
To prevent margin from running into system limitations (that usually lead to a crash),
margin will initially try to raise the limit to a "care-free" large amount:
- On MacOS: 4096 (apparently depending on the hardware, different
hard limits are defined but this value should work on all machines)
- On Linux: 4096 (note that this seems to be a difficult to overcome limit)
- On Windows: This issue doesn't seem to apply, the limit is not adapted at all
If increasing the limit to the desired value was not successful, margin will show a warning dialog
to the user before the login window becomes visible.
More technically, the operating system usually defines two "max-open-file-handles" limits:
- the soft limit describes the default value for each application -- the application
can explicitly increase the soft limit if that is required, but only up to the hard limit
- the hard limit is the absolute maximum of max-open-file-handles per application.
Usually administrator permissions are required to alter this value
As an example, on a current standard MacOS system, the default soft-limit is set to 256, but the
hard-limit is actually set to "unlimited", which means, applications can autonomously set their
soft-limit to any number they desire. However, customizations or other OS versions might define
other limits. On Ubuntu Linux, the default soft limit can be as low as 128 or 256 max open
file-handles, which is why also here margin will automatically try to increase the soft limit at
startup. On Linux increasing the hard limit beyond 4096 seems to be more difficult and thus we set
the limit to this for now.
Before startup, margin will try to raise the soft-limit to at least the desired value and it will
show a warning dialog if this was not successful. Please note that you can increase the soft limit
manually (through your OS settings) beyond the limits required by margin. margin won't decrease
the current limit if it is higher than necessary.
If you get an error message, please try the following steps:
Unfortunately, different version of MacOS seem to have come up with different ways to set up these limits.
Here are some suggestions and howtos:
sudo sysctl -w kern.maxfilesperproc=20000
sudo launchctl limit maxfiles 20000 20000
Perhaps, additional configuration steps are required and very important: some of these require you
to restart the system [...]
sudo sysctl -w fs.file-max=20000