Skip to content

Commit

Permalink
AcceptedJobsMap: hash_strmap<Job*, ..., WithFreeList = true>
Browse files Browse the repository at this point in the history
AcceptedJobsMap should enable_freelist, because its insert is in lock,
enable freelist will result much lower latency spike.
  • Loading branch information
rockeet committed Mar 6, 2024
1 parent bb83b14 commit 8b50722
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions tools/dcompact/dcompact_worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,13 +516,14 @@ static string_appender<> BuildMetaKey(const DcompactMeta& meta) {

class Job;
class AcceptedJobsMap {
hash_strmap<Job*> map;
hash_strmap<Job*, fstring_func::hash_align, fstring_func::equal_align,
ValueInline, FastCopy, unsigned, size_t, true> map;
mutable std::mutex mtx;
public:
hash_strmap<Job*>& get_map() { return map; }
auto& get_map() { return map; }
std::mutex& get_mtx() { return mtx; }
AcceptedJobsMap() { map.enable_freelist(4096); }
std::pair<size_t, bool> add(Job*) noexcept;
void add(Job*) noexcept;
intrusive_ptr<Job> find(const DcompactMeta& key) const noexcept;
void del(Job*) noexcept;
size_t peekSize() const noexcept { return map.size(); }
Expand Down Expand Up @@ -2315,13 +2316,12 @@ double QueueItem::score(long long now) const {
return score;
}

std::pair<size_t, bool>
AcceptedJobsMap::add(Job* j) noexcept {
void AcceptedJobsMap::add(Job* j) noexcept {
const auto key = BuildMetaKey(j->m_meta);
mtx.lock();
auto ib = map.insert_i(key, j);
TERARK_VERIFY_S(ib.second, "key = %s", key);
mtx.unlock();
return ib;
}

intrusive_ptr<Job>
Expand Down

0 comments on commit 8b50722

Please sign in to comment.