Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[YUNIKORN-2374] Add Performance testing tools #774

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions deployments/kwok-perf-test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./output
194 changes: 194 additions & 0 deletions deployments/kwok-perf-test/affinity.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
#!/bin/bash
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

RANDOM=0
OUTPUT_PATH="./output/affinity.yaml"
NUM_PODS=0
NUM_NODES=0
OPERATORS=("In" "NotIn")
OPERATORS_STATE=0
j=0

show_help() {
cat << EOF
Invalid option: -$OPTARG
Usage: $0 <pod_count> <node_count>
Options:
-o, Specifies the location of the output yaml file (default is ./output/affinity.yaml)
Arguments:
<pod_count> Number of pod to create (required).
<node_count> Number of kwok nodes (required).
EOF
}

# Process command-line options
while getopts ":o:" opt; do
case $opt in
o)
OUTPUT_PATH=$OPTARG
;;
\?)
show_help
exit 1
;;
:)
show_help
exit 1
;;
esac
done

# Shift the processed options out of the command-line arguments
shift $((OPTIND-1))

# Check if pod count and node count are provided
if [ $# -ne 2 ]; then
show_help
exit 1
fi

NUM_PODS=$1
NUM_NODES=$2
Comment on lines +67 to +68
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the minimum number of pods/nodes that make sense? Looking at the code below, we need at least 4 nodes. We need to validate them and show an error if it's necessary.


if [ -f "$OUTPUT_PATH" ]; then
# clear origin content in file
echo "" > "$OUTPUT_PATH"
echo "The original content of the file located at $OUTPUT_PATH has been cleared."
else
echo "The file $OUTPUT_PATH does not exist."
mkdir -p "$(dirname "$OUTPUT_PATH")"
touch "$OUTPUT_PATH"
echo "The create $OUTPUT_PATH."
fi

# create pods assigned with random node affinity
echo "Create $((NUM_PODS/2/2)) pods, each with random node affinity using the required rule."
echo "Create $((NUM_PODS/2/2)) pods, each with random node affinity using the preferred rule."
Comment on lines +82 to +83
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I'd just print a single line:
echo "Create $((NUM_PODS/2/2)) pods, each with random node affinity using required and preferred rule."

for (( ;j<NUM_PODS/2; j+=2))
do
operator=${OPERATORS[$OPERATORS_STATE]}
OPERATORS_STATE=$(( (OPERATORS_STATE + 1) % 2 ))
randHost1=$((RANDOM % NUM_NODES))
randHost2=$((RANDOM % NUM_NODES))
randHost3=$((RANDOM % NUM_NODES))
randHost4=$((RANDOM % NUM_NODES))
Comment on lines +88 to +91
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest reproducible testing. Determine a step from the number of nodes.

  • 4-7 nodes -> randHostN = prev + 1
  • 8-11 nodes -> randHostN = prev + 2
  • 12-15 nodes -> randHostN = prev + 3
    etc

cat <<EOF >> "$OUTPUT_PATH"
apiVersion: v1
kind: Pod
metadata:
name: nginx-$j
labels:
applicationId: nginx-$j
spec:
containers:
- name: sleep300
image: "alpine:latest"
command: ["sleep", "0"]
ports:
- containerPort: 80
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: $operator
values:
- kwok-node-$randHost1
- kwok-node-$randHost2
tolerations:
- key: "kwok.x-k8s.io/node"
operator: "Exists"
effect: "NoSchedule"
---
apiVersion: v1
kind: Pod
metadata:
name: nginx-$((j+1))
labels:
applicationId: nginx-$((j+1))
spec:
containers:
- name: sleep300
image: "alpine:latest"
command: ["sleep", "0"]
ports:
- containerPort: 80
affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 1
preference:
matchExpressions:
- key: kubernetes.io/hostname
operator: $operator
values:
- kwok-node-$randHost3
- kwok-node-$randHost4
tolerations:
- key: "kwok.x-k8s.io/node"
operator: "Exists"
effect: "NoSchedule"
---
EOF
done

# create pods assigned with random pod affinity
echo "Create $((NUM_PODS-j)) pods, each with random node affinity using the preferred rule."
for (( ;j<NUM_PODS; j+=1))
do
operator=${OPERATORS[$OPERATORS_STATE]}
OPERATORS_STATE=$(( (OPERATORS_STATE + 1) % 2 ))
randAppID1=$((RANDOM % NUM_PODS))
randAppID2=$((RANDOM % NUM_PODS))
Comment on lines +159 to +160
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, try to come up with a deterministic code here.

cat <<EOF >> "$OUTPUT_PATH"
apiVersion: v1
kind: Pod
metadata:
name: nginx-$((j))
labels:
applicationId: nginx-$((j))
spec:
containers:
- name: sleep300
image: "alpine:latest"
command: ["sleep", "0"]
ports:
- containerPort: 80
affinity:
podAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: applicationId
operator: $operator
values:
- nginx-$randAppID1
- nginx-$randAppID2
topologyKey: kubernetes.io/role
tolerations:
- key: "kwok.x-k8s.io/node"
operator: "Exists"
effect: "NoSchedule"
---
EOF
done
119 changes: 119 additions & 0 deletions deployments/kwok-perf-test/priority.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#!/bin/bash
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

RANDOM=0
OUTPUT_PATH="./output/priority.yaml"
NUM_PODS=0
NUM_PRIORITY=0

show_help() {
cat << EOF
Invalid option: -$OPTARG
Usage: $0 <pod_count> <priorityClass_count>
Options:
-o, Specifies the location of the output yaml file (default is ./output/priority.yaml)
Arguments:
<pod_count> Number of pod to create (required).
<priorityClass_count> Number of priorityClass to create (required).
EOF
}

# Process command-line options
while getopts ":o:" opt; do
case $opt in
o)
OUTPUT_PATH=$OPTARG
;;
\?)
show_help
exit 1
;;
:)
show_help
exit 1
;;
esac
done

