Skip to main content

New-PSFThrottle

SYNOPSIS

Create a throttle object, used to not exceed a certain rate of executions per time interval.

SYNTAX

New-PSFThrottle [-Interval] <TimeSpanParameter> [-Limit] <Int32> [[-ExtraLimits] <Hashtable>]
[<CommonParameters>]

DESCRIPTION

Create a throttle object, used to not exceed a certain rate of executions per time interval. Use this to limit the rate at which you contact throttled APIs / Service Connections.

The returnd object has a GetSlot() method, which will return immediately if slots are available. If none are, it will wait to return until there are.

This object is threadsafe and can be used from multiple runspaces. However, it is not guaranteed to be 100% precise with concurrent access, possibly allowing (slight) overbooking.

EXAMPLES

EXAMPLE 1

New-PSFThrottle -Interval 1m -Limit 60

Generates a throttle object that will allow 60 slots/executions every minute.

EXAMPLE 2

New-PSFThrottle -Interval 1m -Limit 60 -ExtraLimits @{ '1h' = 600 }

Generates a throttle object that will allow 60 slots/executions every minute and 600 every hour.

PARAMETERS

-Interval

The time range during which we measure slot/execution limits. Can be either a timespan or a human-friendly notation such as "10m" for 10 minutes or "1h" for one hour.

Type: TimeSpanParameter
Parameter Sets: (All)
Aliases:

Required: True
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Limit

The number of valid executions within the specified interval.

Type: Int32
Parameter Sets: (All)
Aliases:

Required: True
Position: 2
Default value: 0
Accept pipeline input: False
Accept wildcard characters: False

-ExtraLimits

Additional Interval/Limit pairs to throttle over at the same time. This allows logic such as "Not more than 10 per minute and 100 per hour". The keys of the hashtable are the interval (same type as the Interval parameter), the values the limit (int)

Type: Hashtable
Parameter Sets: (All)
Aliases:

Required: False
Position: 3
Default value: @{}
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

OUTPUTS

NOTES