diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2018-11-20 17:46:17 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-04-09 21:32:53 +0800 |
commit | 404496ca9ac1974fff5c4e89f4fee146da7bac33 (patch) | |
tree | f212f76b50393506b4f95ee8b679989b22419c4e /dex/handler.go | |
parent | 4802a4126fecf3971858b028f4d343fa8a6973d4 (diff) | |
download | dexon-404496ca9ac1974fff5c4e89f4fee146da7bac33.tar.gz dexon-404496ca9ac1974fff5c4e89f4fee146da7bac33.tar.zst dexon-404496ca9ac1974fff5c4e89f4fee146da7bac33.zip |
dex: Tx message optimization (#39)
* dex: Add a tx queue in broadcast
* Modify queue parameter
* Priority select all messages except tx
Diffstat (limited to 'dex/handler.go')
-rw-r--r-- | dex/handler.go | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/dex/handler.go b/dex/handler.go index 21322e4e0..3c8d25ea3 100644 --- a/dex/handler.go +++ b/dex/handler.go @@ -1037,10 +1037,25 @@ func (pm *ProtocolManager) BroadcastPullVotes( } func (pm *ProtocolManager) txBroadcastLoop() { + queueSizeMax := common.StorageSize(100 * 1024) // 100 KB + currentSize := common.StorageSize(0) + txs := make(types.Transactions, 0) for { select { + case <-time.After(500 * time.Millisecond): + pm.BroadcastTxs(txs) + txs = txs[:0] + currentSize = 0 case event := <-pm.txsCh: - pm.BroadcastTxs(event.Txs) + txs = append(txs, event.Txs...) + for _, tx := range event.Txs { + currentSize += tx.Size() + } + if currentSize >= queueSizeMax { + pm.BroadcastTxs(txs) + txs = txs[:0] + currentSize = 0 + } // Err() channel will be closed when unsubscribing. case <-pm.txsSub.Err(): |