Cuncurrent web method WS
I'm work in IT organization, and have an interesting task: create e web service for integrate two several systems.
In short-word, my problem is that web service must use an object with global scope. All requests from first system, will be satisfied from a web method that will use an object shared for read and write operation.
I'Have synchronized the access to this object how follow:
1) i create in global.asax a static istance of this object in web service application start function, and a generical static object for synchcronize the first object.
2) in web method called from request, whenever have requested access to the global object, i use the Monitor instrument for synchronize the access to this object, how in this example:
in this point i must use a global object
Monitor.Enter(Static global object)
reset static global object
use static global object
Monitor.Exit(Static global object)
I create a multithreading client and execute fifty parallel thread that does the request. In this test, i' dont find a synchronization problem, BUT i'm not sure! I see that in the critical area the thread behavior is sequenzial.
The necessity of create only global object is, the critical time for instanziate the object, 5 secondi.
My problems are the follow:
1)Is correct syncronized a web method with monitor, or i must use a mutex, in short monitor grant me the synch?
2)In the case above, to kill the sequenzial behaviour of threads, i must implement a pool of object, with the same global logic?
4)IIS create an appdomain for all request or not?this is importante why the use of monitor or mutex
Sorry for english, i wait answers thank you Vito!
- for first answer, i just know the Monitor behavior. I'want know if Monior are used in following context, please listen.
Principal entity of context, web service sirÂ¨Â¬te:
- web service ws
- static global object in cache MATRIX
- static global object in cache called SYNCH
- monior or (this my enigma) Mutex
Clients performe a soap action request, calling a specific web method. Calling WM.
WM behaviour: WM with monitor object lock the SYNCH object, and execute some operation on global object MATRIX.
And at the End relase SYNCH. like this, the suspended request can start.
This WM don't start other thread, i suppose that web service starts a thread for every request.
IMPORTANT: Difference with mutex and monitor:
At the operating-system level, there
are three kernel objectsÂ¡ÂªMutex, Semaphore, and Event
For example, using a Mutex to synchronize your threads instead of a Monitor is about 33 times slower (as pointed out by Jeffrey Richter in his book CLR via C#, mentioned earlier in this chapter). Even
though these kernel objects come with additional overhead, they allow you to perform synchronization tasks that are impossible with the Monitor and ReaderWriterLock classes:
Â¡Ã¶ A Mutex allows synchronization (like a lock) across AppDomain and process
It's really that web service start a thread for every request? In this case, this threads are in only AppDomain or boundary process? I synchronized with monitor or i must use a Mutex, becouse the mutex is kernel object, across the process?
sorry for english bey , i waiting Vito...