Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion server/api/v1/instance/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
instanceModel "github.com/flipped-aurora/gin-vue-admin/server/model/instance"
instanceReq "github.com/flipped-aurora/gin-vue-admin/server/model/instance/request"
instanceServicePkg "github.com/flipped-aurora/gin-vue-admin/server/service/instance"
"github.com/flipped-aurora/gin-vue-admin/server/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
Expand Down Expand Up @@ -264,7 +265,12 @@ func (instanceApi *InstanceApi) GetAvailableNodes(c *gin.Context) {
return
}

nodes, err := instanceService.GetAvailableNodes(ctx, specId)
meta := instanceServicePkg.SchedulingRequestMeta{
Region: c.Query("region"),
ISP: c.Query("isp"),
UserHash: c.Query("userHash"),
}
nodes, err := instanceService.GetAvailableNodes(ctx, specId, meta)
if err != nil {
global.GVA_LOG.Error("查询可用节点失败!", zap.Error(err))
response.FailWithMessage("查询可用节点失败:"+err.Error(), c)
Expand Down
18 changes: 18 additions & 0 deletions server/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,24 @@ mcp:
url_prefix: ""
addr: 8889
separate: false
pcdn:
enabled: true
version: v2-canary
stable-version: v1
release-state: canary
canary:
regions: ["华东", "华北"]
isps: ["电信", "联通"]
user-hash-percentage: 10
circuit-breaker:
failure-rate-threshold: 0.3
latency-threshold-ms: 800
min-samples: 10
score-weight:
gpu: 0.4
cpu: 0.25
memory: 0.25
disk: 0.1
jumpbox:
enabled: true
port: 2026
Expand Down
19 changes: 19 additions & 0 deletions server/config.yaml.bak
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,22 @@ zap:
show-line: true
log-in-console: true
retention-day: -1

pcdn:
enabled: true
version: v2-canary
stable-version: v1
release-state: canary
canary:
regions: ["华东", "华北"]
isps: ["电信", "联通"]
user-hash-percentage: 10
circuit-breaker:
failure-rate-threshold: 0.3
latency-threshold-ms: 800
min-samples: 10
score-weight:
gpu: 0.4
cpu: 0.25
memory: 0.25
disk: 0.1
3 changes: 3 additions & 0 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,7 @@ type Server struct {

// K8s管理器配置
K8sManager K8sManager `mapstructure:"k8smanager" json:"k8smanager" yaml:"k8smanager"`

// PCDN调度配置
PCDN PCDN `mapstructure:"pcdn" json:"pcdn" yaml:"pcdn"`
}
42 changes: 42 additions & 0 deletions server/config/pcdn.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package config

// PCDN 调度配置
// 支持策略发布状态、灰度规则以及熔断阈值动态调整
// 可通过热更新配置文件实时生效
// 发布状态:draft/canary/stable
// 灰度规则:地域、ISP、用户哈希比例
// 熔断规则:失败率、延迟阈值
// 注意:阈值单位详见字段注释
//
// 该结构由配置映射驱动,字段命名与 YAML 保持一致
// 为了避免歧义,这里保留较直观的命名。
//
//nolint:revive
type PCDN struct {
Enabled bool `mapstructure:"enabled" json:"enabled" yaml:"enabled"`
Version string `mapstructure:"version" json:"version" yaml:"version"`
ReleaseState string `mapstructure:"release-state" json:"release-state" yaml:"release-state"`
Canary Canary `mapstructure:"canary" json:"canary" yaml:"canary"`
CircuitBreaker CircuitBreak `mapstructure:"circuit-breaker" json:"circuit-breaker" yaml:"circuit-breaker"`
ScoreWeight ScoreWeight `mapstructure:"score-weight" json:"score-weight" yaml:"score-weight"`
StableVersion string `mapstructure:"stable-version" json:"stable-version" yaml:"stable-version"`
}

type Canary struct {
Regions []string `mapstructure:"regions" json:"regions" yaml:"regions"`
ISPs []string `mapstructure:"isps" json:"isps" yaml:"isps"`
UserHashPercentage int `mapstructure:"user-hash-percentage" json:"user-hash-percentage" yaml:"user-hash-percentage"`
}

type CircuitBreak struct {
FailureRateThreshold float64 `mapstructure:"failure-rate-threshold" json:"failure-rate-threshold" yaml:"failure-rate-threshold"`
LatencyThresholdMs int64 `mapstructure:"latency-threshold-ms" json:"latency-threshold-ms" yaml:"latency-threshold-ms"`
MinSamples int `mapstructure:"min-samples" json:"min-samples" yaml:"min-samples"`
}

type ScoreWeight struct {
Gpu float64 `mapstructure:"gpu" json:"gpu" yaml:"gpu"`
CPU float64 `mapstructure:"cpu" json:"cpu" yaml:"cpu"`
Memory float64 `mapstructure:"memory" json:"memory" yaml:"memory"`
Disk float64 `mapstructure:"disk" json:"disk" yaml:"disk"`
}
16 changes: 15 additions & 1 deletion server/service/instance/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"strconv"
"time"

"github.com/flipped-aurora/gin-vue-admin/server/global"
"github.com/flipped-aurora/gin-vue-admin/server/model/computenode"
Expand Down Expand Up @@ -417,7 +418,9 @@ type AvailableNode struct {
}

// GetAvailableNodes 根据产品规格获取可用的算力节点
func (instanceService *InstanceService) GetAvailableNodes(ctx context.Context, specIdStr string) (nodes []AvailableNode, err error) {
func (instanceService *InstanceService) GetAvailableNodes(ctx context.Context, specIdStr string, meta SchedulingRequestMeta) (nodes []AvailableNode, err error) {
startAt := time.Now()
strategyVersion, strategyState, hitRule, forceStable := chooseStrategy(meta)
specId, err := strconv.ParseUint(specIdStr, 10, 64)
if err != nil {
return nil, err
Expand Down Expand Up @@ -985,6 +988,17 @@ func (instanceService *InstanceService) GetAvailableNodes(ctx context.Context, s
nodes = append(nodes, availableNode)
}

breakerOn := pcdnSchedulerRuntime.isCircuitOpened()
nodes, scoreDetails := scoreAndSortNodes(nodes, strategyVersion, strategyState, hitRule, breakerOn)
if forceStable && len(nodes) == 0 {
fallback := pcdnSchedulerRuntime.stableFallbackNodes()
if len(fallback) > 0 {
nodes = fallback
hitRule += "_snapshot"
}
}
pcdnSchedulerRuntime.recordAndEvaluate(strategyVersion, strategyState, nodes, nil, time.Since(startAt))
writeSchedulingTraceLog(specIdStr, strategyVersion, strategyState, hitRule, meta, scoreDetails, len(nodes), nil)
return nodes, nil
}

Expand Down
Loading
Loading