0

Considering the future need for greater scalability (assuming usage will increase), wouldn't it make sense at the start of development of a new application to use Async for all actions?

  • Does it make sense for both get's (that mostly return View's) and post's (that will perform some storage/update and return a jsonresult)?
  • All post's will be using Jquery AJAX, will this 'double async' work?
user2713516
  • 2,983
  • 5
  • 23
  • 49
  • Possible duplicate of [how to and when use \`async\` and \`await\`](http://stackoverflow.com/questions/14455293/how-to-and-when-use-async-and-await) – kayess Nov 23 '15 at 13:25
  • Using async operations has some overhead and should be used when needed not just for the sake of using them. If you are returning a simple view it is probably not needed. If the view does some heavy work before being displayed you should consider using async. Using async from ajax isn't really a double async and yes it will work. – Stephen Brickner Nov 23 '15 at 13:25
  • Interesting Link about this topic: http://blog.stevensanderson.com/2010/01/25/measuring-the-performance-of-asynchronous-controllers/ – Xavier Egea Nov 23 '15 at 13:27

2 Answers2

3

Does the action actually do something that benefits from asynchronous use in any way?

If it does, even slightly, by for example hitting file I/O (using async) a database (using async) or a webservice (using async) then it can be worth doing.

If it's just CPU bound then it will make things slightly worth (async is not free) and gain nothing.

It's also worth noting that if you change an action from being async to non-async or vice versa, the code change can be local, so there's no real value to "we might need to in the future". If you have an action that e.g. right now is just returning a view with no other work (no value in async) and then later change it to hit a database (value in async) then you can just change to async then, it won't be a complicated change.

All post's will be using Jquery AJAX, will this 'double async' work?

You mean, being also async in the sense that ajax is async? Completely unconnected, each can be async or not with whether the other part of the code is having zero bearing.

Jon Hanna
  • 110,372
  • 10
  • 146
  • 251
1

Javascript does not actually do anything asynchronously. You can not write an async function without using web workers. All you can do is start a process, such as fileReader, XMLHttpRequest, image/resource load, setTimeout, setInterval etc that run asynchronously. These processes are not javascript. These then place calls (events) on the call stack when required. They run on a different thread and can be said to be asynchronous to javascript, but javascript is restricted to a single thread, and can only execute one function at a time, one instruction at a time.

So inherently javascript (excluding web workers) can not be made to function asynchronously. Even the callbacks associated with events must be handled one at a time, with all so call "async" events being blocked by the currently running call. If you do not exit, the callbacks on the call stack will not be called which will eventually result in a call stack overflow.

Calling any javascript asynchronous is showing a misunderstanding of how javascript code runs. What is popularly call "async javascript" should more accurately be called "event driven" programming.

Blindman67
  • 51,134
  • 11
  • 73
  • 136