-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mongo locking in Akka project #1
Comments
The Akka side doesn't need locking when designed properly. Actors have mailboxes (queues) and process the messages they receive serially. Since we only have one updater actor per product and it is the only thing that can update that product (and only processes one message at a time) we don't need a lock since there is no concurrent access to the memory. The shared state side does need a mechanism to prevent concurrent access to the updateQuantity method for each product's InventoryQuantity instance since it has no such mechanism for enforcing serial access. So a lock (or CAS) is necessary. |
Hi Dana, This is getting clearer. Thanks for all your patience explaining all of this.
It's not as bad as it may sound A. The threadpool is initialized at application start use an ExecutorService I've been think of removing the Play dependency and then use something like https://scalameter.github.io/ to microbenchmark the 2 approaches. That way the only external feature required would be MongoDB. |
Great idea, Kervin! I totally agree that this would certainly even up the playing field to a large degree. But this would be handling concurrency with a consumer-producer paradigm rather than a shared-state one. That said, it's all semantics and it would be fun and informative to see how Akka would stack up there. Cheers and thanks for keeping this conversation going... it's great that we've gotten so much mileage out of a couple of toy apps. |
Hi Dana,
Is the Akka side locking? Otherwise how do you synchronize the inventory count serialization.
If it's not locking, shouldn't the shared side not lock as well?
Best regards,
Kervin
The text was updated successfully, but these errors were encountered: