-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added bench tests for lvm_logical_volume_watcher.go and some fixes
Signed-off-by: Viktor Kramarenko <[email protected]>
- Loading branch information
1 parent
ca224e0
commit 4821779
Showing
3 changed files
with
297 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
276 changes: 276 additions & 0 deletions
276
images/agent/pkg/controller/lvm_logical_volume_watcher_bench_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,276 @@ | ||
package controller | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
v1 "k8s.io/api/core/v1" | ||
sv1 "k8s.io/api/storage/v1" | ||
extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" | ||
"k8s.io/apimachinery/pkg/api/resource" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
apiruntime "k8s.io/apimachinery/pkg/runtime" | ||
clientgoscheme "k8s.io/client-go/kubernetes/scheme" | ||
"os" | ||
"sds-node-configurator/api/v1alpha1" | ||
"sds-node-configurator/internal" | ||
"sds-node-configurator/pkg/kubutils" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"testing" | ||
) | ||
|
||
var ( | ||
lvgName = "hdd-lvg-on-node-0" | ||
poolName = "hhd-thin" | ||
lvCount = 600 | ||
size, err = resource.ParseQuantity("1Gi") | ||
|
||
resizeOn = false | ||
|
||
ctx = context.Background() | ||
cl client.Client | ||
|
||
resourcesSchemeFuncs = []func(*apiruntime.Scheme) error{ | ||
v1alpha1.AddToScheme, | ||
clientgoscheme.AddToScheme, | ||
extv1.AddToScheme, | ||
v1.AddToScheme, | ||
sv1.AddToScheme, | ||
} | ||
) | ||
|
||
func BenchmarkRunThickLLVCreationSingleThread(b *testing.B) { | ||
b.Logf("starts the test") | ||
llvNames := make(map[string]bool, lvCount) | ||
|
||
b.StartTimer() | ||
for i := 0; i < lvCount; i++ { | ||
llv := configureTestThickLLV(fmt.Sprintf("test-llv-%d", i), lvgName) | ||
err := cl.Create(ctx, llv) | ||
if err != nil { | ||
b.Logf("unable to create test LLV %s, err: %s", llv.Name, err.Error()) | ||
} | ||
llvNames[llv.Name] = false | ||
} | ||
lvCreatedTime := b.Elapsed().Seconds() | ||
|
||
succeeded := 0 | ||
for succeeded < len(llvNames) { | ||
llvs, err := getAllLLV(ctx, cl) | ||
if err != nil { | ||
b.Error(err) | ||
continue | ||
} | ||
|
||
for llvName, created := range llvNames { | ||
if llv, found := llvs[llvName]; found { | ||
if llv.Status != nil { | ||
b.Logf("LV %s status %s", llvName, llv.Status.Phase) | ||
} | ||
if err != nil { | ||
b.Logf("can't check LLV %s llv", llvName) | ||
continue | ||
} | ||
|
||
if llv.Status != nil && | ||
llv.Status.Phase == createdStatusPhase && | ||
!created { | ||
succeeded++ | ||
llvNames[llvName] = true | ||
|
||
if resizeOn { | ||
add, err := resource.ParseQuantity("1G") | ||
if err != nil { | ||
b.Logf(err.Error()) | ||
continue | ||
} | ||
|
||
llv.Spec.Size.Add(add) | ||
err = cl.Update(ctx, &llv) | ||
if err != nil { | ||
b.Logf(err.Error()) | ||
continue | ||
} | ||
|
||
b.Logf("resize for LV %s succeeded", llvName) | ||
} | ||
} | ||
} | ||
|
||
} | ||
} | ||
b.Logf("[TIME] LLV resources were configured for %f", lvCreatedTime) | ||
|
||
b.Logf("All LLV were created for %f. Ends the test", b.Elapsed().Seconds()) | ||
} | ||
|
||
func BenchmarkRunThinLLVCreationSingleThread(b *testing.B) { | ||
b.Logf("starts thin test") | ||
llvNames := make(map[string]bool, lvCount) | ||
|
||
b.StartTimer() | ||
for i := 0; i < lvCount; i++ { | ||
llv := configureTestThinLLV(fmt.Sprintf("test-llv-%d", i), lvgName, poolName) | ||
err := cl.Create(ctx, llv) | ||
if err != nil { | ||
b.Logf("unable to create test LLV %s, err: %s", llv.Name, err.Error()) | ||
continue | ||
} | ||
llvNames[llv.Name] = false | ||
} | ||
createdTime := b.Elapsed().Seconds() | ||
|
||
succeeded := 0 | ||
for succeeded < len(llvNames) { | ||
llvs, err := getAllLLV(ctx, cl) | ||
if err != nil { | ||
b.Error(err) | ||
continue | ||
} | ||
|
||
for llvName, visited := range llvNames { | ||
if llv, found := llvs[llvName]; found { | ||
if llv.Status != nil { | ||
b.Logf("LV %s status %s", llvName, llv.Status.Phase) | ||
} | ||
if err != nil { | ||
b.Logf("can't check LLV %s llv", llvName) | ||
continue | ||
} | ||
|
||
if llv.Status != nil && | ||
llv.Status.Phase == createdStatusPhase && | ||
!visited { | ||
succeeded++ | ||
llvNames[llvName] = true | ||
|
||
if resizeOn { | ||
add, err := resource.ParseQuantity("1G") | ||
if err != nil { | ||
b.Logf(err.Error()) | ||
continue | ||
} | ||
|
||
llv.Spec.Size.Add(add) | ||
err = cl.Update(ctx, &llv) | ||
if err != nil { | ||
b.Logf(err.Error()) | ||
continue | ||
} | ||
|
||
b.Logf("resize for LV %s succeeded", llvName) | ||
} | ||
} | ||
} | ||
|
||
} | ||
} | ||
b.Logf("All LLV were configured for %f. Ends the test", createdTime) | ||
b.Logf("All LLV were created in %f. Ends the test", b.Elapsed().Seconds()) | ||
} | ||
|
||
//func BenchmarkDeleteTestLLV(b *testing.B) { | ||
// b.Logf("delete test llv") | ||
// for name := range llvNames { | ||
// llv := &v1alpha1.LVMLogicalVolume{ | ||
// TypeMeta: metav1.TypeMeta{ | ||
// Kind: v1alpha1.LVMLogicalVolumeKind, | ||
// APIVersion: v1alpha1.TypeMediaAPIVersion, | ||
// }, | ||
// ObjectMeta: metav1.ObjectMeta{ | ||
// Name: name, | ||
// }, | ||
// } | ||
// err := cl.Delete(ctx, llv) | ||
// if err != nil { | ||
// b.Logf(err.Error()) | ||
// } | ||
// } | ||
// b.Logf("ends the deletion") | ||
//} | ||
|
||
func getAllLLV(ctx context.Context, cl client.Client) (map[string]v1alpha1.LVMLogicalVolume, error) { | ||
list := &v1alpha1.LVMLogicalVolumeList{} | ||
err := cl.List(ctx, list) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
res := make(map[string]v1alpha1.LVMLogicalVolume, len(list.Items)) | ||
for _, lv := range list.Items { | ||
res[lv.Name] = lv | ||
} | ||
|
||
return res, nil | ||
} | ||
|
||
func configureTestThickLLV(name, lvgName string) *v1alpha1.LVMLogicalVolume { | ||
return &v1alpha1.LVMLogicalVolume{ | ||
TypeMeta: metav1.TypeMeta{ | ||
Kind: v1alpha1.LVMLogicalVolumeKind, | ||
APIVersion: v1alpha1.TypeMediaAPIVersion, | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: name, | ||
Finalizers: []string{internal.SdsNodeConfiguratorFinalizer}, | ||
}, | ||
Spec: v1alpha1.LVMLogicalVolumeSpec{ | ||
ActualLVNameOnTheNode: name, | ||
Type: Thick, | ||
Size: size, | ||
LvmVolumeGroupName: lvgName, | ||
}, | ||
} | ||
} | ||
|
||
func configureTestThinLLV(name, lvgName, poolName string) *v1alpha1.LVMLogicalVolume { | ||
return &v1alpha1.LVMLogicalVolume{ | ||
TypeMeta: metav1.TypeMeta{ | ||
Kind: v1alpha1.LVMLogicalVolumeKind, | ||
APIVersion: v1alpha1.TypeMediaAPIVersion, | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: name, | ||
Finalizers: []string{internal.SdsNodeConfiguratorFinalizer}, | ||
}, | ||
Spec: v1alpha1.LVMLogicalVolumeSpec{ | ||
ActualLVNameOnTheNode: name, | ||
Type: Thin, | ||
Size: size, | ||
LvmVolumeGroupName: lvgName, | ||
Thin: &v1alpha1.ThinLogicalVolumeSpec{PoolName: poolName}, | ||
}, | ||
} | ||
} | ||
|
||
func init() { | ||
//flag.StringVar(&lvgName, "lvgName", "", "LVMVolumeGroup name used to create LV") | ||
//flag.StringVar(&poolName, "poolName", "", "Thin pool name used to create LV") | ||
//flag.IntVar(&lvCount, "lvCount", 0, "Test LV lvCount") | ||
//flag.Parse() | ||
|
||
config, err := kubutils.KubernetesDefaultConfigCreate() | ||
if err != nil { | ||
fmt.Println(err.Error()) | ||
os.Exit(1) | ||
} | ||
|
||
scheme := runtime.NewScheme() | ||
for _, f := range resourcesSchemeFuncs { | ||
err := f(scheme) | ||
if err != nil { | ||
fmt.Println(err.Error()) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
options := client.Options{ | ||
Scheme: scheme, | ||
} | ||
|
||
cl, err = client.New(config, options) | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
} |
Oops, something went wrong.