1
votes

In our service fabric application we have a service that requires keeping some data in memory during operation to optimise performance, however in some rare cases we need to clear this data.

So at some point, a call comes to this service and tells it to empty its cache. The problem arises that we may have several instances of this service, and when you call a service (from another service) in service fabric the call only ends up going to one instance. I need a to call all instances of this service.

We connect to our services (using a generic method) like so:

T service = ServiceProxy.Create<T>(serviceUri);

Is there a way to specify an instance of the service to use? Or some other way to get a message to all instances of a service?

Thanks

1
If you consider each instance to be a separate node like a load balanced set, why not keep the state data youre relying on in a reliable collection instead - then any instance can clear it, and re-reading it from the collection will be (nearly) as fast as reading from memory, but it'll be consistent across nodes.Russell Young
@RussellYoung I actually tried using a reliable collection, however Assemblies are one of the types that I need to store, and reliable collections don't seem to work with Assemblies. I tried storing as byte[] and loading the assembly when needed but this reduced performance too much. Also, I may be wrong, but with stateful services it seems to have more than 1 instance actually be used (i.e not just be a redundant replica) at a time you must partition the service, and reliable collections aren't shared across partitions?QTom

1 Answers

0
votes

This seems like a perfect use case for Service Fabric Pub/Sub. Just have all the services that need to clear their in data memory be subscribers, and then your calling service can publish the message which will broadcast to all subscribing services.

See more here: https://github.com/loekd/ServiceFabric.PubSubActors.