Issue Details (XML | Word | Printable)

Key: AXIS-1519
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Troy Rudolph
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Axis

SimpleUUIDGen.nextUUID() is very, very, very slow

Created: 18/Aug/04 02:56 PM   Updated: 08/Dec/06 11:57 PM
Return to search
Component/s: None
Affects Version/s: 1.1
Fix Version/s: None

Time Tracking:
Not Specified

Environment: Any
Issue Links:
Cloners
 

Resolution Date: 18/Aug/04 03:16 PM


 Description  « Hide
It takes .4917 seconds to generate just one UUID. (Yes, seconds.) This renders the feature very nearly useless.

In SimpleUUIDGen, there is a simple, but very expensive, bug.. It creates a new instance of SecureRandom on each call to nextUUID(). Making a new instance of SecureRandom is very expensive because it has to set up the environment for producing cryptographically strong random numbers.

The instance of SecureRandom should be in a static variable and init'ed just once. Then, you call getNextLong() when you want another number from it. It would be much faster that way without compromising the integrity of the UUIDs generated.

BTW, If you look at the comment I copied from the code, it appears that this is what the developer meant to make the SecureRandom instance static, but forgot.

    /**
     * Creates a new UUID. The algorithm used is described by The Open Group.
     * See <a href="http://www.opengroup.org/onlinepubs/009629399/apdxa.htm">
     * Universal Unique Identifier</a> for more details.
     * <p>
     * Due to a lack of functionality in Java, a part of the UUID is a secure
     * random. This results in a long processing time when this method is called
     * for the first time.
     */


Here's a proposed fix. In the member variables, add the following.

    private static Random secureRandom = null;
    static {
        try {
            secureRandom = SecureRandom.getInstance("SHA1PRNG", "SUN");
        } catch (Exception e) {
            secureRandom = new Random();
        }
    }


The, remove the code near line 235 where the SecureRandom is being created.

This change should do it just once.




 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Davanum Srinivas added a comment - 18/Aug/04 03:16 PM
already fixed in 1.2 :)

-- dims