Skip to content

Commit

Permalink
chore: improve load-test
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianKramm committed Oct 20, 2023
1 parent c593a33 commit 3686e43
Show file tree
Hide file tree
Showing 10 changed files with 249 additions and 126 deletions.
17 changes: 2 additions & 15 deletions hack/load-testing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,8 @@

How to use:

1. Create a new vcluster
1. Create a new vcluster via the deployment options
2. Start testing via:
```
go run hack/load-testing/main.go -amount 1000 secrets
go run hack/load-testing/main.go throughput
```

### Connect to SQLite

Install SQLite:
```
kubectl exec -it -n NAMESPACE NAME-0 -c syncer -- sh -c 'apk update && apk add sqlite'
```

Access Database:
```
kubectl exec -it -n NAMESPACE NAME-0 -c syncer -- sh -c 'sqlite3 /data/server/db/state.db'
```

54 changes: 54 additions & 0 deletions hack/load-testing/deploy/k3s-mysql/mysql.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
apiVersion: v1
kind: Service
metadata:
name: mysql
spec:
ports:
- port: 3306
selector:
app: mysql
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql
spec:
selector:
matchLabels:
app: mysql
strategy:
type: Recreate
template:
metadata:
labels:
app: mysql
spec:
containers:
- image: mysql:8
name: mysql
args:
- "--default-authentication-plugin=mysql_native_password"
env:
# Use secret in real usage
- name: MYSQL_ROOT_PASSWORD
value: my-password
- name: MYSQL_DATABASE
value: k3s
volumeMounts:
- name: mysql-persistent-storage
mountPath: /var/lib/mysql
volumes:
- name: mysql-persistent-storage
persistentVolumeClaim:
claimName: mysql-pv-claim
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pv-claim
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
20 changes: 20 additions & 0 deletions hack/load-testing/deploy/k3s-mysql/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
syncer:
resources:
limits:
cpu: "0"
memory: "0"
requests:
cpu: "0"
memory: "0"

vcluster:
env:
- name: K3S_DATASTORE_ENDPOINT
value: mysql://root:my-password@tcp(mysql:3306)/k3s
resources:
limits:
cpu: "0"
memory: "0"
requests:
cpu: "0"
memory: "0"
17 changes: 17 additions & 0 deletions hack/load-testing/deploy/k3s/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
syncer:
resources:
limits:
cpu: "0"
memory: "0"
requests:
cpu: "0"
memory: "0"

vcluster:
resources:
limits:
cpu: "0"
memory: "0"
requests:
cpu: "0"
memory: "0"
8 changes: 8 additions & 0 deletions hack/load-testing/deploy/k8s/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
syncer:
resources:
limits:
cpu: "0"
memory: "0"
requests:
cpu: "0"
memory: "0"
20 changes: 6 additions & 14 deletions hack/load-testing/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ import (
"fmt"
"os"

"github.com/loft-sh/vcluster/hack/load-testing/tests/events"
"github.com/loft-sh/vcluster/hack/load-testing/tests/secrets"
"github.com/loft-sh/vcluster/hack/load-testing/tests/throughput"
"k8s.io/klog/v2"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
)

func printUsage() {
_, _ = fmt.Fprintln(os.Stderr, "usage: load-testing <TEST> [-amount INT] [-namespace STRING]")
_, _ = fmt.Fprintln(os.Stderr, "usage: load-testing <TEST> [-namespace STRING]")
os.Exit(1)
}

Expand All @@ -25,8 +24,6 @@ func printError(err error) {

func main() {
ctx := context.Background()
amount := flag.Int64("amount", 100, "amount to create")

namespace := ""
flag.StringVar(&namespace, "namespace", "load-testing", "namespace to use")
flag.Parse()
Expand All @@ -39,8 +36,8 @@ func main() {

// We increase the limits here so that we don't get any problems
restConfig := ctrl.GetConfigOrDie()
restConfig.QPS = 1000
restConfig.Burst = 2000
restConfig.QPS = 9999999
restConfig.Burst = 9999999
restConfig.Timeout = 0

// build client
Expand All @@ -51,13 +48,8 @@ func main() {
}

switch test {
case "secrets":
err = secrets.TestSecrets(ctx, kubeClient, *amount, namespace)
if err != nil {
printError(err)
}
case "events":
err = events.TestEvents(ctx, kubeClient, restConfig, *amount, namespace)
case "throughput":
err = throughput.TestThroughput(ctx, kubeClient, namespace)
if err != nil {
printError(err)
}
Expand Down
30 changes: 30 additions & 0 deletions hack/load-testing/stopwatch/stopwatch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package stopwatch

import (
"time"

"github.com/go-logr/logr"
)

func New(logger logr.Logger) *StopWatch {
return &StopWatch{
logger: logger,
lastTime: time.Now(),
}
}

type StopWatch struct {
logger logr.Logger

lastTime time.Time
}

func (s *StopWatch) Reset() {
s.lastTime = time.Now()
}

func (s *StopWatch) Stop(msg string, keysAndValues ...interface{}) {
elapsed := time.Since(s.lastTime)
s.logger.Info(msg, append([]interface{}{"elapsed", elapsed}, keysAndValues...)...)
s.lastTime = time.Now()
}
51 changes: 0 additions & 51 deletions hack/load-testing/tests/events/events.go

This file was deleted.

46 changes: 0 additions & 46 deletions hack/load-testing/tests/secrets/secrets.go

This file was deleted.

Loading

0 comments on commit 3686e43

Please sign in to comment.