client

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2020 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StatScaleToTime

func StatScaleToTime(r float64) time.Duration

StatScaleToTime converts a distribution vector index to a response time. The index is represented by a float64 so that linear interpolation can be applied.

func TimeToStatScale

func TimeToStatScale(d time.Duration) float64

TimeToStatScale converts a response time to a distribution vector index. The index is represented by a float64 so that linear interpolation can be applied.

Types

type NodeValueTracker

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

NodeValueTracker collects service value statistics for a specific server node

func (*NodeValueTracker) RtStats

func (nv *NodeValueTracker) RtStats() ResponseTimeStats

RtStats returns the node's own response time distribution statistics

type PrivateClientAPI

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

PrivateClientAPI implements the lespay client side API

func NewPrivateClientAPI

func NewPrivateClientAPI(vt *ValueTracker) *PrivateClientAPI

NewPrivateClientAPI creates a PrivateClientAPI

func (*PrivateClientAPI) Distribution

func (api *PrivateClientAPI) Distribution(nodeStr string, normalized bool) (RtDistribution, error)

Distribution returns a distribution as a series of (X, Y) chart coordinates, where the X axis is the response time in seconds while the Y axis is the amount of service value received with a response time close to the X coordinate. The distribution is optionally normalized to a sum of 1. If nodeStr == "" then the global distribution is returned, otherwise the individual distribution of the specified server node.

func (*PrivateClientAPI) RequestStats

func (api *PrivateClientAPI) RequestStats() []RequestStatsItem

RequestStats returns the current contents of the reference request basket, with request values meaning average per request rather than total.

func (*PrivateClientAPI) Timeout

func (api *PrivateClientAPI) Timeout(nodeStr string, failRate float64) (float64, error)

Timeout suggests a timeout value based on either the global distribution or the distribution of the specified node. The parameter is the desired rate of timeouts assuming a similar distribution in the future. Note that the actual timeout should have a sensible minimum bound so that operating under ideal working conditions for a long time (for example, using a local server with very low response times) will not make it very hard for the system to accommodate longer response times in the future.

func (*PrivateClientAPI) Value

func (api *PrivateClientAPI) Value(nodeStr string, timeout float64) (float64, error)

Value calculates the total service value provided either globally or by the specified server node, using a weight function based on the given timeout.

type RequestInfo

type RequestInfo struct {
	// Name identifies the request type and is used for re-mapping the service vector if necessary
	Name string
	// InitAmount and InitValue are used to initialize the reference basket
	InitAmount, InitValue float64
}

RequestInfo is an initializer structure for the service vector.

type RequestStatsItem

type RequestStatsItem struct {
	Name                string
	ReqAmount, ReqValue float64
}

type ResponseTimeStats

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

ResponseTimeStats is the response time distribution of a set of answered requests, weighted with request value, either served by a single server or aggregated for multiple servers. It it a fixed length (timeStatLength) distribution vector with linear interpolation. The X axis (the time values) are not linear, they should be transformed with TimeToStatScale and StatScaleToTime.

func (*ResponseTimeStats) Add

func (rt *ResponseTimeStats) Add(respTime time.Duration, weight float64, expFactor utils.ExpirationFactor)

Add adds a new response time with the given weight to the distribution.

func (*ResponseTimeStats) AddStats

func (rt *ResponseTimeStats) AddStats(s *ResponseTimeStats)

AddStats adds the given ResponseTimeStats to the current one.

func (*ResponseTimeStats) DecodeRLP

func (rt *ResponseTimeStats) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder

func (ResponseTimeStats) Distribution

func (rt ResponseTimeStats) Distribution(normalized bool, expFactor utils.ExpirationFactor) (res RtDistribution)

Distribution returns a RtDistribution, optionally normalized to a sum of 1.

func (*ResponseTimeStats) EncodeRLP

func (rt *ResponseTimeStats) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder

func (*ResponseTimeStats) SubStats

func (rt *ResponseTimeStats) SubStats(s *ResponseTimeStats)

SubStats subtracts the given ResponseTimeStats from the current one.

