1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-04-29 13:49:28 +08:00
Mainflux.mainflux/vendor/github.com/hailocab/go-hostpool/epsilon_value_calculators.go
Aleksandar Novaković 426f59d392 MF-235 - Add support for storing messages in Cassandra (#321)
* Add Cassandra writer implementation

Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>

* Add cassandra service with version and metrics endpoints

Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>

* Add test for cassandra writer

Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>

* Exclude api.go files from code coverage

Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>

* Add readme file for cassandra writer

Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>

* Add docker compose configuration for cassandra writer

Add README file. Add docker compose configuration.

Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>

* Add gocql as project dependency

Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>

* Fix init script for cassandra in docker-compose

Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>

* Add testifies require subpackage

Signed-off-by: Aleksandar Novakovic <aleksandar.novakovic@mainflux.com>
2018-06-08 14:25:55 +02:00

41 lines
1.5 KiB
Go

package hostpool
// --- Value Calculators -----------------
import (
"math"
)
// --- Definitions -----------------------
// Structs implementing this interface are used to convert the average response time for a host
// into a score that can be used to weight hosts in the epsilon greedy hostpool. Lower response
// times should yield higher scores (we want to select the faster hosts more often) The default
// LinearEpsilonValueCalculator just uses the reciprocal of the response time. In practice, any
// decreasing function from the positive reals to the positive reals should work.
type EpsilonValueCalculator interface {
CalcValueFromAvgResponseTime(float64) float64
}
type LinearEpsilonValueCalculator struct{}
type LogEpsilonValueCalculator struct{ LinearEpsilonValueCalculator }
type PolynomialEpsilonValueCalculator struct {
LinearEpsilonValueCalculator
Exp float64 // the exponent to which we will raise the value to reweight
}
// -------- Methods -----------------------
func (c *LinearEpsilonValueCalculator) CalcValueFromAvgResponseTime(v float64) float64 {
return 1.0 / v
}
func (c *LogEpsilonValueCalculator) CalcValueFromAvgResponseTime(v float64) float64 {
// we need to add 1 to v so that this will be defined on all positive floats
return c.LinearEpsilonValueCalculator.CalcValueFromAvgResponseTime(math.Log(v + 1.0))
}
func (c *PolynomialEpsilonValueCalculator) CalcValueFromAvgResponseTime(v float64) float64 {
return c.LinearEpsilonValueCalculator.CalcValueFromAvgResponseTime(math.Pow(v, c.Exp))
}