# Shift the processed options out of the command-line arguments
shift $((OPTIND-1))

# Check if pod count and priorityClass count are provided
if [ $# -ne 2 ]; then
show_help
exit 1
fi

NUM_PODS=$1
NUM_PRIORITY=$2
Comment on lines +64 to +65
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verify that the numbers make sense.


if [ -f "$OUTPUT_PATH" ]; then
# clear origin content in file
echo "" > "$OUTPUT_PATH"
echo "The original content of the file located at $OUTPUT_PATH has been cleared."
else
echo "The file $OUTPUT_PATH does not exist."
mkdir -p "$(dirname "$OUTPUT_PATH")"
touch "$OUTPUT_PATH"
echo "The create $OUTPUT_PATH."
fi

# create PriorityClass
echo "Create $((NUM_PRIORITY)) PriorityClass and save then to a YAML file."
for (( i=0;i<NUM_PRIORITY; i++))
do
cat <<EOF >> "$OUTPUT_PATH"
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
name: priority-$i
value: $i
preemptionPolicy: Never
globalDefault: false
---
EOF
done

# create pods assigned with random priorityClass name
echo "Create $((NUM_PODS)) Pods and save them to a YAML file, with each Pod assigned a PriorityClass selected at random."
for (( j=0;j<NUM_PODS; j++))
do
randPriority=$((RANDOM % NUM_PRIORITY))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deterministic priority

cat <<EOF >> "$OUTPUT_PATH"
apiVersion: v1
kind: Pod
metadata:
name: nginx-$j
spec:
containers:
- name: sleep300
image: "alpine:latest"
command: ["sleep", "0"]
ports:
- containerPort: 80
tolerations:
- key: "kwok.x-k8s.io/node"
operator: "Exists"
effect: "NoSchedule"
priorityClassName: priority-$randPriority
---
EOF
done

Loading
Loading