什么是产卵数据库IO线程在ASMX Web服务的正确方法? [英] what is the right way to spawn thread for database IO in asmx web service?

查看:297
本文介绍了什么是产卵数据库IO线程在ASMX Web服务的正确方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个方法很短的锁保护区(供应完全的​​要求),使所有的初始化(日志等相关)。因此,只有1线程可以在时间在那里。在这一部分,我如果不装也从加载数据库系统的数据。这自然是只在1日要求执行,也无所谓它需要时间,没有线程可以传播,因为它做一次(由假人要求)。

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 this section I also load system data from database if not loaded. This is naturally executed only on 1st request and it does not matter it takes time and no threads can propagate since it's done only once (by dummy request).


    static public void LoadAllSystemData()
    {
        SystemData newData = new SystemData(); //own type (etc. Hashtables in Hashtables).
        LoadTables(ref newData);
        LoadClasses(ref newData);
        LoadAllSysDescrs(ref newData);
        LoadFatFields(ref newData);
        LoadAllFields(ref newData);
        _allData = newData;
    }

锁把守节过后系统数据从并发线程只能通过读取访问,并且不需要锁:

After the lock-guarded section the system data is accessed from concurrent threads only by reading and no locks are needed:


    static public Hashtable GetTables()
    {
        return _allData.Tables;
    }

现在的锁保护部分必须有方法来检查,如果系统中的数据是超过24h老年人和刷新。如果它只是通过调用方法(从锁保护部分)该线程做以下需要很长的时间,没有其他线程可以进入锁保护部分。

Now the lock guarded section must have method that checks if system data is older than 24h and refresh it. If it done just by calling method (from lock guarded section) below that thread takes a long time and no other thread can enter the lock guarded section.


   static public void CheckStatus()
   {
       DateTime timeStamp = DateTime.Now;
       TimeSpan span = timeStamp.Subtract(_cacheTimeStamp);
       if (span.Hours >= 24)
       {
           LoadAllSystemData();
           _cacheTimeStamp = DateTime.Now;
       }
    }

我的问题是:


  1. 如何产卵处理IO非线程池线程最好的方法使线程池工作线程可以传播,所有的线程花最少的时间在锁保护节?

  1. How to spawn a non-threadpool thread best way to handle IO so the threadpool worker thread can propagate and all the threads spend minimum time in lock guarded section?

是_allData = newData;在LoadAllSystemData原子?如果是,那感觉,以实现像这样的getXxx的getTables的方法不需要任何锁定的最佳途径!

Is the _allData = newData; in LoadAllSystemData atomic? If it is, it feels the best way to implement that so GetXxx-methods like GetTables do not need any locking!

有没有什么办法让LoadAllSystemData请求之前被调用?例如在IISRESET?

Is there any way to get LoadAllSystemData to be called before requests? For example on iisreset?

在此先感谢您的回答!

Thanks in advance for your answers!

推荐答案

马蒂,你问指向的最佳结构为你的应用程序的多个问题。我会总结你的问题:

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


  • 如何通过我的服务需要处理任何合法的请求之前,我pre-负荷数据?

  • 如何确保pre加载数据被载入曾经?

  • 如何刷​​新时间表的pre-加载的数据,即每24小时?

了解Asp.Net管道和事件结构将帮助你了解这些问题的答案。

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

首先,Asp.Net管道的Application_Start提供一次性执行区。这是每个应用程序周期触发一次。这也将触发在'IISRESET',它的周期每一个应用程序对于一个给定的服务器。然而,应用程序循环本身将回收自己的基础上,其配置。所有这一切,都是通过IIS设置控制。

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.

二,Asp.Net是一个请求体系;它不会触发刷新事件你,也不是你可以用它本身作为一个调度器。你需要一个外部代理作用于你们。

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. 您的pre-数据加载程序添加到的Application_Start。

  2. 配置您的网站的应用周期设置每24小时。

这将确保您的数据加载一次通过的Application_Start。这将确保你的数据你的网站提供的任何请求之前加载。最后,它会确保你的数据是每24小时刷新一次。

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. pre-数据加载程序添加到的Application_Start。

  2. 修改pre-加载的数据日常使用Asp.Net缓存,而不是静态的使用。

  3. 修改查找数据检索缓存,并重新加载数据,如果数据没有找到。

  4. 诊断/监控系统,提供能力即Nagios的,刷新通过Web方法调用,即preload_refresh()。
  5. 异步数据

此将提供基本上相同的正向效果与上述的解决方案,但为您服务更好的可靠性。

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.

这篇关于什么是产卵数据库IO线程在ASMX Web服务的正确方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