[
https://issues.apache.org/jira/browse/RNG-104?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16857765#comment-16857765
]
Alex D Herbert commented on RNG-104:
------------------------------------
I repeated the creation of array seeds up to length 128 using all possible
block sizes in powers of 2. The block size is the number of values created per
synchronisation on the RNG.
Here is the data for the generation of long arrays (seed size on the x-axis):
!t1.jpg!
With a single thread there is a noticeable boost in speed even generating 2
values at a time. For a seed of size 2 the boost is approximately 1.7-fold as
the system does 1 synchronisation rather than 2. It is greater when the seed is
larger. But the improvement is never as high as the block size, i.e. block size
4 does not yield 4-fold improvement, because it is not just synchronisation
that is being timed.
The improvement falls off at higher block sizes to a fairly stable 6 fold speed
increase.
!t4.jpg!
When there is thread contention the improvement is still observed but it is not
as dramatic and it takes longer to fall off to stable.
*Conclusion*
Each thread must wait for the RNG to be free. So the length of time using the
RNG should be balanced with the length of time waiting.
There is no simple ideal setting. If all seed creation is done on a single
thread then it would be an advantage to compute values together. A good cut-off
would be around 4 - 8 values. The output seed would be the same.
When there is thread contention then in this scenario the cut-off is around 16
- 32 values. If using 4 or 8 values then the performance boost is still 3 to 5
fold. The output seed would be different as chunks of output would form the
seed rather than single values taken from the sequence shared between threads.
However the output is never a continuous stream from the RNG unless the block
size exceeds the seed size.
> SeedFactory seed creation performance analysis
> ----------------------------------------------
>
> Key: RNG-104
> URL: https://issues.apache.org/jira/browse/RNG-104
> Project: Commons RNG
> Issue Type: Task
> Components: simple
> Affects Versions: 1.3
> Reporter: Alex D Herbert
> Assignee: Alex D Herbert
> Priority: Minor
> Attachments: t1.jpg, t4.jpg
>
>
> The SeedFactory is used to create seeds for the random generators. To ensure
> thread safety this uses synchronized blocks around a single generator. The
> current method only generates a single int or long per synchronisation.
> Analyze the performance of this approach. The analysis will investigate
> generating multiple values inside each synchronisation around the generator.
> This analysis will also investigate methods to supplement the SeedFactory
> with fast methods to create seeds. This will use a fast seeding method to
> generate a single long value. This can be a seed for a SplitMix generator
> used to create a seed of any length.
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)