You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

dynamicResources.go 2.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package strategy
  2. import (
  3. "errors"
  4. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/common"
  5. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/schedulers/option"
  6. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/collector"
  7. )
  8. type DynamicResourcesStrategy struct {
  9. replicas int32
  10. resources []*collector.ResourceStats
  11. opt option.Option
  12. }
  13. func NewDynamicResourcesStrategy(resources []*collector.ResourceStats, opt option.Option, replica int32) *DynamicResourcesStrategy {
  14. return &DynamicResourcesStrategy{resources: resources, opt: opt, replicas: replica}
  15. }
  16. func (ps *DynamicResourcesStrategy) Schedule() ([]*AssignedCluster, error) {
  17. if ps.replicas < 1 {
  18. return nil, errors.New("replicas must be greater than 0")
  19. }
  20. switch ps.opt.GetOptionType() {
  21. case option.AI:
  22. opt := (interface{})(ps.opt).(*option.AiOption)
  23. var maxCardHoursAvailable float64
  24. var maxCpuCoreHoursAvailable float64
  25. var assignedCluster AssignedCluster
  26. var results []*AssignedCluster
  27. for _, res := range ps.resources {
  28. if res == nil {
  29. continue
  30. }
  31. if opt.ResourceType == "cpu" {
  32. if res.CpuCoreHours <= 0 {
  33. cluster := &AssignedCluster{ClusterId: res.ClusterId, Replicas: ps.replicas}
  34. results = append(results, cluster)
  35. return results, nil
  36. }
  37. if res.CpuCoreHours > maxCpuCoreHoursAvailable {
  38. maxCpuCoreHoursAvailable = res.CpuCoreHours
  39. assignedCluster.ClusterId = res.ClusterId
  40. assignedCluster.Replicas = ps.replicas
  41. }
  42. }
  43. if opt.ResourceType == "computeCard" {
  44. var maxCurrentCardHours float64
  45. for _, card := range res.CardsAvail {
  46. cardHours := common.RoundFloat( /*card.TOpsAtFp16**/ card.CardHours, 3)
  47. if cardHours > maxCurrentCardHours {
  48. maxCurrentCardHours = cardHours
  49. }
  50. }
  51. if maxCurrentCardHours > maxCardHoursAvailable {
  52. maxCardHoursAvailable = maxCurrentCardHours
  53. assignedCluster.ClusterId = res.ClusterId
  54. assignedCluster.Replicas = ps.replicas
  55. }
  56. }
  57. }
  58. results = append(results, &assignedCluster)
  59. return results, nil
  60. case option.CLOUD:
  61. }
  62. return nil, errors.New("failed to apply DynamicResourcesStrategy")
  63. }

PCM is positioned as Software stack over Cloud, aiming to build the standards and ecology of heterogeneous cloud collaboration for JCC in a non intrusive and autonomous peer-to-peer manner.