Skip to content

Commit 09b8e71

Browse files
committed
improve slow backup creation progress logging
1 parent 1b6e6b8 commit 09b8e71

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

prime_backup/action/create_backup_action.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class _ScanResult:
5858

5959
@property
6060
def all_file_size_sum(self) -> int:
61-
return sum(entry.stat.st_size for entry in self.all_files)
61+
return sum(entry.stat.st_size for entry in self.all_files if entry.is_file())
6262

6363

6464
@dataclasses.dataclass(frozen=True)
@@ -452,7 +452,7 @@ def is_stat_unchanged_file(self, src_path: Path) -> bool: # real-world path
452452
files = blob_allocator.schedule_loop([
453453
self.__create_file(session, blob_allocator, file_entry.path)
454454
for file_entry in scan_result.all_files
455-
])
455+
], scan_result.all_file_size_sum)
456456

457457
with self.__time_costs.measure_time_cost(CreateBackupTimeCostKey.stage_finalize):
458458
BackupFinalizer(session).finalize_files_and_backup(backup, files)

prime_backup/action/helpers/blob_allocator.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from prime_backup.db import schema
1919
from prime_backup.db.session import DbSession
2020
from prime_backup.types.chunk_method import ChunkMethod
21+
from prime_backup.types.units import ByteCount
2122
from prime_backup.utils import blob_utils, file_utils, misc_utils, pack_utils
2223
from prime_backup.utils.time_cost_stats import TimeCostStats
2324

@@ -27,6 +28,7 @@
2728

2829
_BLOB_FILE_CHANGED_RETRY_COUNT = 3
2930
_FetchCallback = Callable[[], None]
31+
_MIB = 1024 * 1024
3032

3133

3234
class BatchFetcherBase(ABC):
@@ -270,17 +272,19 @@ def init_blob_store(self):
270272
self.__ctx.blob_store_st = bs_path.stat()
271273
self.__ctx.blob_store_in_cow_fs = file_utils.does_fs_support_cow(bs_path)
272274

273-
def schedule_loop(self, gen_list: List[BlobLookupRoutine[schema.File]]) -> List[schema.File]:
275+
def schedule_loop(self, gen_list: List[BlobLookupRoutine[schema.File]], total_blob_raw_size: int) -> List[schema.File]:
274276
files: List[schema.File] = []
275277

276278
schedule_queue: Deque[BlobLookupRoutine[schema.File]] = collections.deque()
277279
for gen in gen_list:
278280
schedule_queue.append(gen)
279281
gen_count = len(schedule_queue)
280282
done_count = 0
283+
done_blob_raw_size = 0
281284

282285
start_time = time.time()
283286
last_report_time = start_time
287+
last_report_blob_raw_size = 0
284288

285289
while len(schedule_queue) > 0:
286290
scheduled = schedule_queue.popleft()
@@ -291,11 +295,23 @@ def callback(g: BlobLookupRoutine[schema.File] = scheduled):
291295
query_req = scheduled.send(None)
292296
self.__batch_lookup_manager.query(query_req, callback)
293297
except StopIteration as e:
294-
files.append(misc_utils.ensure_type(e.value, schema.File))
298+
file = misc_utils.ensure_type(e.value, schema.File)
299+
files.append(file)
295300
done_count += 1
301+
done_blob_raw_size += file.blob_raw_size or 0
296302
if (now := time.time()) - last_report_time > 30:
297-
self.logger.info('Backup file creation progress: {} / {} done, elapsed time {:.2f}s'.format(done_count, gen_count, now - start_time))
303+
time_delta = now - last_report_time
304+
size_delta = done_blob_raw_size - last_report_blob_raw_size
305+
self.logger.info(
306+
'Backup file creation progress: {} / {} done, size {} / {}, speed {:.2f}MiB/s, elapsed time {:.2f}s'.format(
307+
done_count, gen_count,
308+
ByteCount(done_blob_raw_size).auto_str(), ByteCount(total_blob_raw_size).auto_str(),
309+
size_delta / _MIB / time_delta if time_delta > 0 else 0,
310+
now - start_time,
311+
)
312+
)
298313
last_report_time = now
314+
last_report_blob_raw_size = done_blob_raw_size
299315
except SourceFileNotFoundWrapper as e:
300316
if self.__should_skip_missing_source_file(e.file_path):
301317
self.logger.warning('Backup source file {!r} not found, suppressed and skipped by config'.format(str(e.file_path)))

0 commit comments

Comments
 (0)