From e9532ec6357747676433acfd5f6240dada406f87 Mon Sep 17 00:00:00 2001 From: Jimmy Hu Date: Tue, 20 Nov 2018 17:46:17 +0800 Subject: dex: Tx message optimization (#39) * dex: Add a tx queue in broadcast * Modify queue parameter * Priority select all messages except tx --- dex/handler.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'dex/handler.go') 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(): -- cgit