Memory consumption increasing linearly on creating multiple workers

Hi,

I have a piece of code that was creating a new temporal worker on every execution. (~every 5 minutes).
I soon realized that it was a bad practise to do that but I found out that creating a new worker (with same Id and queue) is causing my application to consume memory like there’s no tomorrow.

The consumption of memory in a 10 minute period went from ~50MB to 20KB once I changed the code to create only one worker.

I am curious to find out

  • Why does creating a new worker cause memory to be held like that?
  • Why is the worker not being shutdown if it wasn’t used for five minutes?
  • Which pattern out of these two is recommended?
    • One worker per workflow
    • One worker per application
  • Why does creating a new worker cause memory to be held like that?

Workers are heavy objects that use multiple goroutines and other resources. They constantly poll for work, so they are not expected to use fewer resources after any period.

  • Why is the worker not being shutdown if it wasn’t used for five minutes?

Because it was never an intention.

  • Which pattern out of these two is recommended?
  • One worker per workflow
  • One worker per application

One worker per process. You can run multiple workflow and activity types by a single worker.