Skip to content

Commit 3dbb73f

Browse files
committed
Support to adjust the maximum open files on containerize env
Enable users to modify the maximum number of open file descriptors by setting the THANOS_ULIMIT_NOFILES environment variable as in Kubernetes environment, adjusting this value can be challenging. Signed-off-by: Kien Nguyen Tuan <[email protected]>
1 parent 2a5a856 commit 3dbb73f

File tree

5 files changed

+35
-7
lines changed

5 files changed

+35
-7
lines changed

Dockerfile

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ FROM quay.io/prometheus/busybox@sha256:${BASE_DOCKER_SHA}
44
LABEL maintainer="The Thanos Authors"
55

66
COPY /thanos_tmp_for_docker /bin/thanos
7+
COPY docker-entrypoint.sh /docker-entrypoint.sh
78

89
RUN adduser \
910
-D `#Dont assign a password` \
1011
-H `#Dont create home directory` \
1112
-u 1001 `#User id`\
1213
thanos && \
13-
chown thanos /bin/thanos
14+
chown thanos /bin/thanos && \
15+
chown thanos /docker-entrypoint.sh && \
16+
chmod +x /docker-entrypoint.sh
1417
USER 1001
15-
ENTRYPOINT [ "/bin/thanos" ]
18+
ENTRYPOINT [ "/docker-entrypoint.sh" ]

Dockerfile.multi-arch

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@ ARG ARCH="amd64"
88
ARG OS="linux"
99

1010
COPY .build/${OS}-${ARCH}/thanos /bin/thanos
11+
COPY docker-entrypoint.sh /docker-entrypoint.sh
1112

1213
RUN adduser \
1314
-D `#Dont assign a password` \
1415
-H `#Dont create home directory` \
1516
-u 1001 `#User id`\
1617
thanos && \
17-
chown thanos /bin/thanos
18+
chown thanos /bin/thanos && \
19+
chown thanos /docker-entrypoint.sh && \
20+
chmod +x /docker-entrypoint.sh
1821
USER 1001
19-
ENTRYPOINT [ "/bin/thanos" ]
22+
ENTRYPOINT [ "/docker-entrypoint.sh" ]

Dockerfile.multi-stage

+5-2
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@ FROM quay.io/prometheus/busybox@sha256:${BASE_DOCKER_SHA}
2020
LABEL maintainer="The Thanos Authors"
2121

2222
COPY --from=builder /go/bin/thanos /bin/thanos
23+
COPY docker-entrypoint.sh /docker-entrypoint.sh
2324

2425
RUN adduser \
2526
-D `#Dont assign a password` \
2627
-H `#Dont create home directory` \
2728
-u 1001 `#User id`\
2829
thanos && \
29-
chown thanos /bin/thanos
30+
chown thanos /bin/thanos && \
31+
chown thanos /docker-entrypoint.sh && \
32+
chmod +x /docker-entrypoint.sh
3033
USER 1001
31-
ENTRYPOINT [ "/bin/thanos" ]
34+
ENTRYPOINT [ "/docker-entrypoint.sh" ]

docker-entrypoint.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
# Resources limits: maximum number of open file descriptors
6+
if [ -n "${THANOS_ULIMIT_NOFILES:-}" ]; then
7+
current_limit=$(ulimit -Hn)
8+
if [ "$current_limit" != "unlimited" ]; then
9+
# shellcheck disable=SC2086
10+
if [ $THANOS_ULIMIT_NOFILES -gt $current_limit ]; then
11+
echo "Setting file description limit to $THANOS_ULIMIT_NOFILES"
12+
ulimit -Hn $THANOS_ULIMIT_NOFILES
13+
fi
14+
fi
15+
fi
16+
17+
exec /bin/thanos "$@"

docs/operating/binary-index-header.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ Since the index-header is built downloading specific segments of the original bl
6161

6262
## Impact on number of open file descriptors
6363

64-
The Store Gateway stores each block's index-header on the local disk and loads it via mmap. This means that the Gateway keeps a file descriptor for each loaded block. If your Thanos setup has many blocks in the bucket, the Gateway may hit the `file-max` ulimit (maximum number of open file descriptions by a process); in such case, we recommend increasing the limit on your system.
64+
The Store Gateway stores each block's index-header on the local disk and loads it via mmap. This means that the Gateway keeps a file descriptor for each loaded block. If your Thanos setup has many blocks in the bucket, the Gateway may hit the `file-max` ulimit (maximum number of open file descriptions by a process); in such case, we recommend increasing the limit on your system or running more Store Gateway instances with blocks sharding enabled.
65+
66+
The rule of thumb is that a production system shouldn't have the `file-max` ulimit below `65536`, but higher values are recommended (eg. `1048576`).
6567

6668
## Impact on CPU, memory and disk
6769

0 commit comments

Comments
 (0)