From 77725fa8f8495c3048c77e63d8b72ba65dce8c95 Mon Sep 17 00:00:00 2001 From: tb365 Date: Tue, 14 Sep 2021 16:01:40 +0800 Subject: [PATCH] fix(region): change aws disk iops --- pkg/multicloud/aws/disk.go | 20 ++++++++++++++++++-- pkg/multicloud/aws/instance.go | 18 ++---------------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/pkg/multicloud/aws/disk.go b/pkg/multicloud/aws/disk.go index 0a3359e892..9f3ea44309 100644 --- a/pkg/multicloud/aws/disk.go +++ b/pkg/multicloud/aws/disk.go @@ -480,6 +480,22 @@ func (self *SRegion) resetDisk(diskId, snapshotId string) (string, error) { return StrVal(ret.VolumeId), self.DeleteDisk(diskId) } +// io1类型的卷需要指定IOPS参数,最大不超过32000。这里根据aws网站的建议值进行设置 +// io2类型的卷需要指定IOPS参数,最大不超过64000。 +// GenDiskIops Base 100, 卷每增加2G。IOPS增加1。最多到3000 iops +func GenDiskIops(diskType string, sizeGB int) int64 { + if diskType == api.STORAGE_IO1_SSD || diskType == api.STORAGE_IO2_SSD { + iops := int64(100 + sizeGB/2) + if iops < 3000 { + return iops + } else { + return 3000 + } + } + + return 0 +} + func (self *SRegion) CreateDisk(zoneId string, category string, name string, sizeGb int, snapshotId string, desc string) (string, error) { tagspec := TagSpec{ResourceType: "volume"} tagspec.SetNameTag(name) @@ -494,8 +510,8 @@ func (self *SRegion) CreateDisk(zoneId string, category string, name string, siz params.SetSnapshotId(snapshotId) } - if category == api.STORAGE_IO1_SSD || category == api.STORAGE_IO2_SSD { - params.SetIops(200) + if iops := GenDiskIops(category, sizeGb); iops > 0 { + params.SetIops(iops) } params.SetTagSpecifications([]*ec2.TagSpecification{ec2Tags}) diff --git a/pkg/multicloud/aws/instance.go b/pkg/multicloud/aws/instance.go index 6571b01ae6..f47c3f6605 100644 --- a/pkg/multicloud/aws/instance.go +++ b/pkg/multicloud/aws/instance.go @@ -792,22 +792,8 @@ func (self *SRegion) CreateInstance(name string, image *SImage, instanceType str } } - // io1类型的卷需要指定IOPS参数。这里根据aws网站的建议值进行设置 - // 卷每增加1G。IOPS增加50。最大不超过32000 - if disk.Category == api.STORAGE_IO1_SSD { - iops := int64(disk.Size * 50) - if iops < 32000 { - ebs.SetIops(iops) - } else { - ebs.SetIops(32000) - } - } else if disk.Category == api.STORAGE_IO2_SSD { - iops := int64(disk.Size * 100) - if iops < 64000 { - ebs.SetIops(iops) - } else { - ebs.SetIops(64000) - } + if iops := GenDiskIops(disk.Category, disk.Size); iops > 0 { + ebs.SetIops(iops) } blockDevice := &ec2.BlockDeviceMapping{