Tanel
Tanel

Reputation: 314

Singleton vs PerSession vs PerCall state managment

I have a WCF Service that is transferring large files.

Currently I'm using Singleton service with list of instances from my class to hold the state and to response to the client requests for transfer progress and so on.

The instanced class itself handles new threads for each transfer when needed.

Clients who add transfer requests and request progress can disconnect meanwhile and reconnect at random time for the requests.

Also several different clients may want to request progress of all transfers that are going on.

Everything is working great as it is, but I'm sure there is better way of doing this?

Storing state somehow in SQL? Storing state as I'm currently doing and somehow reconnecting to the same instance? How to get data from all instances then?

I hope you understood my rather long question :)

Upvotes: 3

Views: 425

Answers (1)

Alexander Stepaniuk
Alexander Stepaniuk

Reputation: 6418

Yor solution would work great if there is only one instance of yor WCF service.

When you instantiate more than 1 instance with loadballancing then that approach won't work.
In such case you need to keep the state is some place which is common to all instances. It could be SQL, State server, another WCF service which could keep state, etc.

UPDATE:
You need to generate id for each file tranfer task. Then Singletone can assosiate id with instance which does transfer (let's call it Executor).
When client wants to get progress or cancel transfer then it requests Singletone and provides task id.
Singletone should use task id to resolve the actual Executor and forvard client's request to the right Executor.

As result you will be able to instantiate as many Executors as you need. Client should not worry which exactly Executor processes file. Everithing what client should know is task id.

Upvotes: 2

Related Questions