func (ResponseTimeStats) Timeout

func (rt ResponseTimeStats) Timeout(failRatio float64) time.Duration

Timeout suggests a timeout value based on the previous distribution. The parameter is the desired rate of timeouts assuming a similar distribution in the future. Note that the actual timeout should have a sensible minimum bound so that operating under ideal working conditions for a long time (for example, using a local server with very low response times) will not make it very hard for the system to accommodate longer response times in the future.

func (ResponseTimeStats) Value

Value calculates the total service value based on the given distribution, using the specified weight function.

type ResponseTimeWeights

type ResponseTimeWeights [timeStatLength]float64

ResponseTimeStats is the response time distribution of a set of answered requests, weighted with request value, either served by a single server or aggregated for multiple servers. It it a fixed length (timeStatLength) distribution vector with linear interpolation. The X axis (the time values) are not linear, they should be transformed with TimeToStatScale and StatScaleToTime.

func TimeoutWeights

func TimeoutWeights(timeout time.Duration) (res ResponseTimeWeights)

TimeoutWeights calculates the weight function used for calculating service value based on the response time distribution of the received service. It is based on the request timeout value of the system. It consists of a half cosine function starting with 1, crossing zero at timeout and reaching -1 at 2*timeout. After 2*timeout the weight is constant -1.

type RtDistribution

type RtDistribution [timeStatLength][2]float64

RtDistribution represents a distribution as a series of (X, Y) chart coordinates, where the X axis is the response time in seconds while the Y axis is the amount of service value received with a response time close to the X coordinate.

type ServedRequest

type ServedRequest struct {
	ReqType, Amount uint32
}

type ValueTracker

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

ValueTracker coordinates service value calculation for individual servers and updates global statistics

func NewValueTracker

func NewValueTracker(db ethdb.KeyValueStore, clock mclock.Clock, reqInfo []RequestInfo, updatePeriod time.Duration, transferRate, statsExpRate, offlineExpRate float64) *ValueTracker

NewValueTracker creates a new ValueTracker and loads its previously saved state from the database if possible.

func (*ValueTracker) GetNode

func (vt *ValueTracker) GetNode(id enode.ID) *NodeValueTracker

GetNode returns an individual server node's value tracker. If it did not exist before then a new node is created.

func (*ValueTracker) Register

func (vt *ValueTracker) Register(id enode.ID) *NodeValueTracker

Register adds a server node to the value tracker

func (*ValueTracker) RequestStats

func (vt *ValueTracker) RequestStats() []RequestStatsItem

RequestStats returns the current contents of the reference request basket, with request values meaning average per request rather than total.

func (*ValueTracker) RtStats

func (vt *ValueTracker) RtStats() ResponseTimeStats

RtStats returns the global response time distribution statistics

func (*ValueTracker) Served

func (vt *ValueTracker) Served(nv *NodeValueTracker, reqs []ServedRequest, respTime time.Duration)

Served adds a served request to the node's statistics. An actual request may be composed of one or more request types (service vector indices).

func (*ValueTracker) StatsExpirer

func (vt *ValueTracker) StatsExpirer() *utils.Expirer

StatsExpirer returns the statistics expirer so that other values can be expired with the same rate as the service value statistics.

func (*ValueTracker) Stop

func (vt *ValueTracker) Stop()

Stop saves the value tracker's state and each loaded node's individual state and returns after shutting the internal goroutines down.

func (*ValueTracker) TotalServiceValue

func (vt *ValueTracker) TotalServiceValue(nv *NodeValueTracker, weights ResponseTimeWeights) float64

TotalServiceValue returns the total service value provided by the given node (as a function of the weights which are calculated from the request timeout value).

func (*ValueTracker) Unregister

func (vt *ValueTracker) Unregister(id enode.ID)

Unregister removes a server node from the value tracker

func (*ValueTracker) UpdateCosts

func (vt *ValueTracker) UpdateCosts(nv *NodeValueTracker, reqCosts []uint64)

UpdateCosts updates the node value tracker's request cost table

Jump to

Keyboard shortcuts

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