Skip to content

Commit

Permalink
#50 Perfomance Degradation: Heavy Disk Usage
Browse files Browse the repository at this point in the history
  • Loading branch information
hleb-albau authored and arturalbov committed Oct 22, 2018
1 parent e6ba7e9 commit 6b2fd57
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
1 change: 0 additions & 1 deletion cosmos/poc/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ func (app *CyberdApp) EndBlocker(ctx sdk.Context, _ abci.RequestEndBlock) abci.R
hash := sha256.Sum256(rankAsBytes)
app.latestRankHash = hash[:]
app.memStorage.UpdateRank(newRank)
app.persistStorages.Rank.StoreFullRank(ctx, newRank)
app.mainStorage.StoreAppHash(ctx, hash[:])
return abci.ResponseEndBlock{}
}
Expand Down
35 changes: 22 additions & 13 deletions cosmos/poc/app/rank/calculate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@ package rank
import (
. "github.com/cybercongress/cyberd/cosmos/poc/app/storage"
"math"
"sync"
)

const (
d = 0.85
tolerance = 0.1
)

func CalculateRank(data *InMemoryStorage) []float64 {
func CalculateRank(data *InMemoryStorage) ([]float64, int) {

size := data.GetCidsCount()

if size == 0 {
return []float64{}
return []float64{}, 0
}
inverseOfSize := 1.0 / float64(size)

prevrank := data.GetRank()
zeros := make([]float64, size-len(prevrank))
prevrank = append(prevrank, zeros...)
prevrank := make([]float64, size)

tOverSize := (1.0 - d) / float64(size)
danglingNodes := calculateDanglingNodes(data)
Expand All @@ -32,14 +31,16 @@ func CalculateRank(data *InMemoryStorage) []float64 {

change := 2.0

steps := 0
var rank []float64
for change > tolerance {
rank = step(tOverSize, prevrank, danglingNodes, data)
change = calculateChange(prevrank, rank)
prevrank = rank
steps++
}

return rank
return rank, steps
}

func calculateDanglingNodes(data *InMemoryStorage) []int64 {
Expand All @@ -66,17 +67,25 @@ func step(tOverSize float64, prevrank []float64, danglingNodes []int64, data *In
innerProductOverSize := innerProduct / float64(len(prevrank))
rank := make([]float64, len(prevrank))

var wg sync.WaitGroup
wg.Add(len(data.GetInLinks()))

for i, inLinksForI := range data.GetInLinks() {
ksum := 0.0

for j := range inLinksForI {
linkStake := float64(data.GetOverallLinkStake(CidNumber(j), CidNumber(i)))
jCidOutStake := float64(data.GetOverallOutLinksStake(CidNumber(j)))
ksum += prevrank[j] * (linkStake / jCidOutStake)
}
go func(cid CidNumber, inLinks CidLinks) {
defer wg.Done()
ksum := 0.0

for j := range inLinks {
linkStake := float64(data.GetOverallLinkStake(CidNumber(j), CidNumber(cid)))
jCidOutStake := float64(data.GetOverallOutLinksStake(CidNumber(j)))
ksum += prevrank[j] * (linkStake / jCidOutStake)
}

rank[i] = d*(ksum+innerProductOverSize) + tOverSize
rank[cid] = d*(ksum+innerProductOverSize) + tOverSize
}(i, inLinksForI)
}
wg.Wait()
return rank
}

Expand Down
1 change: 0 additions & 1 deletion cosmos/poc/app/storage/inmemory.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ func (s *InMemoryStorage) Load(ctx sdk.Context, ps CyberdPersistentStorages, am
s.cidsByNumberIndex = cidsByNumber
s.cidsCount = uint64(len(cidsIndexes))
s.userStake = GetAllAccountsStakes(ctx, am)
s.UpdateRank(ps.Rank.GetFullRank(ctx))
}

// Also returns bool flag, whether index exists
Expand Down

0 comments on commit 6b2fd57

Please sign in to comment.