diff --git a/db/db_impl.cc b/db/db_impl.cc index e84817b9b2c32267a192cbd39c5bec77190665e0..0cafc269c8fd901d997f875347895b98b9aba5f8 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -3155,7 +3155,7 @@ void DBImpl::BuildBatchGroup(Writer** last_writer, // The goal of this formula is to gradually increase the rate at which writes // are slowed. We also tried linear delay (r * 1000), but it seemed to do // slightly worse. There is no other particular reason for choosing quadratic. -uint64_t DBImpl::SlowdownAmount(int n, int top, int bottom) { +uint64_t DBImpl::SlowdownAmount(int n, double bottom, double top) { uint64_t delay; if (n >= top) { delay = 1000; @@ -3167,10 +3167,10 @@ uint64_t DBImpl::SlowdownAmount(int n, int top, int bottom) { // If we are here, we know that: // level0_start_slowdown <= n < level0_slowdown // since the previous two conditions are false. - float how_much = - (float) (n - bottom) / + double how_much = + (double) (n - bottom) / (top - bottom); - delay = how_much * how_much * 1000; + delay = std::max(how_much * how_much * 1000, 100.0); } assert(delay <= 1000); return delay; diff --git a/db/db_impl.h b/db/db_impl.h index 214affac7c4374a21da3881142c9037dc25166b4..3eebaf4a78cf48482079bbb1365b8ddc0669b211 100644 --- a/db/db_impl.h +++ b/db/db_impl.h @@ -293,7 +293,7 @@ class DBImpl : public DB { Status WriteLevel0Table(std::vector &mems, VersionEdit* edit, uint64_t* filenumber); - uint64_t SlowdownAmount(int n, int top, int bottom); + uint64_t SlowdownAmount(int n, double bottom, double top); // MakeRoomForWrite will return superversion_to_free through an arugment, // which the caller needs to delete. We do it because caller can delete // the superversion outside of mutex