Skip to content

Commit

Permalink
remove gogo
Browse files Browse the repository at this point in the history
  • Loading branch information
d80tb7 committed Feb 11, 2025
1 parent 723cf64 commit 620c0d1
Show file tree
Hide file tree
Showing 6 changed files with 333 additions and 248 deletions.
7 changes: 7 additions & 0 deletions internal/common/proto/protoutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,10 @@ func ToStdDuration(pd *types.Duration) time.Duration {
}
return time.Duration(pd.Seconds)*time.Second + time.Duration(pd.Nanos)*time.Nanosecond
}

func ToDuration(d time.Duration) *types.Duration {
return &types.Duration{
Seconds: d.Nanoseconds() / 1000000000,
Nanos: int32(d.Nanoseconds() % 1000000000),
}
}
39 changes: 27 additions & 12 deletions internal/scheduler/simulator/simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ func (s *Simulator) setupClusters() error {
TotalResources: nodeTemplate.TotalResources.DeepCopy(),
AllocatableByPriorityAndResource: schedulerobjects.NewAllocatableByPriorityAndResourceType(
types.AllowedPriorities(s.schedulingConfig.PriorityClasses),
nodeTemplate.TotalResources,
*nodeTemplate.TotalResources,
),
}
dbNode := nodeFactory.FromSchedulerObjectsNode(node)
Expand Down Expand Up @@ -412,7 +412,7 @@ func (s *Simulator) bootstrapWorkload() error {
eventSequence.Events = append(
eventSequence.Events,
&armadaevents.EventSequence_Event{
Created: protoutil.ToTimestamp(s.time.Add(jobTemplate.EarliestSubmitTime)),
Created: protoutil.ToTimestamp(s.time.Add(protoutil.ToStdDuration(jobTemplate.EarliestSubmitTime))),
Event: &armadaevents.EventSequence_Event_SubmitJob{
SubmitJob: submitJobFromJobTemplate(jobId, jobTemplate, gangId),
},
Expand Down Expand Up @@ -464,7 +464,7 @@ func submitJobFromJobTemplate(jobId string, jobTemplate *JobTemplate, gangId str
annotations[serverconfig.GangNodeUniformityLabelAnnotation] = "armadaproject.io/clusterName"
}
// Make it so gang jobs end at the same time, this means they don't have a distribution currently
jobTemplate.RuntimeDistribution.TailMean = 0
jobTemplate.RuntimeDistribution.TailMean = protoutil.ToDuration(0)
}

return &armadaevents.SubmitJob{
Expand Down Expand Up @@ -864,16 +864,26 @@ func (s *Simulator) handleJobRunLeased(txn *jobdb.Txn, e *armadaevents.JobRunLea
return updatedJob, true, nil
}

func (s *Simulator) generateRandomShiftedExponentialDuration(rv ShiftedExponential) time.Duration {
func (s *Simulator) generateRandomShiftedExponentialDuration(rv *ShiftedExponential) time.Duration {
return generateRandomShiftedExponentialDuration(s.rand, rv)
}

func generateRandomShiftedExponentialDuration(r *rand.Rand, rv ShiftedExponential) time.Duration {
if rv.TailMean == 0 {
return rv.Minimum
} else {
return rv.Minimum + time.Duration(r.ExpFloat64()*float64(rv.TailMean))
func generateRandomShiftedExponentialDuration(r *rand.Rand, rv *ShiftedExponential) time.Duration {
if rv == nil {
return 0
}

tailMean := time.Duration(0)
if rv.TailMean != nil {
tailMean = protoutil.ToStdDuration(rv.TailMean)
}

minimum := time.Duration(0)
if rv.Minimum != nil {
minimum = protoutil.ToStdDuration(rv.Minimum)
}

return minimum + time.Duration(r.ExpFloat64()*float64(tailMean))
}

func (s *Simulator) handleJobSucceeded(txn *jobdb.Txn, e *armadaevents.JobSucceeded) (*jobdb.Job, bool, error) {
Expand Down Expand Up @@ -923,6 +933,10 @@ func (s *Simulator) handleJobSucceeded(txn *jobdb.Txn, e *armadaevents.JobSuccee
for _, dependentJobTemplate := range s.jobTemplatesByDependencyIds[jobTemplate.Id] {
i := slices.Index(dependentJobTemplate.Dependencies, jobTemplate.Id)
dependentJobTemplate.Dependencies = slices.Delete(dependentJobTemplate.Dependencies, i, i+1)

templateEarliestSubmitTime := protoutil.ToStdDuration(dependentJobTemplate.EarliestSubmitTime)
dependentTemplateEarliestSubmitTime := protoutil.ToStdDuration(dependentJobTemplate.EarliestSubmitTimeFromDependencyCompletion)

if len(dependentJobTemplate.Dependencies) > 0 {
continue
}
Expand All @@ -941,7 +955,7 @@ func (s *Simulator) handleJobSucceeded(txn *jobdb.Txn, e *armadaevents.JobSuccee
eventSequence.Events,
&armadaevents.EventSequence_Event{
// EarliestSubmitTimeFromDependencyCompletion must be positive
Created: protoutil.ToTimestamp(maxTime(time.Time{}.Add(dependentJobTemplate.EarliestSubmitTime), s.time.Add(dependentJobTemplate.EarliestSubmitTimeFromDependencyCompletion))),
Created: protoutil.ToTimestamp(maxTime(s.time.Add(templateEarliestSubmitTime), s.time.Add(dependentTemplateEarliestSubmitTime))),
Event: &armadaevents.EventSequence_Event_SubmitJob{
SubmitJob: submitJobFromJobTemplate(jobId, dependentJobTemplate, gangId),
},
Expand Down Expand Up @@ -1053,12 +1067,13 @@ func expandRepeatingTemplates(w *WorkloadSpec) *WorkloadSpec {
var templates []*JobTemplate
for _, template := range q.GetJobTemplates() {
if template.Repeat != nil {
period := *template.Repeat.Period
period := protoutil.ToStdDuration(template.Repeat.Period)
for i := 0; i < int(template.Repeat.NumTimes); i++ {
t := proto.Clone(template).(*JobTemplate)
earliestSubmitTime := protoutil.ToStdDuration(t.EarliestSubmitTime) + time.Duration(i)*period
t.Repeat = nil
t.Id = fmt.Sprintf("%s-repeat-%d", t.Id, i)
t.EarliestSubmitTime = t.EarliestSubmitTime + time.Duration(i)*period
t.EarliestSubmitTime = protoutil.ToDuration(earliestSubmitTime)
templates = append(templates, t)
}
} else {
Expand Down
Loading

0 comments on commit 620c0d1

Please sign in to comment.