Problem with GuidGenerator on AsParallel context #28

Closed
Caldas opened this Issue May 18, 2012 · 3 comments

2 participants

@Caldas

Hi man, here is the code that I´m testing:

static void Main(string[] args)
{
    List<Int32> list = new List<Int32>();
    for (int i = 0; i < 5; i++)
    {
        list.Add(i);
    }
    list.AsParallel().ForAll(item => X());
}

static void X()
{
Guid rowGuid = GuidGenerator.GenerateTimeBasedGuid();
//Here I get a cassandra client 
//Insert cassandra row column name 'A' just for test
}

Because of parallel I just insert 2 or 3 items instead of 5.

@nberardi nberardi was assigned May 22, 2012
@nberardi

This is a DateTime precision problem. I haven't looked at the problem that you are stating but, this would happen for one of two reasons.

  1. DateTime.UtcNow isn't updating fast enough resulting in the same DateTime
  2. Because you are using Parallel one or more treads is executing at the same time resulting in the same DateTime

Having the same DateTime would cause the column to overwrite it self if you were using this GUID as a Column Name.

I have looked at integrating DateTimePrecise into the GuidGenerate to give the precision a little boost.

http://code.google.com/p/mikeamundsen/source/browse/trunk/Amundsen.Utilities/DateTimePrecise.cs?r=126

But haven't had time, if this is something you want to explore, I will be happy to accept a pull request.

@Caldas

I implemented DateTimePrecise and used:


new DateTimePrecise(5).UtcNow

It´s worked. I will submit a Pull Request

@nberardi

Thanks for the pull request.

@nberardi nberardi closed this May 23, 2012
@nberardi nberardi added a commit that referenced this issue May 23, 2012
@nberardi nberardi moved around some code from issues #28 and #30 and used DateTimePreci…
…se in other locations in the project

moved around some methods because they were on the wrong object
f4b065b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment