1753
in *taskqueuepb.TaskQueueStats,
1754
rampPct float32,
1756
>
if in == nil {
1757
in = &taskqueuepb.TaskQueueStats{ApproximateBacklogAge: durationpb.New(0)}
1758
}
1759
1761
>
// We intentionally bias towards over-attribution ("safe side"):
1762
>
// compute both shares with ceil. This can result in currentCount+rampCount > total.
1763
>
rampCount := int64(math.Ceil(float64(total) * float64(rampPct) / 100.0))
1764
>
currentCount := int64(math.Ceil(float64(total) * float64(100.0-rampPct) / 100.0))
1765
>
1766
>
// Just being defensive here; should never happen.
1767
>
if rampCount < 0 {
1768
rampCount = 0
1769
}
1771
currentCount = 0
1772
}
1773
1775
>
rampDispatchRate := in.GetTasksDispatchRate() * rampPct / 100
1776
>
1777
>
age := in.GetApproximateBacklogAge()
1778
>
if age == nil {
1779
age = durationpb.New(0)
1780
}
1781
1782
// Rather than splitting the backlog age, we set it to the oldest backlog age for both the current and the ramping shares.
1784
>
rampAge := durationpb.New(age.AsDuration())
1785
>
if currentCount == 0 {
1786
currentAge = durationpb.New(0)
1787
}
1789
rampAge = durationpb.New(0)
1790
}
1791
1793
>
ApproximateBacklogCount: currentCount,
1794
>
ApproximateBacklogAge: currentAge,
1795
>
TasksAddRate: in.GetTasksAddRate() - rampAddRate,
1796
>
TasksDispatchRate: in.GetTasksDispatchRate() - rampDispatchRate,
1797
>
}
1798
>
rampShare = &taskqueuepb.TaskQueueStats{
1799
>
ApproximateBacklogCount: rampCount,
1800
>
ApproximateBacklogAge: rampAge,
1801
>
TasksAddRate: rampAddRate,
1802
>
TasksDispatchRate: rampDispatchRate,
1803
>
}
1804
>
return currentShare, rampShare
1805
}
1806