xml地图|网站地图|网站标签 [设为首页] [加入收藏]
当前位置: 美高梅4858mgm > 娱乐八卦 > 正文

美高梅4858mgmDNS解析服务增加缓存机制

时间:2019-07-07 09:20来源:娱乐八卦
$2.19 Genres: Pop, Music Released: 26 June 2012 ℗ 2012 Universal Republic/Interscope Records, division(s) of UMGRecordings, Inc.      在此之前我们已经依照 ARSoft.Tools.Net 简简单单落成了DNS剖判模块的效果,不过

$2.19
Genres: Pop, Music
Released: 26 June 2012
℗ 2012 Universal Republic/Interscope Records, division(s) of UMG Recordings, Inc.

      在此之前我们已经依照ARSoft.Tools.Net简简单单落成了DNS剖判模块的效果,不过当质量要求提高时,每三回爬取都要拓展DNS乞请,以至很有希望一段时间内每一遍乞求的没什么不一致的地址,频仍的DNS央求就能够形成品质瓶颈,所以大家要经过缓存机制将DNS深入分析结果缓存下来,裁减DNS深入分析操作,进步系统品质。

与此相类似,我们依照在此以前封装的MemoryCacheHelper类对DnsResolver类实行改变:

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Net;
using ARSoft.Tools.Net;
using ARSoft.Tools.Net.Dns;
using Mem = Crawler.Common.MemoryCacheHelper;


namespace Crawler.Protocol { public class DnsResolver { public TimeSpan TimeSpan { get; set; } public string Url { get; set; } public ARecord Record { get; set; } public string DnsServer { get; set; } public int TimeOut { get; set; } public ReturnCode ReturnCode { get; set; } public bool IsSuccess { get; private set; } public TimeSpan TimeToLive { get; set; } public DnsResolver(string url, string dnsServer = "223.5.5.5", int timeOut = 10000) { Url = url; DnsServer = dnsServer; TimeOut = timeOut; IsSuccess = false; if (Mem.Contains(url)) Fill(Mem.Get(url)); else Dig(); }
private void Fill(DnsResolver resolver) { TimeSpan = resolver.TimeSpan; Url = resolver.Url; Record = resolver.Record; DnsServer = resolver.DnsServer; TimeOut = resolver.TimeOut; ReturnCode = resolver.ReturnCode; IsSuccess = resolver.IsSuccess; }
public void Dig() { //开端化DnsClient,第七个参数为DNS服务器的IP,第二个参数为超时时间 var dnsClient = new DnsClient(IPAddress.Parse(DnsServer), TimeOut); var s = new Stopwatch(); s.Start(); //分析域名。将域名央求发送至DNS服务器深入分析,参数为索要剖判的域名 var dnsMessage = dnsClient.Resolve(DomainName.Parse(Url)); s.Stop(); TimeSpan = s.Elapsed; //若再次回到结果为空,可能存在破绽百出,则该诉求退步。 if (dnsMessage == null || (dnsMessage.ReturnCode != ReturnCode.NoError && dnsMessage.ReturnCode != ReturnCode.NxDomain)) IsSuccess = false; //循环遍历再次回到结果,将回来的IPV4记下加多到结果集List中。 if (dnsMessage != null) { if (dnsMessage.AnswerRecords.Count > 0) { Record = dnsMessage.AnswerRecords[0] as ARecord; if (Record != null) { IsSuccess = true; TimeToLive=new TimeSpan(0,0,Record.TimeToLive); Mem.Add(Url, this, TimeToLive); } } } if (dnsMessage != null) ReturnCode = dnsMessage.ReturnCode; } } }

如此那般,每一遍做完DNS分析后,会依赖域名的TTL将分析结果缓存下来,下一次询问时方可一贯调用缓存,升高系统性子。

1 Good Time

DL: http://11'5.com/file/anc001s5

编辑:娱乐八卦 本文来源:美高梅4858mgmDNS解析服务增加缓存机制

关键词: 美高梅4858mgm