tps

package
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2024 License: MIT Imports: 3 Imported by: 0

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

func Transaction(t string, uid string, tpsMax float32) *time.Time

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

type CleanUpCycleRange struct {
	msg.Message
}

CleanUpCycleRange exported

type PenaltyFactorRange added in v0.1.43

type PenaltyFactorRange struct {
	msg.Message
}

PenaltyFactorRange

type PrecisionRange added in v0.1.43

type PrecisionRange struct {
	msg.Message
}

PrecisionRange exported

type TPS

type TPS struct {
	// contains filtered or unexported fields
}

TPS exported

type TPSmap

type TPSmap map[string]map[string]*TPS

TPSmap exported

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL