2016-11-21 12 views
-1

Azure에서 매우 오래 실행되는 프로세스가 있습니다. 로그 또는 오류 메시지를 남기지 않고 임의의 순간에 실행이 중지됩니다. 때로는 수 시간 연속으로 실행되기도하고 때로는 몇 분만에 실행되는 경우도 있습니다. 이것은 내 로컬 PC에서 발생하지 않습니다.Azure에서는 응용 프로그램이 종료되지만 로컬 PC에서는 종료되지 않습니다.

일부 사람들은 이미 "항상 켜기"로 앱을 켜면 문제가 해결되지만 비슷한 경우에는 문제를 해결할 수 있다고 대답 한 적이 있습니다. 문제는 계속됩니다.

이 문제에 대한 다른 게시물과 WebJob을 사용하기 위해 제안 된 답변을 읽었습니다. 내 응용 프로그램이 150MB이고 WebJob의 최대 파일 크기를 초과하기 때문에 그럴 수 없습니다.

프로젝트 정보 : 제 3자가 제공 한 무거운 얼굴 감지 및 인식 알고리즘을 구현 한 것입니다. 내가 볼 수없는 모든 코드는 try 문으로 둘러싸여 있습니다.

그건 내가 함수를 호출하는 방법은 다음과 같습니다 당신의 설명으로

Task.Run(()=> loopDeReconhecimento(biometricClient, code, photosInfo,ultimoIndiceReconhecido, totalNumberOfFiles,outPutDestionation)); 


private async void loopDeReconhecimento(NBiometricClient biometricClient, string code, List<PhotoInfo> photosInfo,int ultimoIndiceReconhecido, int totalNumberOfFiles,string outPutDestionation) 
     { 
      WebClient wc = new WebClient(); 
      for (int i = ultimoIndiceReconhecido; i < totalNumberOfFiles; i++) 
      { 
       if (forceStop.Contains(code)) 
       { 
        Log.register(code, "STOPPING!!!!"); 
        forceStop.Remove(code); 
        return; 
       } 
       if (i >= photosInfo.Count) 
       { 
        i--; 
        try 
        { 
         Log.register(code, "Fim das fotos upadas por enquanto foi encontrado. Esperando trinta segundos, baixando novamente as informações e tentando de novo " + DateTime.Now.ToLongTimeString()); 
         Thread.Sleep(30000); 

         wc.DownloadFile(pathWebBase + code + @"/" + @"1.Eventos_grande_simples/imagensConfig.txt", outPutDestionation); 
         //Log.register(code,"Tempo de download: " + tempoTotal); 
         PhotoInfo.init(File.ReadAllLines(outPutDestionation), photosInfo); 
        } catch 
        { 
         Log.register(code, "Attempt to download failed. Try again in 30 seconds"); 
        } 
        continue; 
       } 
       Log.register(code, "Starting photo " + i.ToString() + " de " + totalNumberOfFiles); 


       recognizePhoto(biometricClient,wc, code, photosInfo[i], photosInfo, tentativasPorFoto); 

       status = i.ToString() + @"/" + totalNumberOfFiles.ToString(); 
       if (forceSave.Contains(code) || (double)i/salvarACadaQuantas == Math.Floor((double)i/salvarACadaQuantas)) 
       { 
        forceSave.Remove(code); 
        salvar(i, code, photosInfo); 

       } 

      } 

      Log.register(code, "Fim."); 

     } 


void recognizePhoto(NBiometricClient biometricClient,WebClient wc, string code, PhotoInfo photoInfo, List<PhotoInfo> photosInfo, int attempts) 
{ 



      try 
      { 

       Log.register(code, "Foto iniciada: " + photoInfo.shortAdress); 

       NBiometricStatus status; 

       string localPath = localPathBase + code + @"\Fotos a separar\1.Eventos_grande" + photoInfo.shortAdress; 
       Stopwatch sw = new Stopwatch(); 
       sw.Start(); 


       NSubject candidateSubject = CreateSubjectFromURL(pathWebBase + code + @"/1.Eventos_grande_simples" + photoInfo.shortAdress, true); 

       status = biometricClient.CreateTemplate(candidateSubject); 
       if (status != NBiometricStatus.Ok) 
       { 
        Log.register(code, "Template creation was unsuccessful. Status: " + status); 
        return; 
       } 
       else 
       { 
        Log.register(code, "Created: Status: " + status); 

       } 

       // Set ids to candidate subjects and related subjects 
       int i = 1; 
       candidateSubject.Id = "ID_0"; 
       Log.register(code, "Subject na foto: Status: " + candidateSubject.Id); 
       PersonTagInfo pti = detalharFace(candidateSubject, biometricClient, code); 
       if (pti != null) 
        photoInfo.peopleTags.Add(pti); 
       foreach (var subject in candidateSubject.RelatedSubjects) 
       { 
        subject.Id = string.Format("ID_{0}", i++); 
        Log.register(code, "Subject found in photo: Status: " + subject.Id); 
        pti = detalharFace(subject, biometricClient, code); 
        if (pti != null) 
         photoInfo.peopleTags.Add(pti); 

       } 


       identificarESalvarPersonTagInfo(biometricClient, photoInfo, candidateSubject, code); 
       foreach (NSubject candidato in candidateSubject.RelatedSubjects) 
       { 
        identificarESalvarPersonTagInfo(biometricClient, photoInfo, candidato, code); 
       } 

       photoInfo.done = true; 
       Log.register(code, "Tempo de processamento: " + sw.ElapsedMilliseconds); 
      } catch 
      { 
       if (attempts > 0) 
       { 
        Log.register(code, "Erro ao processar foto. Tentando novamente em 1 segundo. Tentativas restantes: " + attempts.ToString()); 

        Thread.Sleep(1000); 
        recognizePhoto(biometricClient,wc, code, photoInfo,photosInfo, attempts - 1); 

       } 

      } 





     } 
+0

당신이 오래 실행되는 프로세스가 원래 구현 (내가 MVC/WebAPI 액션의 순간에 추측하고있어) 방법과 WebJob 실행 된 방법이 무엇인지에 대한 몇 가지 세부 사항을 알려 제공 할 수 (및 종속성)은 150MB를 초과하여 관리합니다. –

+0

얼굴 인식 및 인식을 위해 타사 SDK를 사용합니다. 원래 웹 앱으로 구현되었습니다. 나는 당신이 코드를 볼 수 있도록 질문을 변경했다. – Lucas

답변

0

을, 당신은 플랫폼에 매우 긴 실행중인 프로세스가 필요합니다. 작업자 역할을 사용해보십시오. 작업자 역할은이를 채우기 위해 정의 된 역할입니다. 루프를 사용하여 작업을 처리하는 데 사용할 수 있습니다. 그리고 150M 크기가 제한되어 있지 않습니다. 또한 VM을보다 잘 제어 할 수 있습니다. 작업자 역할에 대한 자세한 내용은 document을 참조하십시오.

작업자 역할로 프로그래밍하는 방법에 대한 자습서가 있습니다. https://channel9.msdn.com/Series/Windows-Azure-Cloud-Services-Tutorials/Introduction-to-Windows-Azure-Worker-Roles-Part-1

https://channel9.msdn.com/Series/Windows-Azure-Cloud-Services-Tutorials/Introduction-to-Windows-Azure-Worker-Roles-Part-2