[SERVER-7310] benchRun() doesn't generate random distribution within the specified range Created: 10/Oct/12  Updated: 11/Jul/16  Resolved: 16/Nov/12

Status: Closed
Project: Core Server
Component/s: Performance
Affects Version/s: None
Fix Version/s: 2.3.1

Type: Bug Priority: Major - P3
Reporter: Ben Becker Assignee: Eric Milkie
Resolution: Done Votes: 0
Labels: benchRun
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Participants:

 Description   

rand() returns an integer between 0 and RAND_MAX, which is 32767 on posix systems. Thus using #RAND_INT in benchRun() will not create an even distribute for a large range. See bench.cpp L300:

int x = min + ( rand() % ( max - min ) );



 Comments   
Comment by Eliot Horowitz (Inactive) [ 16/Nov/12 ]

https://github.com/mongodb/mongo/commit/72e82c6c1ed149bdabc8de4207c69856f3f7e86e

Comment by Tad Marshall [ 10/Oct/12 ]

I think we'd be happier in the long run if we switch to using our own pseudo-random number generator and precisely define its semantics. Ideally, we would be able to generate the same pseudo-random sequence on every platform every time by specifying the seed. We may have uses for a "global" sequence shared by all threads or by a subset of threads, just as we may have uses for two threads each getting its own copy of a single "fixed" sequence.

Comment by Andy Schwerin [ 10/Oct/12 ]

rand() isn't really safe to use at all in benchrun, because the global random seed state is not accessed in a thread-safe manner. Every thread should really have its own instance of a random number generator, and said generator should have well defined behavior, regarding uniformity of generated numbers, etc.

Generated at Thu Feb 08 03:14:10 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.