Evaluate the performance benefits of hazard pointers

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Done
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Internal Code
    • Service Arch
    • Service Arch 2024-04-15, Service Arch 2024-04-29
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      The primary objective is to evaluate the potential performance benefits of using hazard pointers for objects that support stale reads (e.g. replica-set configuration). The findings in this ticket will help us decide on the scheduling plan for SERVER-87020.

      We may mimic hazard pointers by creating a mutex protected shared pointer, where the mutex is optimized for readers (see SERVER-86656 for an example).

      template <class T>
      class EmulatedHazardPtr {
      public:
          EmulatedHazardPtr(const EmulatedHazardPtr& other) noexcept {
              std::shared_lock lk(other._mutex);
              _ptr = other._ptr;
          }
      
          T* get() const noexcept {
              std::shared_lock lk(_mutex);
              return _ptr.get();
          }
      
          void reset() noexcept {
              std::lock_guard lk(_mutex);
              _ptr.reset();
          }
          ...
      private:
          RWMutex _mutex;
          std::shared_ptr<T> _ptr;
      };
      

            Assignee:
            Alex Li
            Reporter:
            Amirsaman Memaripour
            Votes:
            0 Vote for this issue
            Watchers:
            17 Start watching this issue

              Created:
              Updated:
              Resolved: