[
https://issues.apache.org/jira/browse/MESOS-4561?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15125320#comment-15125320
]
haosdent commented on MESOS-4561:
---------------------------------
I am not sure how to test, but I think it may related to this {{Why '==' is
slow on
std::string|http://stackoverflow.com/questions/28734684/why-is-slow-on-stdstring}}
when you benchmark. According my test, the result are nearly same.
My test code:
{code}
TEST(RolesTest, Benchmark)
{
int64_t ops = 1000;
int64_t cycles = 1000000;
string validateNames[ops];
for (int64_t i = 0; i < ops; ++i) {
validateNames[i] = stringify(i);
}
Stopwatch watch;
watch.start();
for (int64_t i = 0; i < ops * cycles; ++i) {
roles::validate(validateNames[i % ops]);
}
Duration elapsed = watch.elapsed();
cout << "Estimated Total: " << (elapsed.ns() / ops / cycles)
<< " nanos / ops" << endl;
}
{code}
The result when use {{new
version|https://github.com/apache/mesos/blob/5e618ac2197e856f09511850bebe51fea71c1844/src/common/roles.cpp}}
to test.
{code}
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from RolesTest
[ RUN ] RolesTest.Benchmark
Estimated Total: 49 nanos / ops
[ OK ] RolesTest.Benchmark (49196 ms)
[----------] 1 test from RolesTest (49196 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (49208 ms total)
[ PASSED ] 1 test.
{code}
After revert to {{old
version|https://github.com/apache/mesos/blob/ffcef51f06f41f707e7026070f2335b956ed9d2c/src/common/roles.cpp}},
the result looks don't have big different:
{code}
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from RolesTest
[ RUN ] RolesTest.Benchmark
Estimated Total: 46 nanos / ops
[ OK ] RolesTest.Benchmark (46327 ms)
[----------] 1 test from RolesTest (46327 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (46339 ms total)
[ PASSED ] 1 test.
{code}
> Investigate `std::string` to C string comparison.
> -------------------------------------------------
>
> Key: MESOS-4561
> URL: https://issues.apache.org/jira/browse/MESOS-4561
> Project: Mesos
> Issue Type: Bug
> Reporter: Michael Park
> Labels: mesosphere
>
> [~jvanremoortere] identified a large performance bottleneck in role
> validation logic and submitted a
> [fix|https://github.com/apache/mesos/commit/5e618ac2197e856f09511850bebe51fea71c1844]
> for the 0.27.0 release.
> However, templated versions of {{bool operator==(const std::string&, const
> char \*)}} and {{bool operator==(const char\*, const std::string&)}} are part
> of the standard library
> http://en.cppreference.com/w/cpp/string/basic_string/operator_cmp, and
> therefore should not have triggered temporary string constructions.
> The first thought was perhaps they don't happen to be implemented in
> {{libstdc++}}, but having looked at its implementation, I was able to find
> the definitions of these operators.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)