Skip to content

Commit c097924

Browse files
committed
chore: fixeS
Signed-off-by: Roman Gershman <[email protected]>
1 parent 271ec8d commit c097924

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/server/snapshot.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ void SliceSnapshot::IterateBucketsFb(bool send_full_sync_cut) {
154154
stats_.keys_total += db_slice_->DbSize(db_indx);
155155
}
156156

157+
const uint64_t kCyclesPerYield = base::CycleClock::Frequency() >> 16; // ~15usec.
158+
157159
for (DbIndex db_indx = 0; db_indx < db_array_.size(); ++db_indx) {
158160
if (!cntx_->IsRunning())
159161
return;
@@ -164,6 +166,7 @@ void SliceSnapshot::IterateBucketsFb(bool send_full_sync_cut) {
164166
PrimeTable* pt = &db_array_[db_indx]->prime;
165167
VLOG(1) << "Start traversing " << pt->size() << " items for index " << db_indx;
166168

169+
uint64_t start_cycles = base::CycleClock::Now();
167170
do {
168171
if (!cntx_->IsRunning()) {
169172
return;
@@ -172,7 +175,11 @@ void SliceSnapshot::IterateBucketsFb(bool send_full_sync_cut) {
172175
PrimeTable::Cursor next = pt->TraverseBuckets(
173176
cursor, [this, &db_indx](auto it) { return BucketSaveCb(db_indx, it); });
174177
cursor = next;
175-
ThisFiber::Yield();
178+
uint64_t now = base::CycleClock::Now();
179+
if (now > start_cycles + kCyclesPerYield) {
180+
ThisFiber::Yield();
181+
start_cycles = base::CycleClock::Now();
182+
}
176183

177184
PushSerialized(false);
178185
} while (cursor);

0 commit comments

Comments
 (0)