2017-10-10 21 views
4

최근 클라이언트 환경에서 클라이언트 원격 통신 서비스에 TCP 원격 서비스가 8-10 초 걸리지만 클라이언트와 서비스 통신이 즉시 이루어지고 있음을 확인했습니다.클라이언트에게 메시지를 수신하는 동안 TCP Remoting 지연

먼저 우리가하려고하는 것을 설명하려고 노력할 것입니다. 각 서버의 클라이언트 환경에서 30-40 명의 사용자가 로그인 할 것이므로 트레이 응용 프로그램 [클라이언트]를 시작하고 서비스의 모든 간격마다 클라이언트에 현재 사용자 활성 창 제목을 캡처하도록 요청을 보냅니다 프로세스 이름을 캡처하면 클라이언트는 TCP Remoting을 사용하여 서비스에 세부 정보를 보냅니다.

그런데 문제는 사용자가 7-8 분이 걸리는 한 활동을 완료하는 것이므로 MaxThreadLimit 등록 정보가있는 스레드 폴링을 3으로 생각했습니다. 클라이언트 통신에 대한 서비스 지연의 원인이 무엇인지 의심스러워합니다. 여기에 우리가 사용하는 코드가 있습니다

public static List<DataEntity> GetAllUsersData() 
{ 
     /// This logic is implemented because on customer place as 
     /// more 40 user are logged in then capturing the useractivity is taking more than 5min 
     /// so we have implement the thread pool concept. 
     var complete = new CountdownEvent(1); 
     var throttle = new Semaphore(3, 3); 
     foreach (Process UserProcess in AllUsersProcess) 
     { 
       //Do not monitor the user activity if the user state is locked or personal mode or not authenticated. 
       activeUser = ActiveUsers.GetInstance().GetActiveUserBySessionId(UserProcess.SessionId); 
       if (activeUser == null || 
       activeUser.UserState == UserStateEnum.LOCKED || 
       activeUser.UserState == UserStateEnum.LOGIN_IN_PROGRESS || 
       activeUser.UserState == UserStateEnum.LOGOUT_IN_PROGRESS || 
       activeUser.IgnoreRoleActivity) 
       { 
       activeUser = null; 
       continue; 
       } 

       complete.AddCount(); 
       ThreadPool.QueueUserWorkItem((state) => 
       { 
       throttle.WaitOne(); 
       try 
       { 
       GetCurrentUserActivity(userActivities, ProbeOffline, ref userActivity, UserProcess); 
       Thread.Sleep(300); 
       } 
       catch (Exception ex) { log.ErrorFormat("Exeption occcured while getting user activity in threadpool {0}, {1}", ex.Message, ex.StackTrace); } 
       finally { throttle.Release(); complete.Signal(); } 
       }, null); 
       } 
     complete.Signal(); 
     complete.Wait(); 
} 

이것은 우리가 모든 클라이언트에게 tcp 원격 호출을 할 방법입니다.

private static TrayActivityInterfaces GetCurrentUserActivity(List<DataEntity> userActivities, bool ProbeOffline, ref UserActivityEnitity userActivity, Process UserProcess) 
    { 
     TrayActivityInterfaces remoteMethods; 
     try 
     { 
      Stopwatch userActivityTime = new Stopwatch(); 
      ActiveUserInfo activeUser = ActiveUsers.GetInstance().GetActiveUserBySessionId(UserProcess.SessionId); 
      log.DebugFormat("Activity[{0}], Sending the request to get user activity form tray for sessionid: {1}", activeUser.Username, UserProcess.SessionId); 
      remoteMethods = (TrayActivityInterfaces)Activator.GetObject(typeof(TrayActivityInterfaces), ProbeProperties.ProbeProperties.GetTrayRemotingUrl(UserProcess.SessionId)); 
      userActivity = remoteMethods.GetUserActivity(true); 
      //To avoid data drop when multiple users of system running in different timezone. 
      userActivity.ActivityTime = DateTime.Now; 
      userActivity.Offline = ProbeOffline; 

      //Fix for some applications which are running in elevated mode 
      //and not able to detect the process names. Those are handled 
      //here. 
      if (string.IsNullOrEmpty(userActivity.ActiveProcessName)) 
       userActivity.ActiveProcessName = GetTopWindowProcessName(userActivity.ActiveProcessId); 

      if (log.IsDebugEnabled) log.DebugFormat("Activity[{0}], Received in {1} seconds. User Activity: {2}", activeUser.Username, userActivityTime.Elapsed.Seconds, userActivity.ToString()); 
      userActivities.Add(userActivity); 

      if (retryStatus.ContainsKey(UserProcess.SessionId)) 
       retryStatus[UserProcess.SessionId] = 0; 
      else 
       retryStatus.Add(UserProcess.SessionId, 0); 

      userActivityTime.Reset(); 
     } 
     catch (System.Net.Sockets.SocketException ex) 
     { 
      log.Error("Tray not running for sessionId " + UserProcess.SessionId + ". " + ex.Message); 

      if (retryStatus.ContainsKey(UserProcess.SessionId)) 
       retryStatus[UserProcess.SessionId] = retryStatus[UserProcess.SessionId] + 1; 
      else 
       retryStatus.Add(UserProcess.SessionId, 1); 
     } 
     catch (Exception ex) 
     { 
      log.Error("Unable to connect to tray for sessionId " + UserProcess.SessionId + ". " + ex.Message); 

      if (retryStatus.ContainsKey(UserProcess.SessionId)) 
       retryStatus[UserProcess.SessionId] = retryStatus[UserProcess.SessionId] + 1; 
      else 
       retryStatus.Add(UserProcess.SessionId, 1); 
     } 
     finally 
     { 
      remoteMethods = null; 
     } 

     return remoteMethods; 
    } 
+0

네트워크를 확인하여 시작하십시오. 서버에서 고객 중 한 명에게 핑 (ping)을 시도하고 소요 시간을 확인하십시오. 호스트 이름이나 IP 주소를 사용하고 있습니까? – Caesar

답변