Reputation: 16359
What is the conceptual differences in approaches for achieving asynchronism with the following technologies. My primary search was for Django, but I'm looking for a conceptual answer which describes the ideas behind the technology.
I've found tutorials on the web regarding most of these approaches, however they don't explain the concepts behind, just the technical implementation.
Upvotes: 0
Views: 103
Reputation: 966
Asynchronous programming can be quite hard to get your head around. The basic idea is a way to get around blocking IO. Blocking IO is anything from writing to a file querying a database, querying a REST API, anything that would interrupt your applications processing flow while it waits for something else to happen.
Say for example your building a Gallery application, users can upload large HD resolution images to show off. But your going to need to make various copies of this large image the user uploads, thumbnails, smaller resolution versions etc To do this requires a bit of blocking IO. You need to compress the images and thats quite intensive and once compressed you need to write those to disk, after that you might need to store all this information in your DB. To do this in one single request would result in a very slow clunky performance for your user and honestly your backend process would probably time out before it could complete all the tasks needed. It also doesn't scale very well.
One way to get around this would be to use Asynchronous programming. Once the users upload has finished you could fire various signals to other applications sat waiting just for their chance to compress an image or write data to a DB. Once that signals fired those background processes get to work, and your user doesn't have to sit and wait for a long request to complete, instead they can carry on browsing the site, have a coffee and be notified when their thumbnails have been made etc.
In the example above I would implement this using Celery, RabbitMQ and SocketIO (or maybe TornadIO). Once the users upload has completed I would fire a celery task, celery uses RabbitMQ (I prefer Redis) to manage tasks, you could have 10, 20, 30 celery workers crunching away on these image uploads in the background. Once celery has finished it's job it would fire a message to the Socket server, for handling web sockets, which the users browser is connected too. This would send the user a notification in real time that their new image they uploaded is now ready to be shared with the world
This is the really basic example around Asynchronous Event driven programming. As best I understand it anyway. Anyone else please correct me.
I hope this helps. :)
Upvotes: 2