Re: Surprising threading issue
- From: "Dan Ruehle" <dan@xxxxxxxxxxxxx>
- Date: Tue, 30 Dec 2008 00:17:59 -0500
Sure, I'd be happy to. Basically, in a web farm, there are multiple machines executing your code. Each machine runs independently of the others, unless you make them aware of each other, which is rarely done. So, if you write code to limit your use of a remote web service such that the code relies on timing in a single process and that process is executing on multiple machines, you end up circumventing the logic. If you farm the application on 2 machines, you will hit the web service twice as much because they both will be running independently of each other. A web garden is a way to have IIS instantiate multiple processes to service your application, thus exposing the same situation without the need for multiple servers. To configure this, set the Max Worker Processes setting for the application pool for your site.
Clearly, the next question is how to manage this. You need to centralize something. Typically, a web application has a central database, so that is a natural start. When you make a request to the remote web server, you can record the fact that the request was made and include logic in your class to check the database before it makes a call to see if it can and if not, how long it is going to have to wait. The most straight forward design would be to create a table that will have a row per request that is to be made. Each attempt to make a request does:
1. Get the row with the highest request date/time
2. Calculate when the next allowed request date/time is (previous highest request date/time plus minimum request interval, if in the past, use current date/time)
3. Wait until the calculated next allowed request date/time arrives
4. Make the request
Of course, if your site gets overloaded, you probably want to put in some throttling logic so that if there are so many outstanding requests that it is unreasonable to expect completion any time soon (the calculated next allowed request Date/Time) is too far off in the future, just tell the user the site is too busy or something.
Two other options are to create a Windows service and using remoting to centralize access to the remote web service or create a web service that is not load balanced that does the same thing. Both of these options create single points of failure in the architecture, unless you load balance them using the same mechanism as before, so they do not make the entire solution any more robust in my opinion.
I hope this helps and is in a more "layman" language.
Regards,
Dan Ruehle
"GeezerButler" <kurtrips@xxxxxxxxx> wrote in message news:ca1e98f1-0eb8-4f50-ae4b-e2a201c4b730@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Dec 29, 10:24 am, "Dan Ruehle" <d...@xxxxxxxxxxxxx> wrote:All of this will work, but I think you are overlooking something. If you
set your Application Pool to a web garden of 2 or more processes or ever web
farm your application, using singleton or static member or whatever will not
help. You will need to serialize your use of the web service via a database
or singleton back end Windows service or web service. That may not be in
the plan now, but it will be a huge design change if required in the future.
Thanks for bringing that up however unfortunately I don't understand
most of it :(
Right now my app is on a single machine but going forward I'm going to
upgrade to this. http://www.tsohost.co.uk/clustered-hosting.php
So, does clustered hosting have something to do with what you
mentioned above?
If it does, can you elaborate in a little more layman language?
.
- References:
- Surprising threading issue
- From: GeezerButler
- Re: Surprising threading issue
- From: Peter Duniho
- Re: Surprising threading issue
- From: GeezerButler
- Re: Surprising threading issue
- From: Peter Duniho
- Re: Surprising threading issue
- From: GeezerButler
- Re: Surprising threading issue
- From: Peter Duniho
- Re: Surprising threading issue
- From: GeezerButler
- Re: Surprising threading issue
- From: Peter Duniho
- Re: Surprising threading issue
- From: GeezerButler
- Re: Surprising threading issue
- From: Dan Ruehle
- Re: Surprising threading issue
- From: GeezerButler
- Surprising threading issue
- Prev by Date: is begininvoke like CWinThread::PostThreadMessage in mfc?
- Next by Date: Re: is begininvoke like CWinThread::PostThreadMessage in mfc?
- Previous by thread: Re: Surprising threading issue
- Next by thread: Understanding Installers
- Index(es):
Relevant Pages
|