Skip to content

Commit c3e83a5

Browse files
p3rf Teamcopybara-github
authored andcommitted
Add RemoteHostCopy support and cluster scripts for SwapDaemonSet.
PiperOrigin-RevId: 963246284
1 parent 0607372 commit c3e83a5

20 files changed

Lines changed: 3627 additions & 110 deletions
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
swapoff -a 2>/dev/null || true
3+
swapoff /dev/mapper/swap_encrypted 2>/dev/null || true
4+
dmsetup remove --noudevrules --noudevsync swap_encrypted 2>/dev/null || true
5+
for backing in /var/pkb_swap_backing /run/pkb_swap_backing /mnt/stateful_partition/pkb_swap_backing; do
6+
losetup -j "$backing" 2>/dev/null | awk -F: '{print $1}' | while read dev; do
7+
losetup -d "$dev" 2>/dev/null || true
8+
done
9+
rm -f "$backing"
10+
done
11+
pkill -9 'stress-ng|fio' 2>/dev/null || true
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
set -e
3+
echo 1 > /sys/module/zswap/parameters/enabled
4+
echo lz4 > /sys/module/zswap/parameters/compressor
5+
echo 20 > /sys/module/zswap/parameters/max_pool_percent
6+
echo z3fold > /sys/module/zswap/parameters/zpool
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
ACTIVE=$(awk 'NR==2{print $1}' /proc/swaps 2>/dev/null)
3+
if [ -n "$ACTIVE" ]; then
4+
echo "$ACTIVE"
5+
elif test -e /dev/mapper/swap_encrypted; then
6+
echo /dev/mapper/swap_encrypted
7+
fi
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
set -e
3+
SIZE_GB=$1
4+
SWAPFILE_PATH=$2
5+
fallocate -l ${SIZE_GB}G ${SWAPFILE_PATH}
6+
chmod 600 ${SWAPFILE_PATH}
7+
LOOP=$(losetup -f)
8+
losetup "$LOOP" ${SWAPFILE_PATH}
9+
mkswap "$LOOP"
10+
swapon "$LOOP"
11+
echo "swap loop device: $LOOP"

perfkitbenchmarker/data/cluster/swap_encryption_daemonset.yaml.j2

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@ data:
1313
# Installs measurement tools, verifies the swap device, then writes /tmp/pkb_ready.
1414
set -euo pipefail
1515

16-
echo "[pkb] Installing measurement tools..."
17-
# Only tools needed for Phase 1 (raw-device fio) and Phase 2 (CPU/I/O overhead).
18-
# Workload benchmarks (redis, opensearch, kernel-build) run in separate pods.
16+
echo "[pkb] Installing benchmark measurement tools..."
17+
# Phase 1 tools: fio (raw-device I/O), cryptsetup/mdadm (dm-crypt inspection),
18+
# sysstat (vmstat/pidstat), nvme-cli (NVMe telemetry).
19+
# Phase 2 tools: stress-ng (CPU/I/O overhead), cgroup-tools (cgroup v1 guard),
20+
# util-linux (taskset/ionice).
21+
# Phase 3b tools: gcc/make/bc/flex/bison/libelf-dev/libssl-dev (kernel build).
22+
# Workload benchmarks (redis, opensearch) run in separate PKB benchmark pods.
1923
PKB_APT_OK=0
2024
for _attempt in 1 2 3; do
2125
DEBIAN_FRONTEND=noninteractive apt-get update -qq 2>&1 || true
@@ -25,15 +29,30 @@ data:
2529
mdadm \
2630
sysstat \
2731
nvme-cli \
32+
stress-ng \
33+
cgroup-tools \
34+
util-linux \
35+
gcc \
36+
make \
37+
bc \
38+
flex \
39+
bison \
40+
libelf-dev \
41+
libssl-dev \
2842
2>&1 && PKB_APT_OK=1 && break
2943
echo "[pkb] apt-get attempt $_attempt failed, retrying in 15s..." >&2
3044
sleep 15
3145
done
32-
if [ "$PKB_APT_OK" != "1" ] || ! command -v fio >/dev/null 2>&1; then
33-
echo "[pkb] FATAL: fio not installed after 3 attempts" >&2
46+
if [ "$PKB_APT_OK" != "1" ] || \
47+
! command -v fio >/dev/null 2>&1 || \
48+
! command -v stress-ng >/dev/null 2>&1 || \
49+
! command -v make >/dev/null 2>&1; then
50+
echo "[pkb] FATAL: critical tools (fio, stress-ng, make) not installed after 3 attempts" >&2
3451
exit 1
3552
fi
36-
echo "[pkb] fio installed: $(fio --version 2>&1 | head -1)"
53+
echo "[pkb] fio: $(fio --version 2>&1 | head -1)"
54+
echo "[pkb] stress-ng: $(stress-ng --version 2>&1 | head -1)"
55+
echo "[pkb] gcc: $(gcc --version 2>&1 | head -1)"
3756

