views:

130

answers:

2

Dear Programmers,

When my Application face a long-time process, i.e fetch a query (SELECT a, b, c FROM d) This query needs 10 seconds to be completed in the MSSQL Management Studio, but when the ASP.NET application try to fetch it, it refuse to return any response to any other requests made on that Server.

I am hosting my Application on VPS Server with good specifications, and I am giving this example the (SELECT a, b, c FROM d) just to tell you the issue, it can be any process, maybe processing a movie, or even fetching some data through external API that is experiencing some slow-down,or whatever.

Any help or suggestions would be highly appreciated.

A: 

i highly recommend that you familiarize yourself with Sql Profiler that comes with Sql Server Studio.

Launch it, and see what goes to/from your sql server and for how long.

do you get any exceptions back or just timeout?

can you step through the code?

is it a local server (your machine) or some other machine? (possible could be network connectivity issues)

Sonic Soul
Thank you so much for your quick answer.My idea was not SQL Itself, that was just example, I never had such an SQL, I am talking about any type of process that takes long time.Just like when someone request a Data from external resources that resides outside the hosting Server, i.e RSS Feed consuming.
Ammar
sure, but as of now, i am still not sure what exactly takes so long. that is why i asked those questions to narrow down possible causes
Sonic Soul
@Sonic Soul There are many possibilities of getting long time of processing.One of them is Video Processing (My Current Project), and of course getting Data from external Websites or resources just like RSS Consuming and Saving, and so many other things. If that RSS would take long time, your User will see dead website until that process will end, and that's what I am trying to avoid !
Ammar
i just pointed out some ways to narrow down what is causing the lag. trying to give you ideas in how to troubleshoot this thing
Sonic Soul
+1  A: 

When you make a call on a page, then this page is use one of the application pool to get the data. If this call is make 10 seconds to complete then this pool is stack on this request.

To avoid this stop, I can suggest some ways.

  1. You can use more than one application pool. How ever in this case you going to face some other problems and for solve them you must use mutex in some parts of your program, because you going to face muthithread synchronize issues,

  2. You can use threads to run paraller with the page, and make a thread process, and release the page, and then make some refress to get the results... or make any other thread tricks to release the pool from processing.

  3. You can optimize your sql 10 seconds to run somthing is too much time. In my programs the only routing that take this time to compliete is some statistics calculations. I make them run on background, cache the results, and then just show the results when they request for.

Hope this help you.

Aristos
I can't say more than Thanks very much.You got my point exactly, and I was doing some researches in the past few days about cons and pros of the ASP.NET Threading, would you please explain me more about the (Mutex) you mentioned above ?Once again, thanks a alot.
Ammar
@Ammar If you setup more than 2 pools on your asp.net, then very easy 2 diferent threads access the same part of code at the same time. For example let say that you calculate the value of A, and this take 3 seconds and then you save it to database. You need a mutex so only one pool make the calculation, or else you maybe have 2 pool make the same thinks at the same time. So there you need to synchronize it and the only way is the mutex. Search about them on inet/MSDN to find some examples.
Aristos