Skip to content

Commit

Permalink
chore: refactor for OptimizeDiskPerformance code
Browse files Browse the repository at this point in the history
move dir

fix golint
  • Loading branch information
andyzhangx committed May 27, 2021
1 parent 1af2e64 commit 155e046
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pkg/azuredisk/device_perf_optimization_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func isPerfTuningEnabled(profile string) bool {
}

// getDiskPerfAttributes gets the per tuning mode and profile set in attributes
func getDiskPerfAttributes(attributes map[string]string) (profile string, accountType string, diskSizeGibStr string, diskIopsStr string, diskBwMbpsStr string, err error) {
func getDiskPerfAttributes(attributes map[string]string) (profile, accountType, diskSizeGibStr, diskIopsStr, diskBwMbpsStr string, err error) {
perfProfilePresent := false
for k, v := range attributes {
switch strings.ToLower(k) {
Expand Down
21 changes: 9 additions & 12 deletions pkg/azuredisk/device_perf_optimization_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ func (deviceHelper *DeviceHelper) DiskSupportsPerfOptimization(diskPerfProfile s
}

// OptimizeDiskPerformance optimizes device performance by setting tuning block device settings
func (deviceHelper *DeviceHelper) OptimizeDiskPerformance(nodeInfo *NodeInfo, diskSkus map[string]map[string]DiskSkuInfo, devicePath string,
perfProfile string, accountType string, diskSizeGibStr string, diskIopsStr string, diskBwMbpsStr string) (err error) {
func (deviceHelper *DeviceHelper) OptimizeDiskPerformance(nodeInfo *NodeInfo, diskSkus map[string]map[string]DiskSkuInfo, devicePath,
perfProfile, accountType, diskSizeGibStr, diskIopsStr, diskBwMbpsStr string) (err error) {
klog.V(2).Infof("OptimizeDiskPerformance: Tuning settings for %s", devicePath)

if nodeInfo == nil {
Expand Down Expand Up @@ -134,24 +134,21 @@ func getDeviceName(lunPath string) (deviceName string, err error) {

// echoToFile echos setting value to the file
func echoToFile(content string, filePath string) (err error) {
cmd := exec.Command("echo", content)
outfile, err := os.Create(filePath)
if err != nil {
return err
}
defer outfile.Close()

cmd.Stdout = outfile

err = cmd.Start()
var output []byte
output, err = exec.Command("echo", content).Output()
if err != nil {
return err
return fmt.Errorf("echo %s to %s failed with %v, output: %v", content, filePath, err, string(output))
}
err = cmd.Wait()
return err
return nil
}

func getOptimalDeviceSettings(nodeInfo *NodeInfo, diskSkus map[string]map[string]DiskSkuInfo, perfProfile string, accountType string, diskSizeGibStr string, diskIopsStr string, diskBwMbpsStr string) (queueDepth string, nrRequests string, scheduler string, maxSectorsKb string, readAheadKb string, err error) {
func getOptimalDeviceSettings(nodeInfo *NodeInfo, diskSkus map[string]map[string]DiskSkuInfo, perfProfile string, accountType, diskSizeGibStr, diskIopsStr, diskBwMbpsStr string) (queueDepth, nrRequests, scheduler, maxSectorsKb, readAheadKb string, err error) {
klog.V(2).Infof("Calculating perf optimizations for rofile %s accountType %s diskSize", perfProfile, accountType, diskSizeGibStr)

err = nil
Expand Down Expand Up @@ -224,7 +221,7 @@ func getOptimalDeviceSettings(nodeInfo *NodeInfo, diskSkus map[string]map[string

// getMatchingDiskSku gets the smallest SKU which matches the size, io and bw requirement
// TODO: Query the disk size (e.g. P10, P30 etc) and use that to find the sku
func getMatchingDiskSku(diskSkus map[string]map[string]DiskSkuInfo, accountType string, diskSizeGibStr string, diskIopsStr string, diskBwMbpsStr string) (matchingSku *DiskSkuInfo, err error) {
func getMatchingDiskSku(diskSkus map[string]map[string]DiskSkuInfo, accountType, diskSizeGibStr, diskIopsStr, diskBwMbpsStr string) (matchingSku *DiskSkuInfo, err error) {
err = nil
matchingSku = nil
accountTypeLower := strings.ToLower(accountType)
Expand Down Expand Up @@ -264,7 +261,7 @@ func getMatchingDiskSku(diskSkus map[string]map[string]DiskSkuInfo, accountType
}

// meetsRequest checks to see if given SKU meets\has enough size, iops and bw limits
func meetsRequest(sku *DiskSkuInfo, diskSizeGb int, diskIops int, diskBwMbps int) bool {
func meetsRequest(sku *DiskSkuInfo, diskSizeGb, diskIops, diskBwMbps int) bool {
if sku == nil {
return false
}
Expand Down
File renamed without changes.
Binary file added pkg/tool/gen-skus-map
Binary file not shown.
Binary file added pkg/tool/tool
Binary file not shown.

0 comments on commit 155e046

Please sign in to comment.