[
https://issues.apache.org/jira/browse/MESOS-3046?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14647282#comment-14647282
]
Nikita Vetoshkin commented on MESOS-3046:
-----------------------------------------
Out of curiosity took a look at this one.
In MESOS-2940 it was suggested to put generator in {{thread_local}} like this
{noformat}
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/uuid.hpp
b/3rdparty/libprocess/3rdparty/stout/include/stout/uuid.hpp
index e8ebe0b..b0facb2 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/uuid.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/uuid.hpp
@@ -28,7 +28,7 @@ struct UUID : boost::uuids::uuid
public:
static UUID random()
{
- return UUID(boost::uuids::random_generator()());
+ return UUID(random_generator());
}
static UUID fromBytes(const std::string& s)
@@ -62,6 +62,7 @@ public:
private:
explicit UUID(const boost::uuids::uuid& uuid)
: boost::uuids::uuid(uuid) {}
+ static thread_local boost::uuids::random_generator random_generator;
};
#endif // __STOUT_UUID_HPP__
{noformat}
fails with GCC 5.1.1 on Fedora x64:
{noformat}
./.libs/libmesos.so: error: undefined reference to 'TLS init function for
UUID::random_generator'
./.libs/libmesos.so: error: undefined reference to 'UUID::random_generator'
{noformat}
However, putting static in function does work
{noformat}
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/uuid.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/uuid.hpp
@@ -28,7 +28,8 @@ struct UUID : boost::uuids::uuid
public:
static UUID random()
{
- return UUID(boost::uuids::random_generator()());
+ static thread_local boost::uuids::random_generator random_generator;
+ return UUID(random_generator());
}
static UUID fromBytes(const std::string& s)
{noformat}
But I wonder whether it contradicts with "no static objects with non-trivial
constructors" policy, because lifetime of this object is event more
sophisticated that ordinary {{static}} with per thread list of destructors to
call upon thread exit and so on.
> Stout's UUID re-seeds a new random generator during each call to UUID::random.
> ------------------------------------------------------------------------------
>
> Key: MESOS-3046
> URL: https://issues.apache.org/jira/browse/MESOS-3046
> Project: Mesos
> Issue Type: Bug
> Components: stout
> Reporter: Benjamin Mahler
> Labels: newbie, twitter
>
> Per [~StephanErb] and [~kevints]'s observations on MESOS-2940, stout's UUID
> abstraction is re-seeding the random generator during each call to
> {{UUID::random()}}, which is really expensive.
> This is confirmed in the perf graph from MESOS-2940.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)