3 ms·
If you have code that doesn't need to mutate data, it is already easy-ish to write on whatever scale you want. The problem is that there are very few algorithms
by tsimionescu 7y ago
If you have code that doesn't need to mutate data, it is already easy-ish to write on whatever scale you want. The problem is that there are very few algorithms and business problems that don't require shared state to work.
I'm not sure how actors or continuations could solve the problem of creating a distributed database of clients, or even of computing histograms on data in parallel, significantly more easily than more traditional programming paradigms.
- toast0 7y agoRather than accessing the shared data directly, you send a message to the actor that owns that piece of shared data, that message could be a request for some data, or a request to modify it in some way. The actor that owns the data reads its mailbox of requests and processes them without worrying about locks and things, because it has exclusive access. The actor that needs to access the data doesn't worry about locks and things because it's not directly accessing it, it's just sending a message. The system worries about locks and things, because the message mailboxes are shared state to some extent. If you can cleanly separate ownership of different pieces of data into different actors, you get parallelism. If there's too much dependency between the pieces of data, so that separating ownership makes things more complex, maybe that becomes more visible.
- tsimionescu 7y agoThat sounds nice, but it means that all reads and writes are serialized. You can't scale a system like this to, say, work for sign-up and retrieval of all Gmail users.
- toast0 7y agoTo scale up, you need to partition/shard the space. For gmail users, you could hash on the (normalized) username, and all users with hash between A and B would go to one actor, etc. You don't need (or want) parallelism for signup on a single user id, but you could hash or otherwise divide that work to that level. You can also do a partitioned work queue with a (smallish) worker pool per partition; and have the queue keep track of any keys with a current worker, to assign further work to that worker (to avoiding parallel work on the same key and the locking that requires)
- tsimionescu 7y agoThese are elegant solutions, but they are also rather complex, and I'm sure that if we dig in deeper there are further complexities to explore. I have no doubt that the actor model or continuations can be used to solve any problem. I do however doubt that it would turn out to be simpler than using shared state and explicit locking; or using ledger-like approaches. I also don't think it would be more complex! I believe that problems of distributed computing are inherently hard enough that the incidental complexity from your chosen modeling approach is not likely to be a significant portion of the overall complexity.
- toast0 7y agoThe nice thing, if you do it right, is that each piece is going to be simple. There may well be emergent complexity in how the simple parts go together, but that's going to happen anyway. Might as well make the parts simple where you can. Incidentally, I think email is a great example of something with clear divisions of work --- an actor could easily be responsible for a single user's mailbox, and there should be no overlap in responsibility. Possibly, you could have one actor per folder, but gmail doesn't really have folders, so...
- tsimionescu 7y agoI think that's a good example of how these kinds of static allocations are tricky to get right. With your scheme, you would have hundreds of millions or even billions of actors being idle all day long, and probably a few thousand actors potentially overwhelmed with processing new email every second. You would probably have to go back and decide a new partitioning scheme to avoid this, with maybe cascading consequences in other places. The pieces are simpler, but you might pay a greater cost in system-level design. In shared state models, you could have a more dynamic approach with a number of worker threads scaling with the number of requests (emails), with the only problem being contention when accessing the same piece of the shared storage, but at least no massive overhead from idle workers. The shared-state layer would be responsible for the locking strategy, and could even potentially optimize the required locking without necessarily changing the worker code, depending on the level of abstraction it offers workers to begin with.