0

I am working on a ASP.net application, which basically use huge excel document to do some calculations and finally extract the output from excel to the page. The normal excel document size could be more than 15 MB. So i am forced to put a limit at the application that it should serve only 5 users at one point of time (To keep the memory usage under control so that other web applications run on same server will not get affected). Hence all other users has to wait in a queue to get served. The Excel used for calculation is Cached in the server and when a new request come, the application will clone the cached excel and use that for calculation. Once the calculation is done, the used excel is disposed. (I can't reuse the excel used for other's calculation)

So my question is "How can we put a limit to the excel usage ?". This limit should be application wide (not session wide).

KBBWrite
  • 4,373
  • 2
  • 20
  • 22

2 Answers2

1

You can create a application level shared variable (either using static variable or using Application State) to keep the count of calculation in progress. Don't forget about the locking while modifying the shared state - I will personally prefer the static variable with Interlocked methods for providing thread-safety.

On the different note, I would actually design the solution differently. Because excel based calculation is resource heavy, I will move that part in different process (probably a windows service). Will probably host WCF in this process to accept calculation requests (note request submital can be done in many ways - putting a request file at some folder or inserting row into database table etc). Any kind of throttling will be put into this process. The ASP.NET application will pass the request to this service and update user about the results asynchronously.

VinayC
  • 47,395
  • 5
  • 59
  • 72
  • Thank, now i have used exactly same, but looking to hear is there any better way of doing it. – KBBWrite Nov 16 '11 at 11:51
  • @KBBWrite, as marked in the edit, I would out-source the calculation task to different process/service. The main advantage is web app remains unaffected and the task service (calculation part) can be scaled independently (say you run it on multiple servers). – VinayC Nov 16 '11 at 11:56
  • Yes, that is a perfect way of doing it. But client is not really willing to host Windows service in server, unless the turn around time of the request can't be really meet in stress test. So I am in a kind of R&D to test it with ASP.net first. – KBBWrite Nov 16 '11 at 12:01
  • To do a performance comparison, I am doing a WCF Windows service approach too. – KBBWrite Nov 16 '11 at 14:00
  • @KBBWrite, you can host WCF services in web application or WAS (if available) - just make sure that app-pool serving this web app is different. Although, its not the best hosting scenario, you would solve your problem. – VinayC Nov 17 '11 at 04:19
0

If I am trying to limit access to a resource, then I usually implement the object pool pattern. This question is a great reference for it.

Community
  • 1
  • 1
starskythehutch
  • 3,328
  • 1
  • 25
  • 35
  • thanks, Since the resource once i created is not reusing, is it worth using the Object pool patters? – KBBWrite Nov 16 '11 at 11:49