// NewDefaultRateLimiter creates a default RateLimiter object.
199109
func NewRateLimiter(rate_bytes_per_sec, refill_period_us int64, fairness int32) *RateLimiter {
	return NewNativeRateLimiter(C.rocksdb_ratelimiter_create(
		C.int64_t(rate_bytes_per_sec),
		C.int64_t(refill_period_us),
		C.int32_t(fairness),
	))
}
198396
func (q *RateLimitedTimedQueue) SwapLimiter(newQPS float32) {
	q.limiterLock.Lock()
	defer q.limiterLock.Unlock()
	if q.limiter.QPS() == newQPS {
		return
	}
	var newLimiter flowcontrol.RateLimiter
	if newQPS <= 0 {
		newLimiter = flowcontrol.NewFakeNeverRateLimiter()
	} else {
		newLimiter = flowcontrol.NewTokenBucketRateLimiter(newQPS, EvictionRateLimiterBurst)

		// If we're currently waiting on limiter, we drain the new one - this is a good approach when Burst value is 1
		// TODO: figure out if we need to support higher Burst values and decide on the drain logic, should we keep:
		// - saturation (percentage of used tokens)
		// - number of used tokens
		// - number of available tokens
		// - something else
		if q.limiter.TryAccept() == false {
			newLimiter.TryAccept()
		}
	}
	q.limiter.Stop()
	q.limiter = newLimiter
}
1138049
func NewDefaultRoc() (indicator *Roc, err error) {
	timePeriod := 10
	return NewRoc(timePeriod, gotrade.UseClosePrice)
}
751064
func (c *RESTClient) GetRateLimiter() flowcontrol.RateLimiter {
	if c == nil {
		return nil
	}
	return c.Throttle
}
92498
func NewDefaultCapabilities(defaultAddCapabilities, requiredDropCapabilities, allowedCaps []api.Capability) (CapabilitiesSecurityContextConstraintsStrategy, error) {
	return &defaultCapabilities{
		defaultAddCapabilities:   defaultAddCapabilities,
		requiredDropCapabilities: requiredDropCapabilities,
		allowedCaps:              allowedCaps,
	}, nil
}
1008639
func NewDefaultRsiForStream(priceStream gotrade.DOHLCVStreamSubscriber) (indicator *Rsi, err error) {
	ind, err := NewDefaultRsi()
	priceStream.AddTickSubscription(ind)
	return ind, err
}
1039942
func DefaultControllerRateLimiter() RateLimiter {
	return NewMaxOfRateLimiter(
		NewItemExponentialFailureRateLimiter(5*time.Millisecond, 1000*time.Second),
		// 10 qps, 100 bucket size.  This is only for retry speed and its only the overall factor (not per item)
		&BucketRateLimiter{Limiter: rate.NewLimiter(rate.Limit(10), 100)},
	)
}
1324166
func NewRateLimitedFunction(keyFunc kcache.KeyFunc, interval int, handlerFunc HandlerFunc) *RateLimitedFunction {
	fifo := kcache.NewFIFO(keyFunc)

	qps := float32(1000.0) // Call rate per second (SLA).
	if interval > 0 {
		qps = float32(1.0 / float32(interval))
	}

	limiter := flowcontrol.NewTokenBucketRateLimiter(qps, 1)

	return &RateLimitedFunction{handlerFunc, fifo, limiter}
}
65755
func (tl *TokenLimiter) DefaultRates() *RateSet {
	defaultRates := NewRateSet()
	for _, r := range tl.defaultRates.m {
		defaultRates.Add(r.period, r.average, r.burst)
	}
	return defaultRates
}
829871
func NewDefaultConfig() *Config {
	return &Config{
		BaseURL:            env.GetOrDefaultString(baseURLEnvVar, defaultBaseURL),
		TTL:                env.GetOrDefaultInt(ttlEnvVar, minTTL),
		PropagationTimeout: env.GetOrDefaultSecond(propagationTimeoutEnvVar, 120*time.Second),
		PollingInterval:    env.GetOrDefaultSecond(pollingIntervalEnvVar, 2*time.Second),
		HTTPClient: &http.Client{
			Timeout: env.GetOrDefaultSecond(httpTimeoutEnvVar, 30*time.Second),
		},
	}
}
260374
func NewDefaultTrimaForStream(priceStream gotrade.DOHLCVStreamSubscriber) (indicator *Trima, err error) {
	ind, err := NewDefaultTrima()
	priceStream.AddTickSubscription(ind)
	return ind, err
}
604135
func NewDefaultType(in interface{}, context *compiler.Context) (*DefaultType, error) {
	errors := make([]error, 0)
	x := &DefaultType{}
	matched := false
	switch in := in.(type) {
	case bool:
		x.Oneof = &DefaultType_Boolean{Boolean: in}
		matched = true
	case string:
		x.Oneof = &DefaultType_String_{String_: in}
		matched = true
	case int64:
		x.Oneof = &DefaultType_Number{Number: float64(in)}
		matched = true
	case int32:
		x.Oneof = &DefaultType_Number{Number: float64(in)}
		matched = true
	case int:
		x.Oneof = &DefaultType_Number{Number: float64(in)}
		matched = true
	case float64:
		x.Oneof = &DefaultType_Number{Number: in}
		matched = true
	case float32:
		x.Oneof = &DefaultType_Number{Number: float64(in)}
		matched = true
	}
	if matched {
		// since the oneof matched one of its possibilities, discard any matching errors
		errors = make([]error, 0)
	}
	return x, compiler.NewErrorGroupOrNil(errors)
}
929442
func NewDefaultConfig() Config {
	// Default max parallelism to half the CPU cores, but at least always one.
	maxparallelism := runtime.NumCPU() / 2
	if maxparallelism <= 0 {
		maxparallelism = 1
	}

	return Config{
		FuncSnippetEnabled:      true,
		GocodeCompletionEnabled: false,
		FormatTool:              formatToolGoimports,
		LintTool:                lintToolNone,
		DiagnosticsEnabled:      false,
		MaxParallelism:          maxparallelism,
		UseBinaryPkgCache:       true,
	}
}
1087902
func RateLimited(limit int) *Notifier {
	n := &Notifier{}
	if limit > 0 {
		n.lim = ratelimit.NewRateLimiter(process.Background(), limit)
	}
	return n
}
1290805
func NewWithDefaults(
	serverID string,
	collector collector.EventCollector,
	service packetprocessor.PacketProcessor,
	secrets secrets.Secrets,
	mode constants.ModeType,
	procMountPoint string,
	targetNetworks []string,
) *Datapath {

	if collector == nil {
		zap.L().Fatal("Collector must be given to NewDefaultDatapathEnforcer")
	}

	defaultMutualAuthorization := false
	defaultFQConfig := fqconfig.NewFilterQueueWithDefaults()
	defaultValidity := time.Hour * 8760
	defaultExternalIPCacheTimeout, err := time.ParseDuration(enforcerconstants.DefaultExternalIPTimeout)
	if err != nil {
		defaultExternalIPCacheTimeout = time.Second
	}
	defaultPacketLogs := false

	tokenAccessor, err := tokenaccessor.New(serverID, defaultValidity, secrets)
	if err != nil {
		zap.L().Fatal("Cannot create a token engine", zap.Error(err))
	}

	puFromContextID := cache.NewCache("puFromContextID")

	e := New(
		defaultMutualAuthorization,
		defaultFQConfig,
		collector,
		serverID,
		defaultValidity,
		service,
		secrets,
		mode,
		procMountPoint,
		defaultExternalIPCacheTimeout,
		defaultPacketLogs,
		tokenAccessor,
		puFromContextID,
		&runtime.Configuration{TCPTargetNetworks: targetNetworks},
	)

	conntrackClient, err := flowtracking.NewClient(context.Background())
	if err != nil {
		return nil
	}
	e.conntrack = conntrackClient

	return e
}
1226030
func NewDefaultLlv() (indicator *Llv, err error) {
	timePeriod := 25
	return NewLlv(timePeriod, gotrade.UseClosePrice)
}
1072026
func NewDefault(cfg config.Provider) *Fs {
	fs := &afero.OsFs{}
	return newFs(fs, cfg)
}