BlazorWorker icon indicating copy to clipboard operation
BlazorWorker copied to clipboard

Understanding Worker and BackgroundService instances

Open Matheos96 opened this issue 5 months ago • 6 comments

I have a few questions regarding the use of IWorker instances and IWorkerBackgroundService instances.

  1. Having created a background service for on a Worker instance, is there any point in keeping the worker instance around? Can I for example spawn multiple BackgroundServices from the same Worker instance? If so, I suppose they can only run once at a time, since they are on the same Worker?
  2. Is diposing of the IWorker instance sufficient or do I separately need to dispose of the IWorkerBackgroundServices? (BTW is there an actual need for disposing workers in practise?)
  3. If Workers and BackgroundServices are always a 1-1 relationship, why not allow creating a Background service through a factory method which also implicitly creates a Worker? Just a thought with a lot of "ifs"...

Had high hopes to improve performance in our application using workers but I am starting to see some of the limitations really becoming problems. For example, the cost of serialization + deserialization to pass data may at times overweigh the benefit of doing calculations in parallel, probably depending on the complexitiy of the task. I got some PoC code working with our app but managed to decrease performance by quite a lot... I guess due to massive amounts of serialization work as well as unability to utilize our cache well enough (as it would be global and workers cannot access global things)

Matheos96 avatar Feb 13 '24 21:02 Matheos96