harmonytask tests
This commit is contained in:
parent
3d60a65906
commit
e72e8588b9
@ -161,7 +161,7 @@ func TestHarmonyTasksWith2PartiesPolling(t *testing.T) {
|
|||||||
sender.GracefullyTerminate(time.Second * 5)
|
sender.GracefullyTerminate(time.Second * 5)
|
||||||
worker.GracefullyTerminate(time.Second * 5)
|
worker.GracefullyTerminate(time.Second * 5)
|
||||||
sort.Strings(dest)
|
sort.Strings(dest)
|
||||||
require.Equal(t, dest, []string{"A", "B"})
|
require.Equal(t, []string{"A", "B"}, dest)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -399,6 +399,9 @@ func (e *TaskEngine) resourcesInUse() resources.Resources {
|
|||||||
tmp.Cpu -= int(ct) * t.Cost.Cpu
|
tmp.Cpu -= int(ct) * t.Cost.Cpu
|
||||||
tmp.Gpu -= float64(ct) * t.Cost.Gpu
|
tmp.Gpu -= float64(ct) * t.Cost.Gpu
|
||||||
tmp.Ram -= uint64(ct) * t.Cost.Ram
|
tmp.Ram -= uint64(ct) * t.Cost.Ram
|
||||||
|
if len(t.Cost.GpuRam) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
for i := int32(0); i < ct; i++ {
|
for i := int32(0); i < ct; i++ {
|
||||||
for grIdx, j := range tmp.GpuRam {
|
for grIdx, j := range tmp.GpuRam {
|
||||||
if j > t.Cost.GpuRam[0] {
|
if j > t.Cost.GpuRam[0] {
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
logging "github.com/ipfs/go-log/v2"
|
logging "github.com/ipfs/go-log/v2"
|
||||||
|
"github.com/samber/lo"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/lib/harmony/harmonydb"
|
"github.com/filecoin-project/lotus/lib/harmony/harmonydb"
|
||||||
)
|
)
|
||||||
@ -219,7 +220,7 @@ func (h *taskTypeHandler) AssertMachineHasCapacity() error {
|
|||||||
return errors.New("Did not accept " + h.Name + " task: out of available GPU")
|
return errors.New("Did not accept " + h.Name + " task: out of available GPU")
|
||||||
}
|
}
|
||||||
for _, u := range r.GpuRam {
|
for _, u := range r.GpuRam {
|
||||||
if u > h.Cost.GpuRam[0] {
|
if u > lo.Sum(h.Cost.GpuRam) {
|
||||||
goto enoughGpuRam
|
goto enoughGpuRam
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,11 +54,12 @@ func Register(db *harmonydb.DB, hostnameAndPort string) (*Reg, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("could not read from harmony_machines: %w", err)
|
return nil, fmt.Errorf("could not read from harmony_machines: %w", err)
|
||||||
}
|
}
|
||||||
|
gpuram := lo.Sum(reg.GpuRam)
|
||||||
if len(ownerID) == 0 {
|
if len(ownerID) == 0 {
|
||||||
err = db.QueryRow(ctx, `INSERT INTO harmony_machines
|
err = db.QueryRow(ctx, `INSERT INTO harmony_machines
|
||||||
(host_and_port, cpu, ram, gpu, gpuram) VALUES
|
(host_and_port, cpu, ram, gpu, gpuram) VALUES
|
||||||
($1,$2,$3,$4,$5) RETURNING id`,
|
($1,$2,$3,$4,$5) RETURNING id`,
|
||||||
hostnameAndPort, reg.Cpu, reg.Ram, reg.Gpu, lo.Sum(reg.GpuRam)).Scan(®.Resources.MachineID)
|
hostnameAndPort, reg.Cpu, reg.Ram, reg.Gpu, gpuram).Scan(®.Resources.MachineID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -67,7 +68,7 @@ func Register(db *harmonydb.DB, hostnameAndPort string) (*Reg, error) {
|
|||||||
reg.MachineID = ownerID[0]
|
reg.MachineID = ownerID[0]
|
||||||
_, err := db.Exec(ctx, `UPDATE harmony_machines SET
|
_, err := db.Exec(ctx, `UPDATE harmony_machines SET
|
||||||
cpu=$1, ram=$2, gpu=$3, gpuram=$4 WHERE id=$6`,
|
cpu=$1, ram=$2, gpu=$3, gpuram=$4 WHERE id=$6`,
|
||||||
reg.Cpu, reg.Ram, reg.Gpu, lo.Sum(reg.GpuRam), reg.Resources.MachineID)
|
reg.Cpu, reg.Ram, reg.Gpu, gpuram, reg.Resources.MachineID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user