简体   繁体   中英

Akka actors processes one message at a time

Akka actor can only process one message at a time and hence we dont need to worry about concurrency.

Consider that I have a system for a pizza Shop.

Design is like this

1)Webservice 
2)Akka ecosystem with actors like PizaaCreater, DeliveryHandler 
3)Web service accepts ther order and passes to PizzaCreater,PizzaCreater creates pizza and passes it to DeliveryHanlder.

Now as there is only one instance of PizzaCreater and DeliveryHandler.This will slow down entire system.

1)Should i create multiple PizzaCreaters and DeliveryHandler?
2)How will CustomerService pass order to PizzaCreater with minimum load or how would PizzaCreater pass the pizza to DelivieryHandler with minimum load then?
3)Is creating multiple instance of PizzaCreaters / DeliveryHandler ok?
  1. If the "pizza creation" is a blocking operation (uses network/db) create a router with PizzaCreatorWorkers (the number of workers/threads depends on your scenario). If the "pizza creation" is non-blocking - just create one actor per request. Same thing for Delivery: create a router with a fixed number of DeliveryHandles if the delivery is blocking otherwise just create an actor and pass it "the pizza".

  2. In all cases the order passing should be done through non-mutable messages : you should not modify the order once you passed it down the chain. You should not worry about the "load" as passing messages is what Akka does so it is very efficient - you just pass references between actors.

  3. The akka docs specify that the akka system is designed to handle millions of actors, so never worry about "multiple instances" of actors as long as this is what the logic of your application requires.

From akka.io main page:

50 million msg/sec on a single machine. Small memory footprint; ~2.5 million actors per GB of heap.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM