I have 3-4 related questions regarding this.
-
If Line Number X is using synchronous upload method then:-
a. How will the another request from the same user(same session) will be served for:-
-
An action method different from the _UploadStatement? – Will it be queued or served simultaneously?
-
The same action method i.e. _UploadStatement? – Will it be put into a queue or served simultaneously?
b. How will the another request from a different user(different session) will be served for:-
-
An action method different from the _UploadStatement? – Will it be queued or served simultaneously?
-
The same action method i.e. _UploadStatement? – Will it be put into a queue or served simultaneously?
-
If they are put into a queue, then that means the next user will have to wait until the first user’s upload is finished?
public class AbcController : Controller { public ActionResult A1() { return view(); } public JsonResult _UploadStatement(HttpPostedFileBase UploadedStatement) { // Some web service uploading a lengthy file received to other server (say amazon s3 storage):- // LINE NUMBER - X } }
These actions will happen in parallel. Each time IIS receives a new request, it creates a new controller, and executes that action on the new controller instance. However, each controller will execute the request using a different thread.
Only if you had code like this would user B have to wait until user A finished his upload:
Such a lock will tell the thread “hey, only one of us is allowed to execute this method at a time. Right now I have the method locked and you have to wait until I am done. When I finish I will give the lock to you, and then you can execute the method, making others wait for you to finish.”
The action method doesn’t know or care who the request originated from. If user A submitted 3 uploads, IIS would execute them all in parallel, using different threads. However it may not return results in the same order in which they were requested. For example the 2nd request may finish first, then the third, and finally the first.
What can happen though is thread starvation. Say you have 50 users each uploading 3 files at the same time. That means that at least 150 threads will be taken from the pool, which may cause other parts of your application to respond more slowly. You can look into extending from the AsyncController to help with thread starvation scenarios on tasks that are heavily I/O bound or otherwise latent because of thread blocking.