3857
echo "[pkb] Verifying swap device is active..."
3958
PKB_SWAP_FOUND=0
@@ -53,7 +72,7 @@ data:
5372
exit 1
5473
fi
5574

56-
echo "[pkb] Measurement tools ready. Writing ready sentinel."
75+
echo "[pkb] Benchmark tools ready. Writing ready sentinel."
5776
touch /tmp/pkb_ready
5877
exec sleep infinity
5978
---
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# opensearch-benchmark Kubernetes Job
2+
# Rendered by kubernetes_opensearch_esrally_benchmark.py Run().
3+
#
4+
# Template variables:
5+
# k8s_namespace - Kubernetes namespace (default: 'default')
6+
# race_id - Unique test-execution identifier string
7+
# target_hosts - OpenSearch Service host:port
8+
# esrally_track - opensearch-benchmark workload name, e.g. geonames
9+
# esrally_challenge - test-procedure name, e.g. append-no-conflicts
10+
# esrally_version - opensearch-benchmark pip package version, e.g. 1.7.0
11+
#
12+
# The Job installs opensearch-benchmark at runtime, runs the test in
13+
# benchmark-only pipeline against the OpenSearch headless Service, then
14+
# prints test_execution.json between PKB sentinel markers so Run() can
15+
# parse the results.
16+
---
17+
apiVersion: batch/v1
18+
kind: Job
19+
metadata:
20+
name: esrally-pkb
21+
namespace: {{ k8s_namespace | default('default') }}
22+
labels:
23+
pkb: "true"
24+
spec:
25+
backoffLimit: 0
26+
template:
27+
metadata:
28+
labels:
29+
pkb: "true"
30+
spec:
31+
nodeSelector:
32+
pkb_nodepool: clients
33+
restartPolicy: Never
34+
containers:
35+
- name: esrally
36+
image: python:3.11-slim
37+
resources:
38+
requests:
39+
memory: "4Gi"
40+
cpu: "2"
41+
limits:
42+
memory: "8Gi"
43+
cpu: "4"
44+
env:
45+
- name: BENCHMARK_HOME
46+
value: /var/benchmark
47+
command:
48+
- bash
49+
- -c
50+
- |
51+
set -euo pipefail
52+
export DEBIAN_FRONTEND=noninteractive
53+
echo "[pkb] Installing system dependencies (git)..."
54+
apt-get update -qq && apt-get install -y --no-install-recommends git > /dev/null
55+
echo "[pkb] Installing opensearch-benchmark {{ esrally_version }}..."
56+
pip install opensearch-benchmark=={{ esrally_version }} --quiet
57+
58+
echo "[pkb] Running opensearch-benchmark (workload={{ esrally_track }}, test-procedure={{ esrally_challenge }})..."
59+
opensearch-benchmark execute-test \
60+
--pipeline=benchmark-only \
61+
--target-host="{{ target_hosts }}" \
62+
--workload="{{ esrally_track }}" \
63+
--test-procedure="{{ esrally_challenge }}" \
64+
--workload-params="number_of_replicas:0" \
65+
--test-execution-id="{{ race_id }}"
66+
67+
echo "[pkb] Test complete. Locating test_execution.json..."
68+
# Use -path in find (not grep) to avoid non-zero exit with pipefail.
69+
TEST_JSON=$(find /root /var/benchmark \
70+
-path "*{{ race_id }}*" -name "test_execution.json" 2>/dev/null | head -1)
71+
if [ -z "$TEST_JSON" ]; then
72+
echo "[pkb-error] test_execution.json not found. Listing all benchmark files:"
73+
find /root /var/benchmark -maxdepth 8 -type f 2>/dev/null | sort | head -50
74+
exit 1
75+
fi
76+
echo "[pkb] Found: $TEST_JSON"
77+
echo "=== PKB_RACE_JSON_BEGIN ==="
78+
cat "$TEST_JSON"
79+
echo ""
80+
echo "=== PKB_RACE_JSON_END ==="
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# OpenSearch single-node StatefulSet + headless Service (clusterIP: None)
2+
# Rendered by kubernetes_opensearch_esrally_benchmark.py Prepare().
3+
#
4+
# Template variables:
5+
# k8s_namespace - Kubernetes namespace (default: 'default')
6+
# opensearch_version - OpenSearch image tag, e.g. 2.13.0
7+
# opensearch_port - HTTP port, e.g. 9200
8+
#
9+
# Nodes in the 'servers' nodepool are selected via the pkb_nodepool label
10+
# which PKB sets automatically during nodepool creation.
11+
# An initContainer sets vm.max_map_count=262144 which OpenSearch requires.
12+
---
13+
apiVersion: v1
14+
kind: Service
15+
metadata:
16+
name: opensearch
17+
namespace: {{ k8s_namespace | default('default') }}
18+
labels:
19+
app: opensearch
20+
pkb: "true"
21+
spec:
22+
selector:
23+
app: opensearch
24+
ports:
25+
- name: http
26+
port: {{ opensearch_port }}
27+
targetPort: {{ opensearch_port }}
28+
clusterIP: None
29+
---
30+
apiVersion: apps/v1
31+
kind: StatefulSet
32+
metadata:
33+
name: opensearch
34+
namespace: {{ k8s_namespace | default('default') }}
35+
labels:
36+
app: opensearch
37+
pkb: "true"
38+
spec:
39+
# No volumeClaimTemplates: OpenSearch data lives on ephemeral pod
40+
# storage, giving each PKB run a clean index (intentional).
41+
serviceName: opensearch
42+
replicas: 1
43+
selector:
44+
matchLabels:
45+
app: opensearch
46+
template:
47+
metadata:
48+
labels:
49+
app: opensearch
50+
pkb: "true"
51+
spec:
52+
nodeSelector:
53+
pkb_nodepool: servers
54+
tolerations:
55+
- operator: Exists
56+
initContainers:
57+
- name: sysctl
58+
image: busybox:1.36
59+
command:
60+
- sysctl
61+
- -w
62+
- vm.max_map_count=262144
63+
securityContext:
64+
privileged: true
65+
containers:
66+
- name: opensearch
67+
image: opensearchproject/opensearch:{{ opensearch_version }}
68+
ports:
69+
- name: http
70+
containerPort: {{ opensearch_port }}
71+
env:
72+
- name: discovery.type
73+
value: single-node
74+
- name: DISABLE_SECURITY_PLUGIN
75+
value: "true"
76+
- name: OPENSEARCH_JAVA_OPTS
77+
value: "-Xms4g -Xmx4g"
78+
- name: bootstrap.memory_lock
79+
value: "false"
80+
resources:
81+
requests:
82+
memory: "8Gi"
83+
cpu: "2"
84+
limits:
85+
memory: "16Gi"
86+
cpu: "4"
87+
readinessProbe:
88+
httpGet:
89+
path: /_cluster/health
90+
port: {{ opensearch_port }}
91+
initialDelaySeconds: 30
92+
periodSeconds: 10
93+
timeoutSeconds: 5
94+
failureThreshold: 12

perfkitbenchmarker/linux_benchmarks/kubernetes/swap_encryption/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)