I have a controller action that does heavy computation and takes 10 minutes or more to complete.
def timeConsumingOperation(){
}
when i request the url /application/timeConsumingOperation after sometime of waiting the browser shows timeout or service unavailable.
My question is does this timeout also stop the backend method from running or even though the connection to the server is detached, the method will run till completion in the backend? Thanks for the answer!
If this timeout is enforced solely by your browser, the operation will continue, but may fail. In particular, the response output stream will be closed and any attempts to write to it will throw exceptions.
Related
I am looking at my performance profile of one of my slowest requests, and I see an AWAIT_TIME of more than 6 seconds, but I am not able to get any more information regarding it. How do I figure out what exactly the process is "waiting on"?
From Azure's documentation:
Waiting (AWAIT_TIME)
AWAIT_TIME indicates the code is waiting for another task to complete. This typically happens with C# 'await' statement. When the code does a C# 'await', the thread unwinds and returns control to the thread-pool, and there is no thread that is blocked waiting for the 'await' to finish. However, logically the thread that did the await is 'blocked' waiting for the operation to complete. The AWAIT_TIME indicates the blocked time waiting for the task to complete.+
Blocked Time
BLOCKED_TIME indicates the code is waiting for another resource to be available, such as waiting for a synchronization object, waiting for a thread to be available, or waiting for a request to finish.
So it's waiting on something necessary to continue with processing. We have had the same problem of long AWAIT_TIME with file uploads and it turned out the request was waiting for the Request's stream to be read (ReadAsMultiPartAsync() for us)... If you look at the code in RecASPRequest and _RtlUserThreadStart, you'll probably the culprit...
We are working on a billing invoice system. As a part of processing our request, we need to make an asynchronous call by placing a message in a queue. We work at 20TPS and have SLA for entire transaction of 12 sec. Occasionally, we have observed that when MQ server becomes very slow but still operational it's taking a lot of time just to write the message in the queue. We want to handle this scenario and have a system that throws an exception when it exceeds a predefined limit for writing the message in the queue.
In simple words, we want to implement a write timeout when there is a delay in writing a message in the queue. Any help is appreciated.
We are aware of mentioning timeout for receiving the response but we are unable to find any fix for mentioning timeout while writing the message in the queue.
We have found some suggestions on revalidating the destination. But in our case, we already know the destination is operational and our system becomes slow only during the response.
I Have a quick question about async Controller and Actions in ASP.Net MVC 4+ (using the async/await programming model returning a Task ).
What do i risk if all my actions are async even if the underline operations are not IO Bound (for example slow web service or network communication ) and can be CPU Bound. I mean all my actions will be async no matter what code is int it . I Hope i'am clear.
Will be performance problems due to synchronisation context overhead or any other significant overhead for a public website that can have a lot of simultanous users ?
Thank you for your futur answers.
What do i risk if all my actions are async even if the underline operations are not IO Bound (for example slow web service or network communication ) and can be CPU Bound.
This is exactly what you don't want to do.
Consider what happens with a synchronous action: the request comes in, ASP.NET allocates a thread for that request, and that thread executes the action. When the action is complete, that same thread sends the response.
Now consider what happens if you "offload" an action's CPU-bound work to the thread pool (e.g., Task.Run). The request comes in, ASP.NET allocates a thread for that request, and the thread starts executing the action. When the thread hits Task.Run, it allocates another thread from the thread pool to execute the CPU-bound code. Then the asynchronous action method hits the await for that task, so the original thread is returned to the ASP.NET runtime. The other thread then finishes the work and continues on to send the response.
So, you're doing more work for every request if you have an asynchronous action that pushes CPU-bound work to the thread pool. You should never do this on ASP.NET.
I explain this in more detail on my blog.
I don't think you will run into any problems for a simple app since the async workers are running off a pool of threads with a limit number of threads. But what you may run into is a condition where the client HTTP threads are waiting on the asyn response and it exceeds a network gateway timeout. For instance, amazon ELB have a 60 second timeout. So clients can be disconnected while the async task is still running. If that happens a lot then you could end up with a lot of async tasks running and completing with no client to respond to. That would be an unfortunate condition because your clients are not getting data and your server is working for nothing.
One thing I would consider is whether or not you need async calls. I would suggest tuning up your service calls and making sure they are fast enough to address load instead of making the front end async as a workaround for the latency. For instance, using caching. Just a suggestion.
Hope it helps.
I have problem suspending the current task being executed, I have tried to set NSOperationQueue setSuspended=YES for pausing and setSuspended=NO for resuming the process.
According to apple docs I can not suspend already executing task.
If you want to issue a temporary halt to the execution of operations, you can suspend the corresponding operation queue using the setSuspended: method. Suspending a queue does not cause already executing operations to pause in the middle of their tasks. It simply prevents new operations from being scheduled for execution. You might suspend a queue in response to a user request to pause any ongoing work, because the expectation is that the user might eventually want to resume that work.
My app needs to suspend the time taking upload operation in case of internet unavailability and finally resume the same operation once internet is available. Is there any work around for this? or I just need to start the currently executing task from zero?
I think you need to start from zero. otherwise two problems will come there. If you resume the current uploading you cant assure that you are not missed any packets or not. At the same time if the connection available after a long period of time, server may delete the data that you uploaded previously because of the incomplete operation.
Whether or not you can resume or pause a operation queue is not your issue here...
If it worked like you imagined it could (and it doesn't) when you get back to servicing the TCP connection it may very well be in a bad state, it could have timed out, closed remotely...
you will want to find out what your server supports and use the parts of a REST (or similar) service to resume a stalled upload on a brand new fresh connection.
If you haven't yet, print out this and put it on the walls of your cube, make t-shirts for your family members to wear... maybe add it as a screensaver?
Here is what I do in a controller action:
create and start a new Thread that does a relatively long processing task (~30 seconds on average, but might be several minutes)
immediately return the page response so the user knows processing has started (trivially, a Json with a task ID for polling purposes).
At some random point, ThreadAbortException is thrown, so the async task does not complete. The exception is not thrown every time, it just happens randomly roughly 25% of the times.
Points to note:
I'm not calling Response.End or Response.Redirect - there isn't even a request running when the exception is thrown
I tried using ThreadPool and I got the same behavior
I know running threads in ASP.NET has several caveats but I don't care right now
Any suggestion?
The problem is you shouldn't do it this way. If you need a task to run for a long period of time in the background ASP.Net should either spawn a process to handle it or add the work item to a queue for a Windows Service to handle.
Does this help since you want to fire and forget.
"Delegates provide a method called BeginInvoke that allows us to call the delegate asychronously."
http://hackingon.net/post/Asynchronous-fire-and-forget-method-calls-in-NET.aspx
How about using an Asynchronous controller?
The problem was that the app was being recycled. I perfectly know that when that happens, all threads are aborted, I didn't expect the application to recycle. The reason is that the async process used changed temp files stored in the app root, and that caused a recycle.
I feel dumb.