> On July 29, 2016, 8:52 p.m., Benjamin Mahler wrote: > > src/common/resources.cpp, lines 1456-1457 > > <https://reviews.apache.org/r/50569/diff/1/?file=1457498#file1457498line1456> > > > > On second thought, can we inline the logic here and add a TODO? > > > > ``` > > // Remove the resource if it has become negative or empty. > > // Note that a negative resource means the caller is > > // subtracting more than they should! > > // > > // TODO(bmahler): Provide a stronger interface to avoid > > // silently allowing this to occur. > > > > bool negative = > > resource->type() == Value::SCALAR && > > resource->scalar().value() < 0; > > > > if (negative || isEmpty(*resource)) { > > ... > > } > > ``` > > > > Since isNegative only applies to Scalar, it seems a bit odd to expose > > it as a function. Whereas isEmpty applies to all resource types. > > Guangya Liu wrote: > Hi Ben, just want to have some discussion here, seems another option is > to enhance `isEmpty` as following by enabling checking if `SCALAR` resources > is 0 or a negative number, what do you think? > > ``` > bool Resources::isEmptyOrNegative(const Resource& resource) > { > if (resource.type() == Value::SCALAR) { > return resource.scalar().value() <= 0; > } else if (resource.type() == Value::RANGES) { > return resource.ranges().range_size() == 0; > } else if (resource.type() == Value::SET) { > return resource.set().item_size() == 0; > } else { > return false; > } > } > ```
I thought about this as well, sounds good. Although since it's in the public interface I'm inclined to leave it called 'isEmpty'. - Benjamin ----------------------------------------------------------- This is an automatically generated e-mail. To reply, visit: https://reviews.apache.org/r/50569/#review144190 ----------------------------------------------------------- On July 29, 2016, 5:43 a.m., Guangya Liu wrote: > > ----------------------------------------------------------- > This is an automatically generated e-mail. To reply, visit: > https://reviews.apache.org/r/50569/ > ----------------------------------------------------------- > > (Updated July 29, 2016, 5:43 a.m.) > > > Review request for mesos, Benjamin Mahler, Joris Van Remoortere, and Klaus Ma. > > > Bugs: MESOS-5921 > https://issues.apache.org/jira/browse/MESOS-5921 > > > Repository: mesos > > > Description > ------- > > When subtract resources finished, we need to call `validate` to > check if the scalar resource is negative so as to remove this > resource if it is negative. This is a bit heavy as the `validate` > did many stuffs. > > This patch is introducing a new helper function `isNegative` > to check if the resource is a negative scalar resource. > > > Diffs > ----- > > include/mesos/resources.hpp 88a9feabf66ed34e7e5b1c6cb7e831818e7f7883 > include/mesos/v1/resources.hpp 054ed00a03319ae5e350542add34f497eaf79152 > src/common/resources.cpp 3dbff24d6859d3b1ed8589cec50170a5202cfbcb > src/v1/resources.cpp 3c85dc8aa8125962b44e60806ece83a7653d0dc7 > > Diff: https://reviews.apache.org/r/50569/diff/ > > > Testing > ------- > > make > make check > > The time of 1000 `ports` `-=` operations was reduced about `0.3s`, even > though this does not improve much, the update does make the logic more clear. > > Before fix: > ``` > [ RUN ] ResourcesOperators/Resources_BENCHMARK_Test.Arithmetic/2 > Took 2.834335secs to perform 1000 'total += r' operations on ports(*):[1-2, > 4-5, 7-8, 10-11, 13-14, 16-17, 1... > Took 21.828846secs to perform 1000 'total.contains(r)' operations on > ports(*):[1-2, 4-5, 7-8, 10-11, 13-14, 16-17, 1... > Took 3.689858secs to perform 1000 'total -= r' operations on ports(*):[1-2, > 4-5, 7-8, 10-11, 13-14, 16-17, 1... > Took 2.962259secs to perform 1000 'total = total + r' operations on > ports(*):[1-2, 4-5, 7-8, 10-11, 13-14, 16-17, 1... > Took 3.760281secs to perform 1000 'total = total - r' operations on > ports(*):[1-2, 4-5, 7-8, 10-11, 13-14, 16-17, 1... > Took 125159us to perform 1000 'r.nonRevocable()' operations on ports(*):[1-2, > 4-5, 7-8, 10-11, 13-14, 16-17, 1... > [ OK ] ResourcesOperators/Resources_BENCHMARK_Test.Arithmetic/2 (35204 > ms) > ``` > > After fix: > ``` > [ RUN ] ResourcesOperators/Resources_BENCHMARK_Test.Arithmetic/2 > Took 2.619237secs to perform 1000 'total += r' operations on ports(*):[1-2, > 4-5, 7-8, 10-11, 13-14, 16-17, 1... > Took 20.528293secs to perform 1000 'total.contains(r)' operations on > ports(*):[1-2, 4-5, 7-8, 10-11, 13-14, 16-17, 1... > Took 3.39984secs to perform 1000 'total -= r' operations on ports(*):[1-2, > 4-5, 7-8, 10-11, 13-14, 16-17, 1... > Took 2.78301secs to perform 1000 'total = total + r' operations on > ports(*):[1-2, 4-5, 7-8, 10-11, 13-14, 16-17, 1... > Took 3.399465secs to perform 1000 'total = total - r' operations on > ports(*):[1-2, 4-5, 7-8, 10-11, 13-14, 16-17, 1... > Took 121055us to perform 1000 'r.nonRevocable()' operations on ports(*):[1-2, > 4-5, 7-8, 10-11, 13-14, 16-17, 1... > [ OK ] ResourcesOperators/Resources_BENCHMARK_Test.Arithmetic/2 (32854 > ms) > ``` > > > Thanks, > > Guangya Liu > >
