From 8966178702876e4c2423d9877e25c536d99f0ab7 Mon Sep 17 00:00:00 2001 From: CJ Cobb Date: Tue, 5 Oct 2021 18:53:53 -0400 Subject: [PATCH] add upper bound to time spent in fetchLedgerPage --- src/backend/BackendInterface.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/backend/BackendInterface.cpp b/src/backend/BackendInterface.cpp index 84b62f38..da74508f 100644 --- a/src/backend/BackendInterface.cpp +++ b/src/backend/BackendInterface.cpp @@ -196,6 +196,7 @@ BackendInterface::fetchLedgerPage( uint32_t adjustedLimit = std::max(limitHint, std::max(limit, (uint32_t)4)); LedgerPage page; page.cursor = cursor; + long totalTime = 0; do { adjustedLimit = adjustedLimit >= 8192 ? 8192 : adjustedLimit * 2; @@ -207,18 +208,18 @@ BackendInterface::fetchLedgerPage( page.cursor ? ripple::strHex(*page.cursor) : ""; std::string partialCursorStr = partial.cursor ? ripple::strHex(*partial.cursor) : ""; + auto thisTime = + std::chrono::duration_cast(end - start) + .count(); BOOST_LOG_TRIVIAL(debug) << __func__ << " " << std::to_string(ledgerSequence) << " " << std::to_string(adjustedLimit) << " " << pageCursorStr << " - " - << partialCursorStr << " - time = " - << std::to_string( - std::chrono::duration_cast( - end - start) - .count()); + << partialCursorStr << " - time = " << std::to_string(thisTime); + totalTime += thisTime; page.objects.insert( page.objects.end(), partial.objects.begin(), partial.objects.end()); page.cursor = partial.cursor; - } while (page.objects.size() < limit && page.cursor); + } while (page.objects.size() < limit && page.cursor && totalTime < 5000); if (incomplete) { auto rng = fetchLedgerRange();