Skip to content
Snippets Groups Projects
Commit 37f53165 authored by Hans Moog's avatar Hans Moog
Browse files

Refactor: adjusted worker sizes

parent 3619ae97
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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()
......
......@@ -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
}
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment