2017-03-16 1 views
0

이 질문에 대한 답변이 이미 여러 번 나왔지만 불행히도 나를위한 답변이 없습니다.WebClient.DownloadString()이 반복적으로 다운로드 속도가 느려집니다.

나는 WebClient.DownloadString()을 사용하고 있으며 실행 속도가 매우 느리다. WebClient.Proxy를 null로 설정하려고 시도했으며 GlobalProxySelection.GetEmptyWebProxy()가 작동하지 않았다. 인터넷 속도. 내가 도대체 ​​뭘 잘못하고있는 겁니까? 브라우저 URL에 URL을 호출하는 동안

public partial class WebForm1 : System.Web.UI.Page 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 
     var res = GetData("tp"); 
     ShowData(res); 
     res = GetData("nl"); 
     ShowData(res); 
     res = GetData("sp"); 
     ShowData(res); 
     res = GetData("en"); 
     ShowData(res); 
     res = GetData("in"); 
     ShowData(res); 
     res = GetData("st"); 
     ShowData(res); 
     res = GetData("sh"); 
     ShowData(res); 
     res = GetData("fl"); 
     ShowData(res); 
     res = GetData("ce"); 
     ShowData(res); 
    } 

    public IEnumerable<object> GetData(string playListName) 
    { 
     try 
     { 
      String url = string.Empty; 
      string jsonStr = string.Empty; 

      if (playListName == "tp") 
       url = "https://content.jwplatform.com/feeds/wDg7QXiZ.json"; 
      else if (playListName == "nl") 
       url = "https://content.jwplatform.com/feeds/ZluqvHh7.json"; 
      else if (playListName == "sp") 
       url = "https://content.jwplatform.com/feeds/CqjyIXVZ.json"; 
      else if (playListName == "en") 
       url = "https://content.jwplatform.com/feeds/FEvaC7IT.json"; 
      else if (playListName == "in") 
       url = "https://content.jwplatform.com/feeds/7HSiwnEm.json"; 
      else if (playListName == "st") 
       url = "https://content.jwplatform.com/feeds/ioE6BWAD.json"; 
      else if (playListName == "sh") 
       url = "https://content.jwplatform.com/feeds/XHZFlpw1.json"; 
      else if (playListName == "fl") 
       url = "https://content.jwplatform.com/feeds/N2gtCgnE.json"; 
      else if (playListName == "ce") 
       url = "https://content.jwplatform.com/feeds/Lw3otpHB.json"; 
      else 
       url = string.Empty; 

      using (var webClient = new WebClient()) 
      { 
       webClient.Proxy = null; // not working 
       //webClient.Proxy = GlobalProxySelection.GetEmptyWebProxy(); // not working 
       jsonStr = webClient.DownloadString(url); // take 8 to 10 seconds 
      } 
      return jsonStr; 
     } 
     catch (Exception) { return null; } 
    } 
} 

입니다 (코드의 더 넓은 맥락에서 찾고 모니터링 그것으로 탐구하지 않고 속도 저하의 주요 원인이 무엇인지 정확히 알려

+1

프록시 측면이 속도 측면과 어떤 관련이 있는지, 또는 다른 방법으로 데이터를 검색하는 속도 (예 : 브라우저)를 테스트했는지 여부는 분명하지 않습니다. 어쩌면 서버가 느린 것일까 요? –

답변

1

하드 잘 작동 네트워크 및 \ 또는 응용 프로그램 프로파일 링). 여러 통화 HttpClient를 사용할 수있는 경우

  1. 다음은 성능을 향상시킬 수 있습니다

    은 도움이 될 수 있습니다 내가 그 생각을 수있는 몇 가지가 일반적으로 고 말했다 가졌어요. 최고의 성능을 얻으려면 weblient와 달리 Httpclient의 동일한 인스턴스를 다시 사용해야합니다 (DNS 조회와 같은 요청을 저장할 수 있음).
  2. 많은 요청이 병렬로 실행되는 경우 .net은 병렬로 최대 두 개의 요청을 실행할 수 있습니다. 엔드 포인트에 대한 연결 한계를 구성하여이를 변경할 수 있습니다. 경우

  3. 이 가능합니다 그리고 당신은 당신이 수축 또는 gzip을 콘텐츠 형식 제외시켰다 위해 httpclienthandler automaticDecompression 속성을 설정할 수 있습니다 아직 구성하지 않았다. 이렇게하면 서버가 메시지를 압축하여 페이지로 다시 보내기 전에 서버가 지원할 수 있습니다.

네트워크 문제 또는 엔드 포인트 조절과 같이 문제가 밤 어딘가에 있다는 것을 명심하십시오.

관련 문제