MCPcopy Create free account
hub / github.com/Permify/permify / calculateAverageLoad

Method calculateAverageLoad

pkg/consistent/consistent.go:161–173  ·  view source on GitHub ↗

calculateAverageLoad is a private helper method that performs the actual calculation of the average load across all members. It is not thread-safe and should be called only from within methods that already manage locking.

()

Source from the content-addressed store, hash-verified

159// of the average load across all members. It is not thread-safe and should be called
160// only from within methods that already manage locking.
161func (c *Consistent) calculateAverageLoad() float64 {
162 // If there are no members, return an average load of 0 to prevent division by zero.
163 if len(c.members) == 0 {
164 return 0
165 }
166
167 // Calculate the average load by dividing the total partition count by the number of members
168 // and multiplying by the configured load factor.
169 avgLoad := float64(c.partitionCount/uint64(len(c.members))) * c.config.Load
170
171 // Use math.Ceil to round up the average load to the nearest whole number.
172 return math.Ceil(avgLoad)
173}
174
175// assignPartitionWithLoad distributes a partition to a member based on the load factor.
176// It ensures that no member exceeds the calculated average load while distributing partitions.

Callers 2

GetAverageLoadMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected