what is the right way to spawn thread for database IO in asmx web service?

前端 未结 2 1932
面向向阳花
面向向阳花 2021-01-23 10:50

I have a short lock guarded section in a method (that serves the request entirely) that makes all initializations (etc. log-related). So only 1 thread can be there at time. In

2条回答
  •  南方客
    南方客 (楼主)
    2021-01-23 11:32

    Matti, you're asking multiple questions that point to the best structure for your application. I would summarize your questions as:

    • How do I pre-load data needed by my service prior to handling any legitimate requests?
    • How do I ensure the pre-loaded data is loaded "once"?
    • How do I refresh the pre-loaded data on a schedule, i.e. every 24 hours?

    Understanding the Asp.Net pipeline and event structure will help you understand the answers to these questions.

    First, the Asp.Net pipeline provides a one-time execution region in Application_Start. This is fired once per application cycle. This would also fire in 'iisreset', which cycles every application for a given server. However, application cycles themselves will recycle on their own, based on their configuration. All of which are controlled through IIS settings.

    Second, Asp.Net is a request system; it won't fire refresh events for you, nor can you use it by itself as a scheduler. You need an outside agent to act on that for you.

    Here's what you could do:

    1. Add your pre-loaded data routine to Application_Start.
    2. Configure your web site's Application cycle settings for every 24 hours.

    This would ensure your data is loaded once, via Application_Start. It would ensure your data is loaded prior to your site serving any requests. Last, it would ensure your data is refreshed every 24 hours.

    Here's what I would do:

    1. Add pre-loaded data routine to Application_Start.
    2. Modify pre-loaded data routine to use Asp.Net Cache, instead of static usage.
    3. Modify lookup data to retrieve data from cache, and re-load if data is not found.
    4. Provide capability for diagnostic/monitoring system, i.e. nagios, to refresh data asynchronously via web method call, i.e. "preload_refresh()".

    This would provide essentially the same forward effect as the above solution, but with better reliability for your service.

    As always, your mileage may vary. Hope this helps.

提交回复
热议问题