gossip sync: sync with random 20 peers per cycle instead of all peers
This commit is contained in:
parent
38d594ac50
commit
4b98779122
3 changed files with 15 additions and 2 deletions
|
|
@ -54,9 +54,14 @@ class ForumDB:
|
|||
"CREATE TABLE IF NOT EXISTS synced_instances ("
|
||||
" instance_hash TEXT PRIMARY KEY,"
|
||||
" name TEXT DEFAULT '',"
|
||||
" last_sync TEXT DEFAULT ''"
|
||||
" last_sync TEXT DEFAULT '',"
|
||||
" status TEXT DEFAULT 'active'"
|
||||
")"
|
||||
)
|
||||
try:
|
||||
db.execute("ALTER TABLE synced_instances ADD COLUMN status TEXT DEFAULT 'active'")
|
||||
except Exception:
|
||||
pass
|
||||
db.execute(
|
||||
"CREATE TABLE IF NOT EXISTS settings ("
|
||||
" key TEXT PRIMARY KEY,"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import json
|
||||
import random
|
||||
import threading
|
||||
import time
|
||||
import RNS
|
||||
|
|
@ -6,6 +7,7 @@ import RNS
|
|||
FORUM_APP = "tinyweb-forum"
|
||||
SYNC_INTERVAL = 300 # 5 minutes
|
||||
REQUEST_TIMEOUT = 60
|
||||
GOSSIP_FANOUT = 20 # random peers to sync per cycle
|
||||
|
||||
|
||||
class _ForumAnnounceHandler:
|
||||
|
|
@ -90,7 +92,11 @@ class ForumSync:
|
|||
while self._running:
|
||||
try:
|
||||
instances = self.fdb.get_synced_instances()
|
||||
for inst in instances:
|
||||
# Gossip: sync with random subset for scaling
|
||||
# If <= GOSSIP_FANOUT peers, sync with all (current behavior)
|
||||
# If more, sync with random FANOUT per cycle — content spreads epidemically
|
||||
random.shuffle(instances)
|
||||
for inst in instances[:GOSSIP_FANOUT]:
|
||||
if not self._running:
|
||||
break
|
||||
try:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue