mesos-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Benjamin Mahler <bmah...@apache.org>
Subject Re: Review Request 50569: Added `isNegative` to check if the scalar resource is negative.
Date Fri, 29 Jul 2016 20:52:18 GMT

-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/50569/#review144190
-----------------------------------------------------------




src/common/resources.cpp (lines 1456 - 1457)
<https://reviews.apache.org/r/50569/#comment210195>

    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.


- Benjamin Mahler


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
> 
>


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message