diff --git a/harmony/harmonytask/harmonytask.go b/harmony/harmonytask/harmonytask.go index e59b79ca3..f14035bb0 100644 --- a/harmony/harmonytask/harmonytask.go +++ b/harmony/harmonytask/harmonytask.go @@ -7,6 +7,7 @@ import ( "sync/atomic" "time" + logging "github.com/ipfs/go-log/v2" "github.com/samber/lo" "go.opencensus.io/stats" "go.opencensus.io/tag" @@ -425,15 +426,20 @@ func (e *TaskEngine) pollerTryAllWork() bool { return false } +var rlog = logging.Logger("harmony-res") + // ResourcesAvailable determines what resources are still unassigned. func (e *TaskEngine) ResourcesAvailable() resources.Resources { tmp := e.reg.Resources + llog := rlog.With("Resource availability Check") for _, t := range e.handlers { ct := t.Max.ActiveThis() tmp.Cpu -= ct * t.Cost.Cpu tmp.Gpu -= float64(ct) * t.Cost.Gpu tmp.Ram -= uint64(ct) * t.Cost.Ram + llog.Debugw("Per task type", "Name", t.Name, "Count", ct, "CPU", ct*t.Cost.Cpu, "RAM", uint64(ct)*t.Cost.Ram, "GPU", float64(ct)*t.Cost.Gpu) } + llog.Debugw("Total", "CPU", tmp.Cpu, "RAM", tmp.Ram, "GPU", tmp.Gpu) return tmp } diff --git a/harmony/harmonytask/task_type_handler.go b/harmony/harmonytask/task_type_handler.go index 9e93fd613..b58e8600d 100644 --- a/harmony/harmonytask/task_type_handler.go +++ b/harmony/harmonytask/task_type_handler.go @@ -11,6 +11,7 @@ import ( logging "github.com/ipfs/go-log/v2" "go.opencensus.io/stats" "go.opencensus.io/tag" + "golang.org/x/xerrors" "github.com/filecoin-project/go-state-types/abi" @@ -336,13 +337,13 @@ func (h *taskTypeHandler) AssertMachineHasCapacity() error { } if r.Cpu-h.Cost.Cpu < 0 { - return errors.New("Did not accept " + h.Name + " task: out of cpu") + return xerrors.Errorf("Did not accept %s task: out of cpu: required %d available %d)", h.Name, h.Cost.Cpu, r.Cpu) } if h.Cost.Ram > r.Ram { - return errors.New("Did not accept " + h.Name + " task: out of RAM") + return xerrors.Errorf("Did not accept %s task: out of RAM: required %d available %d)", h.Name, h.Cost.Ram, r.Ram) } if r.Gpu-h.Cost.Gpu < 0 { - return errors.New("Did not accept " + h.Name + " task: out of available GPU") + return xerrors.Errorf("Did not accept %s task: out of available GPU: required %f available %f)", h.Name, h.Cost.Gpu, r.Gpu) } if h.TaskTypeDetails.Cost.Storage != nil { diff --git a/harmony/resources/resources.go b/harmony/resources/resources.go index 48d524ddb..98ba6192e 100644 --- a/harmony/resources/resources.go +++ b/harmony/resources/resources.go @@ -98,6 +98,8 @@ func Register(db *harmonydb.DB, hostnameAndPort string) (*Reg, error) { } }() + logger.Infow("Node registered the following resources", "CPU", reg.Cpu, "Memory", reg.Ram, "GPU", reg.Gpu) + return ®, nil }