From 83e4a83a6bf3e93bc8dcfdfef4fe54f43f2bb2ef Mon Sep 17 00:00:00 2001 From: Sebastian Webber Date: Wed, 17 Feb 2021 09:58:02 -0300 Subject: [PATCH] fix: random_page_cost and effective_io_concurrency added rules to compute those params. Signed-off-by: Sebastian Webber --- pkg/rules/compute.go | 1 + pkg/rules/storage.go | 24 ++++++++++++++++++++++++ pkg/rules/storage_test.go | 29 +++++++++++++++++++++++++++++ rules.yml | 2 +- 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 pkg/rules/storage.go create mode 100644 pkg/rules/storage_test.go diff --git a/pkg/rules/compute.go b/pkg/rules/compute.go index 85c239e..31f34f6 100644 --- a/pkg/rules/compute.go +++ b/pkg/rules/compute.go @@ -13,6 +13,7 @@ var allRules = []rule{ computeArch, computeOS, computeProfile, + computeStorage, // computeVersion can remove values deppending on the version // to be sure that it will not break other rules, leave it at diff --git a/pkg/rules/storage.go b/pkg/rules/storage.go new file mode 100644 index 0000000..62b1072 --- /dev/null +++ b/pkg/rules/storage.go @@ -0,0 +1,24 @@ +package rules + +import ( + "github.com/pgconfig/api/pkg/category" + "github.com/pgconfig/api/pkg/config" +) + +func computeStorage(in *config.Input, cfg *category.ExportCfg) (*category.ExportCfg, error) { + + switch in.DiskType { + case "SSD": + cfg.Storage.EffectiveIOConcurrency = 200 + case "SAN": + cfg.Storage.EffectiveIOConcurrency = 300 + default: + cfg.Storage.EffectiveIOConcurrency = 2 + } + + if in.DiskType != "HDD" { + cfg.Storage.RandomPageCost = 1.1 + } + + return cfg, nil +} diff --git a/pkg/rules/storage_test.go b/pkg/rules/storage_test.go new file mode 100644 index 0000000..dcbd7ee --- /dev/null +++ b/pkg/rules/storage_test.go @@ -0,0 +1,29 @@ +package rules + +import ( + "testing" + + "github.com/pgconfig/api/pkg/category" +) + +func Test_computeStorage(t *testing.T) { + in := fakeInput() + in.DiskType = "SSD" + outSSD, _ := computeStorage(in, category.NewExportCfg(*in)) + in.DiskType = "SAN" + outSAN, _ := computeStorage(in, category.NewExportCfg(*in)) + in.DiskType = "HDD" + outHDD, _ := computeStorage(in, category.NewExportCfg(*in)) + + if outSSD.Storage.RandomPageCost > 1.1 || outSAN.Storage.RandomPageCost > 1.1 { + t.Error("should use lower values for random_page_cost on both SSD and SAN") + } + + if outSSD.Storage.EffectiveIOConcurrency < 200 || outSAN.Storage.EffectiveIOConcurrency < 300 { + t.Error("should use higher values for effective_io_concurrency on both SSD and SAN") + } + + if outHDD.Storage.EffectiveIOConcurrency > 2 { + t.Error("should use lower values for effective_io_concurrency on HDD drives") + } +} diff --git a/rules.yml b/rules.yml index 6ea230a..4359401 100644 --- a/rules.yml +++ b/rules.yml @@ -126,4 +126,4 @@ categories: elsif disk_type == "SSD": 200 elsif disk_type == "SAN": - 200 + 300