Skip to content

Conversation

@pcmoritz
Copy link
Contributor

@pcmoritz pcmoritz commented May 14, 2018

This gets rid of the std::random_device, which is slow and causes errors in valgrind. Instead we use the std::mt19937 Mersenne Twister.

@pcmoritz pcmoritz changed the title ARROW-2578: Use mersenne twister to generate random number ARROW-2578: [Plasma] Use mersenne twister to generate random number May 14, 2018
@codecov-io
Copy link

codecov-io commented May 14, 2018

Codecov Report

Merging #2039 into master will increase coverage by 1.19%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2039      +/-   ##
==========================================
+ Coverage   86.28%   87.48%   +1.19%     
==========================================
  Files          11      178     +167     
  Lines         773    28595   +27822     
==========================================
+ Hits          667    25015   +24348     
- Misses        106     3580    +3474
Impacted Files Coverage Δ
cpp/src/plasma/test/client_tests.cc 100% <100%> (ø)
cpp/src/plasma/common.cc 94.11% <100%> (ø)
rust/src/lib.rs
rust/src/memory.rs
rust/src/error.rs
rust/src/list_builder.rs
rust/src/bitmap.rs
rust/src/array.rs
rust/src/datatypes.rs
rust/src/memory_pool.rs
... and 181 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 19af862...21d0e3f. Read the comment docs.

#include <limits>
#include <mutex>
#include <random>
#include <thread>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

static std::mutex mutex;
std::lock_guard<std::mutex> lock(mutex);
static std::mt19937 generator;
std::uniform_int_distribution<uint32_t> d(0, std::numeric_limits<uint8_t>::max());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor, but I'm not a huge fan of the variable name d

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@pcmoritz
Copy link
Contributor Author

+1 merging this now to remove the valgrind testing error

@pcmoritz pcmoritz closed this in 4b8511f May 14, 2018
@pcmoritz pcmoritz deleted the new-rng branch May 14, 2018 08:19
@pitrou
Copy link
Member

pitrou commented May 16, 2018

This PR is constructing a generator with a fixed seed, so now distinct processes will trivially collide when generate random ids:

$ python -c "from pyarrow import plasma; print(plasma.ObjectID.from_random())"
ObjectID(d022e7d520f8e938a14e188c47308cfef5fff7f7)
$ python -c "from pyarrow import plasma; print(plasma.ObjectID.from_random())"
ObjectID(d022e7d520f8e938a14e188c47308cfef5fff7f7)

@pcmoritz
Copy link
Contributor Author

pcmoritz commented Aug 7, 2018

I just saw this and opened a JIRA here: https://issues.apache.org/jira/browse/ARROW-3018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants