simple .net approach to share load between two application servers
This question is more of an architecture based question. I would like some solutions using .net technologies. I would also like to keep database operations to a minimum. That means I do not want too much polling of the database for statuses and such
I have two application servers (windows 2003 server based) on which I want to do some type of load balancing. For discussion we shall call it AppX1 and AppX2. The app also uses SQL Server to store and retrieve.
I have some location information to process, data for which comes from excel files. Data from the excel file will be loaded into the database first via a windows service.
I would like a simple approach where I can split processing load between the two app servers. Maybe AppX1 can be the master and AppX2 will be a slave. AppX1 can communicate to AppX2 to process certain set of loca开发者_高级运维tions. What is the best way to achieve this communication? Is WCF an option?
Once AppX2 completes it will dump information back into a database and inform AppX1. AppX1 can then send more locations to AppX2 to process.
Rather than divide your functionality across servers, I would, without knowing further/deeper details of your system, implement stateless service calls, multi-threaded behavior within the service implementation, (very easy in .NET) and a single instance/multiple concurrency service host. Then use an actual load balancer, or even just Windows NLB, to split calls across servers, serving a single call on a single server in the most efficient way possible.
I don't know how you are reading the data from the Excel files, but in principle I would do something like this:
try to exclusively open the spreadsheet for reading/writing, on error (file is already open) wait a bit before retrying the open.
read the next set of data that has not already been processed. mark this data as processed (e.g., have a "Processed" column in the spreadsheet). Save the spreadsheet and close it.
Now process the data and write the results to the database.
With this mechanism the application servers do not communicate directly with each other--the spreadsheet is used to share the work between them.
If you want to get more fancy, the Processed column in the spreadsheet could have 3 states: Not processed, Pending, and Processed. When you grab the data, you set the column to Pending, and once the results have been written to the database, you open the spreadsheet again and set the column to Processed, grabbing the next set of (Not processed) data at the same time.
精彩评论