Skip to content
Snippets Groups Projects
Commit 7b84e672 authored by Luca Moser's avatar Luca Moser Committed by Levente Pap
Browse files

print DBStats() func ints

parent caaf3c10
Branches
No related tags found
No related merge requests found
...@@ -2,6 +2,7 @@ package tangle ...@@ -2,6 +2,7 @@ package tangle
import ( import (
"container/list" "container/list"
"fmt"
"runtime" "runtime"
"time" "time"
...@@ -57,6 +58,8 @@ func New(store kvstore.KVStore) (result *Tangle) { ...@@ -57,6 +58,8 @@ func New(store kvstore.KVStore) (result *Tangle) {
Events: *newEvents(), Events: *newEvents(),
} }
result.DBStats()
result.solidifierWorkerPool.Tune(runtime.GOMAXPROCS(0)) result.solidifierWorkerPool.Tune(runtime.GOMAXPROCS(0))
return return
} }
...@@ -111,6 +114,9 @@ func (tangle *Tangle) Shutdown() *Tangle { ...@@ -111,6 +114,9 @@ func (tangle *Tangle) Shutdown() *Tangle {
tangle.solidifierWorkerPool.ShutdownGracefully() tangle.solidifierWorkerPool.ShutdownGracefully()
tangle.messageStorage.Shutdown() tangle.messageStorage.Shutdown()
// Prints the number of messages in messageMetadataStorage before shutting it down (to console).
// TODO: get rid of console printing
tangle.DBStats()
tangle.messageMetadataStorage.Shutdown() tangle.messageMetadataStorage.Shutdown()
tangle.approverStorage.Shutdown() tangle.approverStorage.Shutdown()
tangle.missingMessageStorage.Shutdown() tangle.missingMessageStorage.Shutdown()
...@@ -138,7 +144,10 @@ func (tangle *Tangle) Prune() error { ...@@ -138,7 +144,10 @@ func (tangle *Tangle) Prune() error {
// DBStats returns the number of solid messages and total number of messages in the database, furthermore the average time it takes to solidify messages. // DBStats returns the number of solid messages and total number of messages in the database, furthermore the average time it takes to solidify messages.
func (tangle *Tangle) DBStats() (solidCount int, messageCount int, avgSolidificationTime float64) { func (tangle *Tangle) DBStats() (solidCount int, messageCount int, avgSolidificationTime float64) {
var sumSolidificationTime time.Duration var sumSolidificationTime time.Duration
var iterations int
// TODO: iterating over a huge database doesn't seem to be efficient...
tangle.messageMetadataStorage.ForEach(func(key []byte, cachedObject objectstorage.CachedObject) bool { tangle.messageMetadataStorage.ForEach(func(key []byte, cachedObject objectstorage.CachedObject) bool {
iterations++
cachedObject.Consume(func(object objectstorage.StorableObject) { cachedObject.Consume(func(object objectstorage.StorableObject) {
msgMetaData := object.(*MessageMetadata) msgMetaData := object.(*MessageMetadata)
messageCount++ messageCount++
...@@ -151,6 +160,8 @@ func (tangle *Tangle) DBStats() (solidCount int, messageCount int, avgSolidifica ...@@ -151,6 +160,8 @@ func (tangle *Tangle) DBStats() (solidCount int, messageCount int, avgSolidifica
return true return true
}) })
avgSolidificationTime = float64(sumSolidificationTime.Milliseconds()) / float64(solidCount) avgSolidificationTime = float64(sumSolidificationTime.Milliseconds()) / float64(solidCount)
// TODO: get rid of console printing
fmt.Println("solid", solidCount, "message", messageCount, "iterations", iterations)
return return
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment