abstract class IdMsg(val id:Long = System.nanoTime)case class AMsg(a:Int, b:String) extends IdMsg {override def toString = s"(a = $a, b= $b, id = $id)"}val a = AMsg(1,"foo")val b = AMsg(2,"foo")
Is it really safe, in this multi-core era, to assume that two IDs could not be generated in the same nanosecond?
--
>>>>>>>>>> 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 akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/groups/opt_out.
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.
--
>>>>>>>>>> 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 akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
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 akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/groups/opt_out.
Hi Derek,15 dec 2013 kl. 23:55 skrev Derek Wyatt <de...@derekwyatt.org>: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?
On Dec 16, 2013, at 2:09 AM, Roland Kuhn <goo...@rkuhn.info> wrote:Hi Derek,15 dec 2013 kl. 23:55 skrev Derek Wyatt <de...@derekwyatt.org>: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?
On Mon, Dec 16, 2013 at 11:33 AM, Derek Wyatt <de...@derekwyatt.org> wrote:
On Dec 16, 2013, at 2:09 AM, Roland Kuhn <goo...@rkuhn.info> wrote:Hi Derek,15 dec 2013 kl. 23:55 skrev Derek Wyatt <de...@derekwyatt.org>: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.
On 2013-12-16, at 5:42 AM, √iktor Ҡlang wrote:On Mon, Dec 16, 2013 at 11:33 AM, Derek Wyatt <de...@derekwyatt.org> wrote:
On Dec 16, 2013, at 2:09 AM, Roland Kuhn <goo...@rkuhn.info> wrote:Hi Derek,15 dec 2013 kl. 23:55 skrev Derek Wyatt <de...@derekwyatt.org>: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.
In the general case, this might be a problem, but with Actors all you should need to do is give them a unique prefix.
If you don't like nanoTime, don't use it. Use a Long.
On Mon, Dec 16, 2013 at 11:46 AM, Derek Wyatt <de...@derekwyatt.org> wrote:
On 2013-12-16, at 5:42 AM, √iktor Ҡlang wrote:On Mon, Dec 16, 2013 at 11:33 AM, Derek Wyatt <de...@derekwyatt.org> wrote:
On Dec 16, 2013, at 2:09 AM, Roland Kuhn <goo...@rkuhn.info> wrote:Hi Derek,15 dec 2013 kl. 23:55 skrev Derek Wyatt <de...@derekwyatt.org>: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?
Gosh, I must have done a poor job making my point! My question is probably more about Scala but since I'm looking for ideas on modeling related data (messages) specifically for Akka, I posted here.So, my original issue is really asking how to define common data between messages. My first reply to this thread was a naive (scala newbie) attempt at that.Ideally I'd like to say something likecase class MyMessage(foo:String) extends MessageWithId... and have it act as if MyMessage was a case class defined with an id property and preferably some implementation (implementation important, but not for this discussion) to generate the id. So my question is about whether we can define messages in something akin to an OO inheritance hierarchy.