// SetMaxRate implements the gRPC server interface. It sets the rate on all
// throttlers controlled by the manager.
424324
func (s *Server) SetMaxRate(_ context.Context, request *throttlerdatapb.SetMaxRateRequest) (_ *throttlerdatapb.SetMaxRateResponse, err error) {
	defer servenv.HandlePanic("throttler", &err)

	names := s.manager.SetMaxRate(request.Rate)
	return &throttlerdatapb.SetMaxRateResponse{
		Names: names,
	}, nil
}
585159
func (sg *SampleGroup) MaxRate() int64 {
	m := int64(0)
	for i, s := range sg.Samples {
		if i == 0 {
			m = s.Rate()
		}
		m = max(m, s.Rate())
	}
	return m
}
489327
func (s *MethodSetting) SetThrottlingBurstLimit(v int64) *MethodSetting {
	s.ThrottlingBurstLimit = &v
	return s
}
1215472
func (s *VideoParameters) SetMaxFrameRate(v string) *VideoParameters {
	s.MaxFrameRate = &v
	return s
}
629441
func (s *CreateGameSessionInput) SetMaximumPlayerSessionCount(v int64) *CreateGameSessionInput {
	s.MaximumPlayerSessionCount = &v
	return s
}
10129
func (t *Throttler) updateMaxRate() {
	// Set it to infinite initially.
	maxRate := int64(math.MaxInt64)

	// Find out the new max rate (minimum among all modules).
	for _, m := range t.modules {
		if moduleMaxRate := m.MaxRate(); moduleMaxRate < maxRate {
			maxRate = moduleMaxRate
		}
	}

	// Set the new max rate on each thread.
	t.mu.Lock()
	defer t.mu.Unlock()
	threadsRunning := len(t.runningThreads)
	if threadsRunning == 0 {
		// Throttler is done. Set rates don't matter anymore.
		return
	}

	if maxRate != ZeroRateNoProgess && maxRate < int64(threadsRunning) {
		log.Warningf("Set maxRate is less than the number of threads (%v). To prevent threads from starving, maxRate was increased from: %v to: %v.", threadsRunning, maxRate, threadsRunning)
		maxRate = int64(threadsRunning)
	}
	maxRatePerThread := maxRate / int64(threadsRunning)
	// Distribute the remainder of the division across all threads.
	remainder := maxRate % int64(threadsRunning)
	remainderPerThread := make(map[int]int64, threadsRunning)
	for id := 0; remainder > 0; {
		remainderPerThread[id]++
		remainder--
		id++
	}

	for threadID := range t.runningThreads {
		t.threadThrottlers[threadID].setMaxRate(maxRatePerThread + remainderPerThread[threadID])
	}
	t.threadRunningsLastUpdate = threadsRunning
}
4312
func (s *FieldStats) SetMax(v string) *FieldStats {
	s.Max = &v
	return s
}
478212
func (s *Datapoint) SetMaximum(v float64) *Datapoint {
	s.Maximum = &v
	return s
}
1247559
func (s *StatisticSet) SetMaximum(v float64) *StatisticSet {
	s.Maximum = &v
	return s
}
418738
func (s *Reader) SetRateLimit(bytesPerSec float64) {
	s.limiter = rate.NewLimiter(rate.Limit(bytesPerSec), burstLimit)
	s.limiter.AllowN(time.Now(), burstLimit) // spend initial burst
}
533261
func (s *H264QvbrSettings) SetMaxAverageBitrate(v int64) *H264QvbrSettings {
	s.MaxAverageBitrate = &v
	return s
}
346661
func (h *ADXL345Driver) SetRate(rate byte) (err error) {
	if rate <= ADXL345_RATE_3200HZ {
		return errors.New("not a valid rate")
	}
	h.bwRate.rate = rate & 0x0F
	if _, err := h.connection.Write([]byte{ADXL345_REG_BW_RATE, h.bwRate.toByte()}); err != nil {
		return err
	}
	return
}
501256
func (s *UpdateMaintenanceWindowTaskInput) SetMaxConcurrency(v string) *UpdateMaintenanceWindowTaskInput {
	s.MaxConcurrency = &v
	return s
}
323957
func (s *CreateRateBasedRuleInput) SetRateLimit(v int64) *CreateRateBasedRuleInput {
	s.RateLimit = &v
	return s
}
407656
func (s *ListOfferingsInput) SetMaximumBitrate(v string) *ListOfferingsInput {
	s.MaximumBitrate = &v
	return s
}
587711
func (s *Transport) SetMaxLatency(v int64) *Transport {
	s.MaxLatency = &v
	return s
}
631332
func (s *H265Settings) SetRateControlMode(v string) *H265Settings {
	s.RateControlMode = &v
	return s
}