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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package strategy
  2. import (
  3. "errors"
  4. "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/scheduler/common"
  5. "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/scheduler/schedulers/option"
  6. "gitlink.org.cn/JointCloud/pcm-coordinator/api/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 opt.ResourceType == "cpu" {
  29. if res.CpuCoreHours <= 0 {
  30. cluster := &AssignedCluster{ClusterId: res.ClusterId, Replicas: ps.replicas}
  31. results = append(results, cluster)
  32. return results, nil
  33. }
  34. if res.CpuCoreHours > maxCpuCoreHoursAvailable {
  35. maxCpuCoreHoursAvailable = res.CpuCoreHours
  36. assignedCluster.ClusterId = res.ClusterId
  37. assignedCluster.Replicas = ps.replicas
  38. }
  39. }
  40. if opt.ResourceType == "computeCard" {
  41. var maxCurrentCardHours float64
  42. for _, card := range res.CardsAvail {
  43. cardHours := common.RoundFloat( /*card.TOpsAtFp16**/ card.CardHours, 3)
  44. if cardHours > maxCurrentCardHours {
  45. maxCurrentCardHours = cardHours
  46. }
  47. }
  48. if maxCurrentCardHours > maxCardHoursAvailable {
  49. maxCardHoursAvailable = maxCurrentCardHours
  50. assignedCluster.ClusterId = res.ClusterId
  51. assignedCluster.Replicas = ps.replicas
  52. }
  53. }
  54. }
  55. results = append(results, &assignedCluster)
  56. return results, nil
  57. case option.CLOUD:
  58. }
  59. return nil, errors.New("failed to apply DynamicResourcesStrategy")
  60. }

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.