Uploaded image for project: 'Mesos'
  1. Mesos
  2. MESOS-6765

Make the Resources wrapper "copy-on-write" to improve performance.

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Critical
    • Resolution: Fixed
    • None
    • 1.7.1, 1.8.0
    • None

    Description

      Resources currently directly stores the underlying resource objects:

      class Resources
      {
        ...
        std::vector<Resource_> resources;
      };
      

      What this means is that copying of Resources (which occurs frequently) is expensive since copying a Resource object is relatively heavy-weight.

      One strategy, in MESOS-4770, is to avoid protobuf in favor of C++ types (i.e. replace Value::Scalar, Value::Set, and Value::Ranges with C++ equivalents). However, metadata like reservations, disk info, etc, is still fairly expensive to copy even if avoiding protobufs.

      An approach to reduce copying would be to only copy the resource objects upon writing, when there are multiple references to the resource object. If there is a single reference to the resource object we could safely mutate it without copying. E.g.

      class Resource
      {
        ...
        std::vector<shared_ptr<Resource_>> resources;
      };
      
      // Mutation function:
      void Resources::mutate(size_t index)
      {
        // Copy if there are multiple references.
        if (resources[i].use_count() > 1) {
          resources[i] = copy(resources[i]);
        }
      
        // Mutate safely.
        resources[i].some_mutation();
      }
      

      On the other hand, this introduces a additional level of pointer chasing. So we would need to weigh the approaches.

      Attachments

        Issue Links

          Activity

            People

              mzhu Meng Zhu
              bmahler Benjamin Mahler
              Benjamin Mahler Benjamin Mahler
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: