diff --git a/src/expire.cpp b/src/expire.cpp index 5d257428d..ba0b99284 100644 --- a/src/expire.cpp +++ b/src/expire.cpp @@ -260,6 +260,7 @@ void activeExpireCycle(int type) { size_t expired = 0; size_t tried = 0; + long long check = ACTIVE_EXPIRE_CYCLE_FAST_DURATION; // assume a check is roughly 1us. It isn't but good enough db->expireitr = db->setexpire->enumerate(db->expireitr, now, [&](expireEntry &e) __attribute__((always_inline)) { if (e.when() < now) { @@ -279,9 +280,10 @@ void activeExpireCycle(int type) { g_pserver->stat_expired_time_cap_reached_count++; return false; } + check = ACTIVE_EXPIRE_CYCLE_FAST_DURATION; } return true; - }); + }, &check); total_expired += expired; } diff --git a/src/semiorderedset.h b/src/semiorderedset.h index 450910c49..00a1f1d91 100644 --- a/src/semiorderedset.h +++ b/src/semiorderedset.h @@ -30,7 +30,7 @@ class semiorderedset { // Aim for roughly 4 cache lines per bucket (determined by imperical testing) // lower values are faster but use more memory - return std::max((64/sizeof(T))*4, (size_t)2); + return std::max((64/sizeof(T))*8, (size_t)2); } public: @@ -122,7 +122,7 @@ public: // enumeration starting from the 'itrStart'th key. Note that the iter is a hint, and need no be valid anymore template - setiter enumerate(const setiter &itrStart, const T_MAX &max, T_VISITOR fn) + setiter enumerate(const setiter &itrStart, const T_MAX &max, T_VISITOR fn, long long *pccheck) { setiter itr(itrStart); @@ -135,7 +135,7 @@ public: for (size_t ibucket = 0; ibucket < m_data.size(); ++ibucket) { - if (!enumerate_bucket(itr, max, fn)) + if (!enumerate_bucket(itr, max, fn, pccheck)) break; itr.idxSecondary = 0; @@ -314,7 +314,7 @@ private: } template - inline bool enumerate_bucket(setiter &itr, const T_MAX &max, T_VISITOR &fn) + inline bool enumerate_bucket(setiter &itr, const T_MAX &max, T_VISITOR &fn, long long *pcheckLimit) { auto &vec = m_data[itr.idxPrimary]; for (; itr.idxSecondary < vec.size(); ++itr.idxSecondary) @@ -323,8 +323,9 @@ private: assert((itr.idxSecondary+1) >= vec.size() || static_cast(vec[itr.idxSecondary]) <= static_cast(vec[itr.idxSecondary+1])); + (*pcheckLimit)--; if (max < static_cast(*itr)) - return true; + return *pcheckLimit > 0; size_t sizeBefore = vec.size(); if (!fn(*itr)) @@ -339,6 +340,6 @@ private: } } vec.shrink_to_fit(); - return true; + return *pcheckLimit > 0; } };