Implementing an Actor Model in Golang | by Gaurav Sharma | Feb, 2022

Harness the ability of concurrency utilizing this programming assemble

Photograph by George Howden on Unsplash
sort Actor interface 
AddTask(activity Job)
sort Job interface 
sort ActorSystem interface 
SubmitTask(activity Job)
Shutdown(shutdownWG *sync.WaitGroup)

Here’s a gist of ActorSystem:

We put every of the incoming Duties in a channel duties, taskAssigner and Jobwithin the inner queue of an Actor.

It is usually an actor and its job is to execute activity which is added to it channel duties just like assigner actor.

Right here we’ve got simulated an online server.

  1. Every request take [0,50) ~25 millseconds when clock is in first 30 second of minute and [50–100) ~75 millisecond in final 30 second of a minute.
  2. This simulates a state of affairs the place we’ve got sudden variation in latencies from a downstream service. We need to maintain our throughput in test in order to not enhance wait instances for any activity

Right here is the results of simulation. We’re monitoring 3 metrics each 100 millisecond interval

  1. accomplished activity: It’s the yellow line and it tries to intently comply with orange line as we need to full submitted activity as quickly as doable.
  2. active-actors: It’s the blue line and reveals variety of lively actor which the system wants to have the ability to present brief wait time for a activity. Variety of actors will increase when activity latencies enhance as we require extra actors to achive comparable throughput.


  1. At about 30 second mark latencies elevated from ~25 milliseconds to ~75 milliseconds
  2. accomplished metric dropped as with present actors we are able to now not course of comparable variety of duties.
  3. auto scalar notices elevated queue measurement and begins growing actors which stabalises round 30 actors
  4. We return to unique state round 60 second mark when latencies drops again to ~25 millsecond.

More Posts