Documentation ¶
Overview ¶
TPS package. TPS is an acronym for Transactions Per Second package. This package allows for TPS control. Users's actual TPS is recalculated on every request and a time penalty is accounted for in case the user's TPS rate is exceeded. Penalties are accumulative, so if a user who is currently voided insists making new requests exceeding her TPS quota, new penalties will add to existing ones. Penalties are stored in-memory in the TPSmap registry. Obsolete penalties are removed from the registry automatically.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Init ¶
func Init() error
Init function initializes TPS control. chcap is the number of request needed to calculate TPS. After a period of a user's inactivity, her TPS control is reset to save server resources. mapcln param sets the time window of inactivity required in order to reset. mapcln starts counting after any TPS related penalty is fulfilled.
func IsEnabled ¶
func IsEnabled() bool
IsEnabled exported. Just by calling Init() once, IsEnabled will return true.
func Transaction ¶
Transaction takes note of the request, recalculates the actual TPS, and returns a datetime if the TPS rate is exceeded. In such case, the user shouldn't be granted access before said datetime. Even if a user is blocked, new request should also be accounted for here, a more distant datetime could be returned.
Types ¶
type CleanUpCycleRange ¶ added in v0.1.43
CleanUpCycleRange exported
type PenaltyFactorRange ¶ added in v0.1.43
PenaltyFactorRange
type PrecisionRange ¶ added in v0.1.43
PrecisionRange exported