This page looks best with JavaScript enabled

Using Fluid and S3FS to Access S3 Storage and Performance Testing

 ·  ☕ 3 min read

This post uses Fluid 1.0. In later versions the configuration file paths changed, so adjust according to your actual situation.

1. Building the Image

1.1 fluid_config_init.py

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python

import json
import os

rawStr = ""
with open("/etc/fluid/config.json", "r") as f:
    rawStr = f.readlines()

rawStr = rawStr[0]

script = """
#!/bin/sh
set -ex
MNT_TO=$targetPath

trap "umount ${MNT_TO}" SIGTERM
mkdir -p ${MNT_TO} || true
s3fs $bucket:$bucketPath $MNT_TO -o url=$url -o allow_other -f -d -o f2
echo "mounted and exit code: $?"
sleep inf
"""

obj = json.loads(rawStr)

with open("/root/.passwd-s3fs", "w") as f:
    f.write("%s:%s\n" % (obj["mounts"][0]["options"]["s3-access-key"], obj["mounts"][0]["options"]["s3-access-secret"]))

# set /root/.passwd-s3fs to be read only by owner
os.chmod("/root/.passwd-s3fs", 0o600)

bucketPath = obj["mounts"][0]["mountPoint"].lstrip("s3://").rstrip("/")
bucket = bucketPath.split("/")[0]
bucketPath = bucketPath[len(bucket):]

with open("/mount-s3.sh", "w") as f:
    f.write('targetPath="%s"\n' % obj["targetPath"])
    f.write('bucket="%s"\n' % bucket)
    f.write('bucketPath="%s"\n' % bucketPath)
    f.write('url="%s"\n' % obj["mounts"][0]["options"]["url"])
    f.write(script)

1.2 entrypoint.sh

1
2
3
4
5
6
#!/usr/bin/env bash
set +x

python /fluid_config_init.py
chmod u+x /mount-s3.sh
bash /mount-s3.sh

1.3 Dockerfile

1
2
3
4
5
6
FROM shaowenchen/runtime-ubuntu:20.04
RUN apt-get update && apt-get install -y python s3fs
COPY ./fluid_config_init.py /
COPY ./entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/entrypoint.sh
ENTRYPOINT []

1.4 Building the Image

1
2
docker build . --network=host -f Dockerfile -t shaowenchen/demo:fluid-s3fs
docker push shaowenchen/demo:fluid-s3fs

1. Mounting S3 Storage

  • Set the environment variables
1
2
3
4
export ENDPOINT=obs.ap-southeast-3.myhuaweicloud.com
export BUCKET=
export AK=
export SK=
  • Create the Dataset
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
kubectl apply -f - <<EOF
apiVersion: data.fluid.io/v1alpha1
kind: Dataset
metadata:
  name: mys3fs
spec:
  mounts:
    - mountPoint: s3://${BUCKET}/test1
      options:
        s3-access-key: ${AK}
        s3-access-secret: ${SK}
        url: https://${ENDPOINT}
EOF
  • Create the ThinRuntimeProfile
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
kubectl apply -f - <<EOF
apiVersion: data.fluid.io/v1alpha1
kind: ThinRuntimeProfile
metadata:
  name: s3fs-profile
spec:
  fileSystemType: s3fs
  fuse:
    image: shaowenchen/demo:fluid-s3fs
    imageTag: latest
    imagePullPolicy: Always
    command:
      - "/usr/local/bin/entrypoint.sh"
EOF
  • Create the ThinRuntime
1
2
3
4
5
6
7
8
kubectl apply -f - <<EOF
apiVersion: data.fluid.io/v1alpha1
kind: ThinRuntime
metadata:
  name: mys3fs-37
spec:
  profileName: s3fs-profile
EOF
  • Create the Pod workload
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
kubectl apply -f - <<EOF
apiVersion: v1
kind: Pod
metadata:
  name: mys3fs
spec:
  containers:
    - name: mys3fs
      image: shaowenchen/demo:ubuntu
      volumeMounts:
        - mountPath: /data
          name: mys3fs
  volumes:
    - name: mys3fs
      persistentVolumeClaim:
        claimName: mys3fs
EOF

2. Performance Testing

Enter the Pod

1
kubectl exec -it mys3fs -- bash

Run

1
curl -sSL https://d.juicefs.com/install | sh -

Install the JuiceFS client

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
juicefs bench --block-size 4 --big-file-size 1024  /data

Benchmark finished!
BlockSize: 4.0 MiB, BigFileSize: 1.0 GiB, SmallFileSize: 128 KiB, SmallFileCount: 100, NumThreads: 1
+------------------+-----------------+----------------+
|       ITEM       |      VALUE      |      COST      |
+------------------+-----------------+----------------+
|   Write big file |    194.80 MiB/s |    5.26 s/file |
|    Read big file |    100.50 MiB/s |   10.19 s/file |
| Write small file |     3.6 files/s | 277.70 ms/file |
|  Read small file |    51.1 files/s |  19.59 ms/file |
|        Stat file | 26301.5 files/s |   0.04 ms/file |
+------------------+-----------------+----------------+

3. Cleaning Up Resources

1
2
3
kubectl delete pod mys3fs
kubectl delete thinruntime mys3fs
kubectl delete dataset mys3fs

微信公众号
WRITTEN BY
微信公众号