aboutsummaryrefslogtreecommitdiffstats
path: root/dex/handler.go
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2018-11-20 17:46:17 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-12 17:27:18 +0800
commite9532ec6357747676433acfd5f6240dada406f87 (patch)
tree126984ec350944f71a61417a4ef944a3a0e6fc00 /dex/handler.go
parentd577ca5622381f3ecad9383301d003e1519d6aad (diff)
downloadgo-tangerine-e9532ec6357747676433acfd5f6240dada406f87.tar
go-tangerine-e9532ec6357747676433acfd5f6240dada406f87.tar.gz
go-tangerine-e9532ec6357747676433acfd5f6240dada406f87.tar.bz2
go-tangerine-e9532ec6357747676433acfd5f6240dada406f87.tar.lz
go-tangerine-e9532ec6357747676433acfd5f6240dada406f87.tar.xz
go-tangerine-e9532ec6357747676433acfd5f6240dada406f87.tar.zst
go-tangerine-e9532ec6357747676433acfd5f6240dada406f87.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.go17
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():