From 09d336bd0ccd6fd049b38e4deb35c4284492a673 Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Thu, 10 Aug 2017 13:49:43 -0400 Subject: [PATCH] don't block blob_completed on the blob being announced this considerably slows down the rate at which reflector server can receive blobs --- lbrynet/core/BlobManager.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lbrynet/core/BlobManager.py b/lbrynet/core/BlobManager.py index e435d0713..47ad1db61 100644 --- a/lbrynet/core/BlobManager.py +++ b/lbrynet/core/BlobManager.py @@ -3,7 +3,7 @@ import os import time import sqlite3 -from twisted.internet import threads, defer +from twisted.internet import threads, defer, reactor from twisted.enterprise import adbapi from lbrynet.core.HashBlob import BlobFile, BlobFileCreator from lbrynet.core.server.DHTHashAnnouncer import DHTHashSupplier @@ -11,6 +11,7 @@ from lbrynet.core.sqlite_helpers import rerun_if_locked log = logging.getLogger(__name__) + class DiskBlobManager(DHTHashSupplier): """This class stores blobs on the hard disk""" def __init__(self, hash_announcer, blob_dir, db_dir): @@ -25,7 +26,6 @@ class DiskBlobManager(DHTHashSupplier): self.blobs = {} self.blob_hashes_to_delete = {} # {blob_hash: being_deleted (True/False)} - @defer.inlineCallbacks def setup(self): log.info("Starting disk blob manager. blob_dir: %s, db_file: %s", str(self.blob_dir), @@ -58,13 +58,14 @@ class DiskBlobManager(DHTHashSupplier): def _immediate_announce(self, blob_hashes): if self.hash_announcer: return self.hash_announcer.immediate_announce(blob_hashes) + raise Exception("Hash announcer not set") + @defer.inlineCallbacks def blob_completed(self, blob, next_announce_time=None): if next_announce_time is None: next_announce_time = self.get_next_announce_time() - d = self._add_completed_blob(blob.blob_hash, blob.length, next_announce_time) - d.addCallback(lambda _: self._immediate_announce([blob.blob_hash])) - return d + yield self._add_completed_blob(blob.blob_hash, blob.length, next_announce_time) + reactor.callLater(0, self._immediate_announce, [blob.blob_hash]) def completed_blobs(self, blobhashes_to_check): return self._completed_blobs(blobhashes_to_check)