asp.net - Queuing long running tasks in a web application -
a user can perform action on our web app takes anywhere 100ms 10 seconds, wish return result browser , show results user once task has finished processing. action syncing data third party , implemented class library (dll).
normally it's suggested use queue rabbitmq or msmq , have worker writes results database polled ajax request browser check updates.
however aim reduce latency it's as close running task synchronously possible while being able handle spikes in processing long running task without affecting rest of website.
how should backend architected? in mind, process be: starting task, running task minimal latency, notifying end user task finished (asap) , displaying results in browser.

examples
generating sitemaps http://www.xml-sitemaps.com/ uses chunked transfer encoding send <script> tag every second call javascript function update page latest status.
checking ssl certificates https://www.ssllabs.com/ssltest/ seems refresh whole page updated status.
this situation relatively simple, , not recommend polling @ all.
consider using regular ajax approach: part of page able refresh without rest of page. part (ajax part) synchronous on own, asynchronous whole page's point of view (because refreshes without reloading whole page).
so, when information required calculated, ajax part of page submitted regular request. when request processing done, part of page has access response right away , displays results.
advantage don't have polling overhead, results displayed on screen right away (asap - asked). also, 1 request working on this, instead of several possibly missed requests when polling.
Comments
Post a Comment