It might be overkill, but I partially migrated Twitter's 
Snowflake<https://github.com/twitter/snowflake/blob/master/src/main/scala/com/twitter/service/snowflake/IdWorker.scala>as
 an Akka extension to generate unique ID which can be represented as a 
number.

Snowflake uses millisecond timestamp, datacenter id, worker id and sequence 
number which increases from 0 for a certain timestamp.


On Monday, December 16, 2013 9:42:57 PM UTC+9, Derek Wyatt wrote:
>
>
> On 2013-12-16, at 5:50 AM, √iktor Ҡlang wrote:
>
>
>
>
> On Mon, Dec 16, 2013 at 11:46 AM, Derek Wyatt 
> <[email protected]<javascript:>
> > wrote:
>
>> On 2013-12-16, at 5:42 AM, √iktor Ҡlang wrote:
>>
>>
>>
>>
>> On Mon, Dec 16, 2013 at 11:33 AM, Derek Wyatt 
>> <[email protected]<javascript:>
>> > wrote:
>>
>>>
>>> On Dec 16, 2013, at 2:09 AM, Roland Kuhn <[email protected]<javascript:>> 
>>> wrote:
>>>
>>> Hi Derek,
>>>
>>> 15 dec 2013 kl. 23:55 skrev Derek Wyatt <[email protected]<javascript:>
>>> >:
>>>
>>> On 2013-12-15, at 5:52 PM, Nicholas Sterling wrote:
>>>
>>> Is it really safe, in this multi-core era, to assume that two IDs could 
>>> not be generated in the same nanosecond?
>>>
>>>
>>> Absolutely.  Use whatever mechanism you want. A good UUID generator, an 
>>> AtomicLong, whatever... This is a problem that's been heavily solved for a 
>>> long time now.
>>>
>>>
>>> Those mechanisms you quote are not appropriate to be used at the rates 
>>> proposed and shared across threads, they are simply too heavy. Doing 
>>> something once may be fine, but doing it 50 million times per second can be 
>>> a problem. Anecdotally, we already generate a unique ID—the identity of the 
>>> message envelope—but even that is optimized away if not needed: there is a 
>>> noticeable performance price you pay if you touch an object’s 
>>> identityHashCode because that is normally not stored and instead the 
>>> (unstable) memory location is used. So, what exactly do you refer to when 
>>> saying that this problem has been solved long ago?
>>>
>>>
>>> Well, I think we need to be realistic here.  If an app is going to do 
>>> interesting work, you're not going to be generating 50 mil msgs per second. 
>>> Theoretical discussions are fine, but in reality I don't think we're 
>>> talking about that scale.  As for how the problem has been solved, I think 
>>> there are a number of reasonably obvious solutions, no?
>>>
>>
>> You're assuming that nanoTime has nanosecond accuracy.
>>
>>
>> No, actually I'm not.  I'm trying to just be practical.  You're right 
>> that it isn't that tight, so when I say nanosecond, you can take that as 
>> "resolution of the timer", or whatever you like.
>>
>
> Yes, and if you're really unlucky, it's using currentTimeMillis padded 
> with zeroes (and currentTimeMillis can have 10s of _milliseconds_ of 
> accuracy, which will quite soon lead to collisions)
>  
>
>>
>> In the general case, this might be a problem, but with Actors all you 
>> should need to do is give them a unique prefix.
>>
>
> Yes, but now you need to generate a unique prefix...
>  
>
>>  If you don't like nanoTime, don't use it.  Use a Long.
>>
>
> nanoTime is a Long, but I guess you mean sequence number?
>
>
> I do.
>
> It's quite possible that this thread has gone awry :)  I believe that the 
> original issue was probably meaning to say something like, "Are you sure 
> that using nanoseconds as unique identifiers isn't a terrible idea?".  Of 
> course, to this I would certainly say "yes".  And if that was what the 
> original question was, I probably tore this thread way off course :)
>
>
> Cheers,
> √
>  
>
>>
>>
>> Cheers,
>> √
>>  
>>
>>>
>>> def genId(implicit uniqueifier: Long) = 
>>> s"${uniqueifier}-${System.nanoTime}"
>>>
>>> Now, give each Actor an implicit uniqueifier, and then put in a 
>>> guarantee that no single Actor will call this more than once per nano 
>>> second. e.g. create enough Actors to do the work, loop until the new Id 
>>> isn't the same as the last one, etc...
>>>
>>> Or, give a each Actor a uniqueifier, and let it use a monotonically 
>>> increasing postfix identifier.  e.g. gen the uniqueifier as a UUID and then 
>>> let them increment a Long until it gets exhausted, then pick another UUID, 
>>> or crash the Actor, or...
>>>
>>> Vary these themes as you see fit.  "Solved" here means that I'm not 
>>> being all that inventive; for non-generalized situations, the above should 
>>> work perfectly fine.
>>>
>>>
>>> Regards,
>>>
>>> Roland
>>>
>>>
>>>
>>> -- 
>>> >>>>>>>>>> Read the docs: http://akka.io/docs/
>>> >>>>>>>>>> Check the FAQ: http://akka.io/faq/
>>> >>>>>>>>>> Search the archives: 
>>> https://groups.google.com/group/akka-user
>>> --- 
>>> You received this message because you are subscribed to a topic in the 
>>> Google Groups "Akka User List" group.
>>> To unsubscribe from this topic, visit 
>>> https://groups.google.com/d/topic/akka-user/84Mb4pEp4wQ/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to 
>>> [email protected] <javascript:>.
>>> To post to this group, send email to [email protected]<javascript:>
>>> .
>>> Visit this group at http://groups.google.com/group/akka-user.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>>
>>>
>>> -- 
>>> >>>>>>>>>> Read the docs: http://akka.io/docs/
>>> >>>>>>>>>> Check the FAQ: http://akka.io/faq/
>>> >>>>>>>>>> Search the archives: 
>>> https://groups.google.com/group/akka-user
>>> --- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Akka User List" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to [email protected] <javascript:>.
>>> To post to this group, send email to [email protected]<javascript:>
>>> .
>>> Visit this group at http://groups.google.com/group/akka-user.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>>
>>>
>>>
>>> *Dr. Roland Kuhn*
>>> *Akka Tech Lead*
>>> Typesafe <http://typesafe.com/> – Reactive apps on the JVM.
>>> twitter: @rolandkuhn
>>>  <http://twitter.com/#!/rolandkuhn>
>>>  
>>>
>>> -- 
>>> >>>>>>>>>> Read the docs: http://akka.io/docs/
>>> >>>>>>>>>> Check the FAQ: http://akka.io/faq/
>>> >>>>>>>>>> Search the archives: 
>>> https://groups.google.com/group/akka-user
>>> --- 
>>> You received this message because you are subscribed to a topic in the 
>>> Google Groups "Akka User List" group.
>>> To unsubscribe from this topic, visit 
>>> https://groups.google.com/d/topic/akka-user/84Mb4pEp4wQ/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to 
>>> [email protected] <javascript:>.
>>> To post to this group, send email to [email protected]<javascript:>
>>> .
>>> Visit this group at http://groups.google.com/group/akka-user.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>>
>>>
>>> -- 
>>> >>>>>>>>>> Read the docs: http://akka.io/docs/
>>> >>>>>>>>>> Check the FAQ: http://akka.io/faq/
>>> >>>>>>>>>> Search the archives: 
>>> https://groups.google.com/group/akka-user
>>> --- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Akka User List" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to [email protected] <javascript:>.
>>> To post to this group, send email to [email protected]<javascript:>
>>> .
>>> Visit this group at http://groups.google.com/group/akka-user.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>
>>
>>
>> -- 
>> Cheers,
>> √
>>
>> * Viktor Klang*
>> *Director of Engineering*
>> Typesafe <http://www.typesafe.com/>
>>
>> Twitter: @viktorklang
>>
>> -- 
>> >>>>>>>>>> Read the docs: http://akka.io/docs/
>> >>>>>>>>>> Check the FAQ: http://akka.io/faq/
>> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
>> --- 
>> You received this message because you are subscribed to a topic in the 
>> Google Groups "Akka User List" group.
>> To unsubscribe from this topic, visit 
>> https://groups.google.com/d/topic/akka-user/84Mb4pEp4wQ/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to 
>> [email protected] <javascript:>.
>> To post to this group, send email to [email protected]<javascript:>
>> .
>> Visit this group at http://groups.google.com/group/akka-user.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>> -- 
>> >>>>>>>>>> Read the docs: http://akka.io/docs/
>> >>>>>>>>>> Check the FAQ: http://akka.io/faq/
>> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "Akka User List" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected]<javascript:>
>> .
>> Visit this group at http://groups.google.com/group/akka-user.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>
>
> -- 
> Cheers,
> √
>
> * Viktor Klang*
> *Director of Engineering*
> Typesafe <http://www.typesafe.com/>
>
> Twitter: @viktorklang
>
> -- 
> >>>>>>>>>> Read the docs: http://akka.io/docs/
> >>>>>>>>>> Check the FAQ: http://akka.io/faq/
> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
> --- 
> You received this message because you are subscribed to a topic in the 
> Google Groups "Akka User List" group.
> To unsubscribe from this topic, visit 
> https://groups.google.com/d/topic/akka-user/84Mb4pEp4wQ/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to 
> [email protected] <javascript:>.
> To post to this group, send email to [email protected]<javascript:>
> .
> Visit this group at http://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: http://akka.io/faq/
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to