Explorar o código

Merge pull request #169 from vector-im/hs/add-randomness-to-sync

Add some jitter to the sync loop
Sumner Evans %!s(int64=3) %!d(string=hai) anos
pai
achega
b8545e41dd
Modificáronse 1 ficheiros con 4 adicións e 0 borrados
  1. 4 0
      mautrix_signal/__main__.py

+ 4 - 0
mautrix_signal/__main__.py

@@ -14,6 +14,7 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 from typing import Dict, Any
+from random import uniform
 import asyncio
 import logging
 
@@ -33,6 +34,7 @@ from .puppet import Puppet
 from .web import ProvisioningAPI
 from . import commands
 
+SYNC_JITTER = 10
 
 class SignalBridge(Bridge):
     module = "mautrix_signal"
@@ -96,6 +98,8 @@ class SignalBridge(Bridge):
                 return
             log.info("Executing periodic syncs")
             for user in User.by_username.values():
+                # Add some randomness to the sync to avoid a thundering herd
+                await asyncio.sleep(uniform(0, SYNC_JITTER))
                 try:
                     await user.sync()
                 except asyncio.CancelledError: