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@dexon.org>2019-04-09 13:49:57 +0800
commit176ee2e3f5e61a320e7d5670dd77433f053509ec (patch)
tree68e8779bbd39d2d6c6b564fe6c2f866650e0610c /dex/handler.go
parentcf1259a57233205cfbf6983582bd14b2802a0655 (diff)
downloaddexon-176ee2e3f5e61a320e7d5670dd77433f053509ec.tar
dexon-176ee2e3f5e61a320e7d5670dd77433f053509ec.tar.gz
dexon-176ee2e3f5e61a320e7d5670dd77433f053509ec.tar.bz2
dexon-176ee2e3f5e61a320e7d5670dd77433f053509ec.tar.lz
dexon-176ee2e3f5e61a320e7d5670dd77433f053509ec.tar.xz
dexon-176ee2e3f5e61a320e7d5670dd77433f053509ec.tar.zst
dexon-176ee2e3f5e61a320e7d5670dd77433f053509ec.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():