views:

250

answers:

9

Hi All,

I looking into the concept of queueing for web apps (i.e. putting some types of job in a queue for completion by a seperate worker, rather than being completed in the web request cycle).

I would like to know if there are any good solutions existing for this which can be utilised in an ASP.NET MVC environemnt.

Has anyone had any (good or bad) experiences?

Thank you!

UPDATE:

Just to clarify, I'm not talking about queueing incoming requests. I'll try to illustrate what I mean...

1) Standard situation:

  • Request from browser
  • Server processing starts
  • Long job starts
  • Long job finished
  • Server processing finished
  • Response returned to browser

2) What I'm looking into:

  • Requsest from browser
  • Server processing starts
  • Long job placed in queue
  • Server processing finished
  • Response returned to browser

And in another process (possibly after the response was sent):

  • Long job taken from queue
  • Long job starts
  • Long job finished

In the first instance the user has waited a long time for server resoponse, in the second it was quick.

Of course there are certain types of jobs that would be appropriate for this, some that would not be.

UPDATE2:

The client doesn't have to be updated immediately with the results of the long job. The changes would just show themselves in the application whenever the user happened to refresh a page (after the job had completed of course).

Think of some of the things that happen in stack overflow - they are not immediately updated in each part of the application, but this happends quite quickly - I suspect some of these jobs are being queued.

A: 

You might want to check out article about asynchronous requests.

Can't tell much more - haven't tried yet. :/

Arnis L.
I don't think it's really what I'm looking for - it looks like the response is still not sent until the async job has finidhed. But it looks interesting - I'll take a propper read through it later. Thanks!
UpTheCreek
A: 

I think Chrisitan's comment might be your answer, but considering I don't know much about IIS and queueing with it, my solution would be:

Make an asynchronous request and load the job details in the database. Then have a job to loop through the database and process the job details. I do this for one of my sites. Might not be the best solution out there, but it gets the job done.

EDIT

My answer might still work, but you will need to have some polling mechanism on the client to continuously check the database to see if that user's job is done, then grab the data you need.

Martin
No, Christian's comment is not my answer ;)I've considered the 'roll your own using the DB' route, but I'm looking for something a little more rebust and built for purpose. I don't want to re-invent the wheel (mine would probably not be perfectly round ;)
UpTheCreek
Just to clarify re edit - the client would not need to be updated as to the results of the job so no polling would be required.
UpTheCreek
+1  A: 

You might check into using an ESB. I've played around with MassTransit: http://code.google.com/p/masstransit/ - the documentation is (or at least was) a little sparse, but it's easy to implement.

In addition, I develop apps for running on Amazon EC2 and absolutely love their AmazonSQS Service.

Thanks,

Hal

Hal
I'll check Mass Transit out - I notice it's built on MSMQ. An equivalent of somehting like Amazon SQS is probably what I'm looking - Thanks.
UpTheCreek
+4  A: 

Post the job data in an MSMQ queue and have a Windows Service process the items in the queue. Or, let the web request spawn a process that process the items in the queue.

Magnus Johansson
This is a little more low level than I was thinking, but maybe I'm looking at it in the wrong way - I don't have any MSMQ skills, but I'll look into it - thanks.
UpTheCreek
+2  A: 

The Rhino Service Bus is another solution that may work for you:
http://ayende.com/Blog/archive/2008/12/17/rhino-service-bus.aspx

Joel Martinez
Thanks - I'll check it out. I've enjoyed reading Ayende's posts on other subjects in the past :) Is this ready for production though?
UpTheCreek
I personally have never used it in production, however, I know of people that have used it in production.
Joel Martinez
A: 

have you considered MSMQ? There is nothing stopping you from using that from within MVC, and it is pretty simple to get started with.

Travis Laborde
A: 

Since you mentioned in another comment that you were looking for an equivalent to amazon's sqs service ... you might want to look into Windows Azure. They have an equivalent queue api:
http://msdn.microsoft.com/en-us/library/dd179363.aspx

Joel Martinez
A: 

I have implemented this pattern by having the web server call a WCF service asynchronously. The VS wizards will generate async proxies for you when you consume a WCF service. If you must have guaranteed delivery on the request to the service, you could use MSMQ as the transport layer for the WCF service.

Colin Desmond
+1  A: 

I'll throw my own research in here... I've been looking at NService Bus, which looks quite promising for this kind of thing - has anyone used it?

Some links:

http://www.udidahan.com/2008/07/30/scaling-long-running-web-services/

http://www.hanselminutes.com/default.aspx?showID=194

http://sourceforge.net/apps/mediawiki/nservicebus/index.php?title=Main_Page

UpTheCreek