From 37f531651c573c6fefb285d57297da8031f3b5df Mon Sep 17 00:00:00 2001
From: Hans Moog <hm@mkjc.net>
Date: Tue, 16 Jul 2019 14:05:06 +0200
Subject: [PATCH] Refactor: adjusted worker sizes
---
packages/curl/batch_hasher.go | 2 +-
packages/curl/batch_hasher_test.go | 53 ++++++++++++++++++-
.../transactionspammer/transactionspammer.go | 48 ++++++-----------
plugins/tangle/solidifier.go | 6 ++-
4 files changed, 72 insertions(+), 37 deletions(-)
diff --git a/packages/curl/batch_hasher.go b/packages/curl/batch_hasher.go
index ba174808..51d63f20 100644
--- a/packages/curl/batch_hasher.go
+++ b/packages/curl/batch_hasher.go
@@ -20,7 +20,7 @@ func NewBatchHasher(hashLength int, rounds int) (result *BatchHasher) {
rounds: rounds,
}
- result.workerPool = batchworkerpool.New(result.processHashes, batchworkerpool.BatchSize(strconv.IntSize))
+ result.workerPool = batchworkerpool.New(result.processHashes, batchworkerpool.BatchSize(strconv.IntSize), batchworkerpool.WorkerCount(100), batchworkerpool.QueueSize(500000))
result.workerPool.Start()
return
diff --git a/packages/curl/batch_hasher_test.go b/packages/curl/batch_hasher_test.go
index 009cc6bf..c7672733 100644
--- a/packages/curl/batch_hasher_test.go
+++ b/packages/curl/batch_hasher_test.go
@@ -5,11 +5,62 @@ import (
"testing"
"github.com/iotaledger/iota.go/trinary"
+ "golang.org/x/crypto/blake2b"
+ "golang.org/x/crypto/ed25519"
)
+type zeroReader struct{}
+
+func (zeroReader) Read(buf []byte) (int, error) {
+ for i := range buf {
+ buf[i] = 0
+ }
+ return len(buf), nil
+}
+
+func BenchmarkEd25519(b *testing.B) {
+ var zero zeroReader
+ public, private, _ := ed25519.GenerateKey(zero)
+
+ message := make([]byte, 75)
+ sig := ed25519.Sign(private, message)
+
+ b.ResetTimer()
+
+ var wg sync.WaitGroup
+ for i := 0; i < b.N; i++ {
+ wg.Add(1)
+
+ go func() {
+ if !ed25519.Verify(public, message, sig) {
+ panic("valid signature rejected")
+ }
+
+ wg.Done()
+ }()
+ }
+ wg.Wait()
+}
+
+func BenchmarkBlake2b(b *testing.B) {
+ data := make([]byte, 750)
+
+ var wg sync.WaitGroup
+ for i := 0; i < b.N; i++ {
+ wg.Add(1)
+
+ go func() {
+ blake2b.Sum256(data)
+
+ wg.Done()
+ }()
+ }
+ wg.Wait()
+}
+
func BenchmarkBatchHasher_Hash(b *testing.B) {
batchHasher := NewBatchHasher(243, 81)
- tritsToHash := trinary.MustTrytesToTrits(trinary.Trytes("A999999FF"))
+ tritsToHash := make(trinary.Trits, 7500)
b.ResetTimer()
diff --git a/packages/transactionspammer/transactionspammer.go b/packages/transactionspammer/transactionspammer.go
index 9b9fe4a3..80387272 100644
--- a/packages/transactionspammer/transactionspammer.go
+++ b/packages/transactionspammer/transactionspammer.go
@@ -4,9 +4,10 @@ import (
"sync"
"time"
+ "github.com/iotaledger/goshimmer/plugins/gossip"
+
"github.com/iotaledger/goshimmer/packages/daemon"
"github.com/iotaledger/goshimmer/packages/model/value_transaction"
- "github.com/iotaledger/goshimmer/plugins/gossip"
"github.com/iotaledger/goshimmer/plugins/tipselection"
)
@@ -18,8 +19,6 @@ var shutdownSignal chan int
var sentCounter = uint(0)
-var totalSentCounter = uint(0)
-
func Start(tps uint) {
startMutex.Lock()
@@ -30,6 +29,7 @@ func Start(tps uint) {
daemon.BackgroundWorker("Transaction Spammer", func() {
for {
start := time.Now()
+ totalSentCounter := int64(0)
for {
select {
@@ -40,18 +40,25 @@ func Start(tps uint) {
return
default:
- for _, bundleTransaction := range GenerateBundle(3) {
- gossip.Events.ReceiveTransaction.Trigger(bundleTransaction.MetaTransaction)
- }
+ sentCounter++
+ totalSentCounter++
+
+ tx := value_transaction.New()
+ tx.SetValue(totalSentCounter)
+ tx.SetBranchTransactionHash(tipselection.GetRandomTip())
+ tx.SetTrunkTransactionHash(tipselection.GetRandomTip())
+
+ gossip.Events.ReceiveTransaction.Trigger(tx.MetaTransaction)
if sentCounter >= tps {
duration := time.Since(start)
+
if duration < time.Second {
time.Sleep(time.Second - duration)
-
- start = time.Now()
}
+ start = time.Now()
+
sentCounter = 0
}
}
@@ -77,28 +84,3 @@ func Stop() {
startMutex.Unlock()
}
-
-func GenerateBundle(bundleLength int) (result []*value_transaction.ValueTransaction) {
- result = make([]*value_transaction.ValueTransaction, bundleLength)
-
- branch := tipselection.GetRandomTip()
- trunk := tipselection.GetRandomTip()
-
- for i := 0; i < bundleLength; i++ {
- sentCounter++
- totalSentCounter++
-
- tx := value_transaction.New()
- tx.SetTail(i == 0)
- tx.SetHead(i == bundleLength-1)
- tx.SetTimestamp(totalSentCounter)
- tx.SetBranchTransactionHash(branch)
- tx.SetTrunkTransactionHash(trunk)
-
- result[i] = tx
-
- trunk = tx.GetHash()
- }
-
- return result
-}
diff --git a/plugins/tangle/solidifier.go b/plugins/tangle/solidifier.go
index c7ed648b..71494b86 100644
--- a/plugins/tangle/solidifier.go
+++ b/plugins/tangle/solidifier.go
@@ -21,7 +21,9 @@ var workerPool *workerpool.WorkerPool
func configureSolidifier(plugin *node.Plugin) {
workerPool = workerpool.New(func(task workerpool.Task) {
processMetaTransaction(plugin, task.Param(0).(*meta_transaction.MetaTransaction))
- }, workerpool.WorkerCount(WORKER_COUNT), workerpool.QueueSize(2*WORKER_COUNT))
+
+ task.Return(nil)
+ }, workerpool.WorkerCount(WORKER_COUNT), workerpool.QueueSize(10000))
gossip.Events.ReceiveTransaction.Attach(events.NewClosure(func(rawTransaction *meta_transaction.MetaTransaction) {
workerPool.Submit(rawTransaction)
@@ -186,4 +188,4 @@ func processTransaction(plugin *node.Plugin, transaction *value_transaction.Valu
}
}
-const WORKER_COUNT = 400
+const WORKER_COUNT = 5000
--
GitLab