熱詞統計以及Quartz.net的簡單使用

來源:互聯網
上載者:User

標籤:參數   工作任務   new   let   simple   round   word   解決   資料庫   

一.熱詞統計

方案一:

設計一個表:ID       KeyWord     Count

當使用者再輸入框中查詢的時候,我們就往表中插入資料,在插入之前首先判斷是否已經存在keyword,存在的話,讓Count+1

這種方案非常費時

方案二:

           表 :ID      Keyword     Count

每次使用者輸入的時候直接插入,不需要判斷是否存在,當進行熱詞展示的時候,通過Group By語句進行統計

同樣比較費時

方案三:

           表一明細表:ID   Keyword

           表二匯總表:ID   KeyWord   Count

使用者每次輸入並進行查詢的時候,將資料插入到明細表中,然後使用定時任務,當使用者量訪問量比較小的時候,執行匯總操作,將資料插入到匯總表中。

這種實用性比較高

方案四:

對於使用者訪問量比較大的資料,採用關係型資料庫,速度還是太慢。可以使用NoSql資料庫,可以有效解決高並發。

二.Quartz.net(計劃工作群組件)的簡單使用

1.主要的dll檔案

2.Quartz.net的使用有兩種方式,1.採用設定檔的方式配置參數 2.直接在程式中使用代碼設定參數,此處直接使用官方的demo中的例子,並適當的修改

  static void Main(string[] args)        {            ISchedulerFactory sf = new StdSchedulerFactory();            IScheduler sched = sf.GetScheduler();            //代碼添加job和trigger            DateTimeOffset startTime = DateBuilder.NextGivenSecondDate(null, 5);            IJobDetail job = JobBuilder.Create<KeywordJob>()                .WithIdentity("job1", "group1")                .Build();            // Trigger the job to run on the next round minute            ITrigger trigger = TriggerBuilder.Create()                .WithIdentity("trigger1", "group1")                .StartAt(startTime).WithSimpleSchedule(x => x.WithIntervalInSeconds(5).RepeatForever())                .Build();            sched.ScheduleJob(job, trigger);            sched.Start();            Console.ReadLine();        }

3.Quartz.net中主要包括三個主要的對象:計劃者(IScheduler)、工作任務(IJob)和觸發器(ITrgger),我們可以在工作任務中添加我們需要定時執行的工作。

 public    class KeywordJob:IJob    {        public OA.IBLL.IKeywordCountService keywordService = new OA.BLL.KeywordCountService();        public void Execute(IJobExecutionContext context)        {            keywordService.DeleteAll();            keywordService.InsertAll();        }    }

 

熱詞統計以及Quartz.net的簡單使用

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.