1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-04-27 13:48:49 +08:00
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

63 lines
1.4 KiB
Go

package hostpool
import (
"time"
)
// --- hostEntry - this is due to get upgraded
type hostEntry struct {
host string
nextRetry time.Time
retryCount int16
retryDelay time.Duration
dead bool
epsilonCounts []int64
epsilonValues []int64
epsilonIndex int
epsilonValue float64
epsilonPercentage float64
}
func (h *hostEntry) canTryHost(now time.Time) bool {
if !h.dead {
return true
}
if h.nextRetry.Before(now) {
return true
}
return false
}
func (h *hostEntry) willRetryHost(maxRetryInterval time.Duration) {
h.retryCount += 1
newDelay := h.retryDelay * 2
if newDelay < maxRetryInterval {
h.retryDelay = newDelay
} else {
h.retryDelay = maxRetryInterval
}
h.nextRetry = time.Now().Add(h.retryDelay)
}
func (h *hostEntry) getWeightedAverageResponseTime() float64 {
var value float64
var lastValue float64
// start at 1 so we start with the oldest entry
for i := 1; i <= epsilonBuckets; i += 1 {
pos := (h.epsilonIndex + i) % epsilonBuckets
bucketCount := h.epsilonCounts[pos]
// Changing the line below to what I think it should be to get the weights right
weight := float64(i) / float64(epsilonBuckets)
if bucketCount > 0 {
currentValue := float64(h.epsilonValues[pos]) / float64(bucketCount)
value += currentValue * weight
lastValue = currentValue
} else {
value += lastValue * weight
}
}
return value
}