Skip to content

Commit 3528e67

Browse files
committed
document setting nofile limit on different systems
1 parent 8a9483b commit 3528e67

File tree

3 files changed

+73
-1
lines changed

3 files changed

+73
-1
lines changed

solutions/observability/apm/apm-server/binary.md

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ curl -L -O https://artifacts.elastic.co/downloads/apm-server/apm-server-{{versio
6161
tar xzvf apm-server-{{version.stack}}-linux-x86_64.tar.gz
6262
```
6363

64+
See [modifying the `nofile` ulimit](#modifying-nofile-ulimit).
65+
6466
$$$apm-mac$$$
6567
**Mac:**
6668

@@ -926,4 +928,56 @@ It’s possible to embed your APM Server configuration in a custom image. Here i
926928
```dockerfile
927929
FROM docker.elastic.co/apm/apm-server:9.0.0
928930
COPY --chmod=0644 --chown=1000:1000 apm-server.yml /usr/share/apm-server/apm-server.yml
929-
```
931+
```
932+
933+
#### Modifying `nofile` ulimit [ulimit-on-docker]
934+
935+
Limits can be set from the command line using `--ulimit=soft:hard`, see [Set ulimits in container (--ulimit)](https://docs.docker.com/reference/cli/docker/container/run/#ulimit).
936+
937+
```sh
938+
docker run -d \
939+
-p 8200:8200 \
940+
--name=apm-server \
941+
--user=apm-server \
942+
--volume="$(pwd)/apm-server.docker.yml:/usr/share/apm-server/apm-server.yml:ro" \
943+
docker.elastic.co/apm/apm-server:9.0.0 \
944+
--strict.perms=false -e \
945+
--ulimit=524287:524287 \
946+
-E output.elasticsearch.hosts=["elasticsearch:9200"] <1> <2>
947+
```
948+
949+
1. Substitute your {{es}} hosts and ports.
950+
2. If you are using {{ech}}, replace the `-E output.elasticsearch.hosts` line with the Cloud ID and elastic password using the syntax shown earlier.
951+
952+
953+
## Modify the `nofile` ulimit [modify-nofile-ulimit]
954+
955+
When run as a standalone binary APM Server will inherit the `nofile` limit from the user running the process. On most system this is configured to `1024`. This limit is too low for higher throughput scenarios or when using Tail Based Sampling.
956+
957+
To chose the new limit, consider these guidelines:
958+
- there is no system performance impact of using a limit of ``;
959+
- a limit of `1024` would suffice for low throughput use cases;
960+
- the major contributor to open files will be the number of incoming connections;
961+
- Tail Based Sampling is file based, when enabling it the number of open files will be higher in proportion to the throughput and sampling policies.
962+
963+
To configure the limit for your user, you need to know the username you will run APM Server process with.
964+
965+
```sh
966+
whoami
967+
```
968+
969+
Edit `/etc/security/limits.conf` with root privileges:
970+
971+
```sh
972+
sudo nano /etc/security/limits.conf
973+
```
974+
975+
Add the following lines to set soft and hard limits for your user:
976+
977+
```text
978+
apm-server soft nofile 524287 <1>
979+
apm-server hard nofile 524287 <1>
980+
```
981+
982+
1. Replace `apm-server` with the username you will run APM Server process with.
983+

solutions/observability/apm/apm-server/systemd.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ systemctl restart apm-server
8888
It is recommended that you use a configuration management tool to include drop-in unit files. If you need to add a drop-in manually, use `systemctl edit apm-server.service`.
8989
::::
9090

91+
#### Configuring the NOFILE limit [configuring-nofile-limit]
92+
93+
::::{note}
94+
There should be no need to manually configure this limit when running APM Server.
95+
::::
96+
97+
In systemd the `LimitNOFILE` defaults are set to `1024` (soft) and `524288` (hard) and most Linux systems with systemd will not change these values or reduce them drastically. Golang since 1.19 (see [golang/go#46279](https://github.com/golang/go/issues/46279)) automatically bump the process limit up to the available hard limit. This means that by default APM Server runs with the limit set to the hard limit value by the Operating System is being run on, generally `524287` on a recent system. There should be no reason to change this limit, as back-pressure from too many open files will happen from memory usage.
98+
99+
For guidelines on the value to set this value to see [Modifying the `nofile` ulimit](/solutions/observability/apm/apm-server/binary.md#modify-nofile-ulimit).
100+
91101
#### Configuration file ownership [apm-config-file-ownership]
92102

93103
On systems with POSIX file permissions, the APM Server configuration file is subject to ownership and file permission checks. These checks prevent unauthorized users from providing or modifying configurations that are run by APM Server.

solutions/observability/apm/apm-server/tail-based-sampling.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ Most options on this page are supported by all APM Server deployment methods whe
2020
Enhanced privileges are required to use tail-based sampling. For more information, refer to [Create a tail-based sampling role](/solutions/observability/apm/create-assign-feature-roles-to-apm-server-users.md#apm-privileges-tail-based-sampling).
2121
::::
2222

23+
::::{note}
24+
If you are manually configuring systemd `LimitNOFILE` or `LimitNOFILESoft` when using Tail Based Sampling and it affects the APM Server process, this may result in a `too many open files` error. Please see [configuring the NOFILE limit](/solutions/observability/apm/systemd.md#configuring-nofile-limit).
25+
::::
26+
27+
::::{note}
28+
If you are running the binary standalone (not using the provided dev or rpm packages or the docker images) you need to adjust the `nofile` limit based on your throughput requirements. See [modifying the `nofile` ulimit](/solutions/observability/apm/apm-server/binary.md#modify-nofile-ulimit).
29+
::::
30+
2331
Tail-based sampling configuration options.
2432

2533
:::::::{tab-set}

0 commit comments

Comments
 (0)