A client page uses javascript to post multipart form data (files) to my ASP.NET site (ashx handler).
User selects several files and start a concurrent upload. When files are like 150MB+, this generates several concurrent POST handlers of the ASP.NET server side.
I have the session control implemented, along with captcha functionality to exactly know if it is not a bot flooding my server.
But the problem is with the initial upload start.
Each time a handler is to process a POST
, it checks an ID of the session (my custom session, one per user page), and adds the Request.ContentLength
size to the total size of files POST
ed per session. This data is saved to an XML.
But since several initial posts occur simultaneously, an XML writer that records the sum of bytes "chokes" and reports 0 bytes per session for all initial POST
s, since they come in at the same time.
I've implemented lock
on my persister
object (that does XML-writing), but now until one POST is totally processed, others can't go on.
Also even though I don't do anything with the requests that come in "after the upload limit", they still take time to upload the data to the server.
So my questions are:
What is the correct pattern to process several concurrent POST
uploads?
Is there a way to immediately drop POST as soon as the request is filtered in ASP.NET handler code, and save the client an effort of uploading the data to IIS?
UPDATE: When lock
ing only on XML writing/max session length calculation I still have the concurrency, which is good. Now I only need to figure out how to drop session immediately from ashx handler code.
The answer is that when ASP.NET see two or more requests from the same user( by checking their SessionID) and session is marked with both Read and Write, then it will execute the first request and queue all other requests such that only one request will execute from the same user at the same time.
Number of concurrent requests exceeded the limit of 52. Client applications are not limited to sending requests individually in succession. The client may apply parallel programming patterns or various methods to send multiple requests simultaneously.
ASP.NET Core apps should be designed to process many requests simultaneously. Asynchronous APIs allow a small pool of threads to handle thousands of concurrent requests by not waiting on blocking calls. Rather than waiting on a long-running synchronous task to complete, the thread can work on another request.
Is your ashx handler written to execute asynchronously? If not, this a great article for implementing async ashx handlers:
http://msdn.microsoft.com/en-us/magazine/cc163463.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With