server长时间运行query,Ajax刷新被block
最近有个asp.net程序,需要长时间查 询数据库,千万级,且经常有reports同时运行,所以搞不好一个submit就要等1,2个小时。我把sql timeout设成无限,http request timeout设成12个小时,但是不知为什么在production server上总是运行了1.5小时后就出现page can not be displayed,后台的query则还在运行。但是在我的desktop上运行就没问题,3,4个小时也可以return results.
OK,那就想办法吧,谁叫那是production server呢。
第一个想到的当然是创建extra thread,把那个query放到后台的thread里去,查了查资料,用正规的async thread来做好像有点麻烦。因为是page can not be displayed error, 于是想到如果client page能够时时的联系一下server,估计就不会time out.于是就有了第一个方案。
1) create a web page with 2 frames. One is the real aspx page which will do the quer, the other one is just a dummy page that will refresh itself every, say, 1 minute. Well, it does not turn out to be very successful. The dummy refreshing page actually will stop the query aspx page for some unknown reason. So, solution #1 failed.
Then I thought about AJAX. Maybe I can use ajax to keeping talking to the server, while leaving the database query running.
2) find a quick ajax for asp.net 1.1 sample, set the javascript setTimeou() to 1 minute, and use ajax to get the current time from the server every 1 minute. Then, I got the problem as the title of this article: The ajax remote call is blocked when the long running query is running. Not sure how that happens, my guess is the long running query makes the browser TCP client thread busy waiting, and therefore it can not send another ajax request to the server. But anyway, that totally defeats my purpose to use ajax. Maybe there is another way to correctly apply ajax in this situation, but I do not think I have the time to find that out. Solution #2 failed too.
(updated: I tried ajax.net http://www.cnblogs.com/nihgwu/archive/2006/06/04/417161.html and it works, so I am going to stick with Solution #2)
3) Now, I have to go back to the multithreading way in asp.net. Fortunately, it looks like the traditional threading model still works on asp.net, so I do not have to use async thread. I am going to do this tomorrow, it looks doable after a small test, the only problem is I can not use windows integrated security to logon SQL server in the new thread. The thread's execution account is really wierd. It becomes Domain\Machinename$. Never seen that account before. So I have to use SQL server authentication instead.
(This is just to record something I encountered. And I find I am so slow typing Chinese so I switched to English.)
OK,那就想办法吧,谁叫那是production server呢。
第一个想到的当然是创建extra thread,把那个query放到后台的thread里去,查了查资料,用正规的async thread来做好像有点麻烦。因为是page can not be displayed error, 于是想到如果client page能够时时的联系一下server,估计就不会time out.于是就有了第一个方案。
1) create a web page with 2 frames. One is the real aspx page which will do the quer, the other one is just a dummy page that will refresh itself every, say, 1 minute. Well, it does not turn out to be very successful. The dummy refreshing page actually will stop the query aspx page for some unknown reason. So, solution #1 failed.
Then I thought about AJAX. Maybe I can use ajax to keeping talking to the server, while leaving the database query running.
2) find a quick ajax for asp.net 1.1 sample, set the javascript setTimeou() to 1 minute, and use ajax to get the current time from the server every 1 minute. Then, I got the problem as the title of this article: The ajax remote call is blocked when the long running query is running. Not sure how that happens, my guess is the long running query makes the browser TCP client thread busy waiting, and therefore it can not send another ajax request to the server. But anyway, that totally defeats my purpose to use ajax. Maybe there is another way to correctly apply ajax in this situation, but I do not think I have the time to find that out. Solution #2 failed too.
(updated: I tried ajax.net http://www.cnblogs.com/nihgwu/archive/2006/06/04/417161.html and it works, so I am going to stick with Solution #2)
3) Now, I have to go back to the multithreading way in asp.net. Fortunately, it looks like the traditional threading model still works on asp.net, so I do not have to use async thread. I am going to do this tomorrow, it looks doable after a small test, the only problem is I can not use windows integrated security to logon SQL server in the new thread. The thread's execution account is really wierd. It becomes Domain\Machinename$. Never seen that account before. So I have to use SQL server authentication instead.
(This is just to record something I encountered. And I find I am so slow typing Chinese so I switched to English.)