Catching up on this list, I don't see any replies to this one yet, so I'll take a crack at it:
On Mon, Mar 3, 2014 at 1:00 PM, Kane Lai <[email protected]> wrote: > Then the problem is, I need to maintain a large state in the program in > the format of HashMap<String, MyData>, where MyData is a POJO containing a > few fields, and the size of the map could be as large as 1 million. So I'm > wondering how I should keep such a large state in Akka while allowing > simultaneous insert/delete of records by other actors. It mostly won't > perform well if I copy the whole object. > I'm not clear on every detail of what you're trying to do, but suffice it to say, my app's fairly similar conceptually. The key is Victor's point about structural sharing. Making a "copy" of a HashMap actually just returns a tiny tweak of the previous value, so the time it takes is more or less constant regardless of the Map's size. Think of the HashMap as being essentially a stack of states that are each adding or removing a little information. This is true of pretty much all of the immutable data types, including case classes. In general, when you "copy" one of these data types, you're really just adding a new node on top of the previous state, so it's algorithmically pretty fast. (Obviously, in cases where you are *really* copying the data, such as sending it as a message from an Actor to an Actor on another system, that can get expensive. But that's true regardless of the data structure, and is to be avoided if possible.) A bigger concern is your comment "while allowing simultaneous insert/delete of records by other actors". Keep in mind that the most important principle of good Akka is keeping your data well-isolated. This table should probably be encapsulated inside a single Actor, which does very little aside from providing access to its information. Those other actors should be making their changes through this one... -- >>>>>>>>>> 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.
