private void HandleResult(ThrottlingRpcResult rpcResult, long requestStartTime, long requestCompletionTime, ThrottlingRpcClient client)
        {
            long msecInterval = ThrottlingRpcClientImpl.GetMsecInterval(requestStartTime, requestCompletionTime);

            if (rpcResult != ThrottlingRpcResult.Failed && msecInterval <= 5000L)
            {
                this.HandleSuccessfulResponse();
            }
            else if (rpcResult != ThrottlingRpcResult.Failed)
            {
                ThrottlingRpcClientImpl.tracer.TraceError <string, long>(0L, "RPC request to mailbox server {0} took {1} milliseconds and treated as failed", this.serverName, msecInterval);
                ThrottlingRpcClientImpl.EventLogger.LogEvent(ThrottlingClientEventLogConstants.Tuple_RpcRequestTimedout, this.serverName, new object[]
                {
                    this.serverName,
                    msecInterval
                });
                this.HandleFailure(requestCompletionTime, null);
            }
            else
            {
                this.HandleFailure(requestCompletionTime, client);
            }
            ThrottlingRpcClientImpl.Unref(client);
            this.perfCounters.AddRequestStatus(rpcResult, msecInterval);
        }
Exemple #2
0
        private bool ObtainTokensViaNewApi(string mailboxServer, Guid mailboxGuid, RequestedAction requestedAction, int requestedTokenCount, int quota, string clientInfo)
        {
            ThrottlingRpcClientImpl rpcClient = this.GetRpcClient(mailboxServer);
            ThrottlingRpcResult     result    = rpcClient.ObtainTokens(mailboxGuid, requestedAction, requestedTokenCount, quota, clientInfo);

            return(MailboxThrottle.ThrottlingRpcResultToBoolean(result));
        }
Exemple #3
0
        private bool ObtainTokensViaOldApi(string mailboxServer, Guid mailboxGuid, int requestedTokenCount, int quota)
        {
            ThrottlingRpcClientImpl rpcClient = this.GetRpcClient(mailboxServer);
            ThrottlingRpcResult     result    = rpcClient.ObtainSubmissionTokens(mailboxGuid, requestedTokenCount, quota, 0);

            return(MailboxThrottle.ThrottlingRpcResultToBoolean(result));
        }
        public ThrottlingRpcResult ObtainTokens(Guid mailboxGuid, RequestedAction requestedAction, int requestedTokenCount, int totalTokenCount, string clientInfo)
        {
            this.ThrowIfDisposed();
            ThrottlingRpcClient throttlingRpcClient;

            if (!this.TryGetRpcClient(out throttlingRpcClient))
            {
                ThrottlingRpcClientImpl.tracer.TraceDebug(0L, "Bypassed RPC for mailbox server {0} and mailbox GUID <{1}> because of failure count {2} and last failure time {3}", new object[]
                {
                    this.serverName,
                    mailboxGuid,
                    this.failureCount,
                    this.lastFailureTime
                });
                this.perfCounters.AddRequestStatus(ThrottlingRpcResult.Bypassed);
                return(ThrottlingRpcResult.Bypassed);
            }
            long requestStartTime      = 0L;
            long requestCompletionTime = 0L;
            ThrottlingRpcResult throttlingRpcResult;

            try
            {
                ThrottlingRpcClientImpl.tracer.TraceDebug(0L, "Invoking RPC for mailbox server {0}, mailbox GUID <{1}>, requestedAction {2}, requestedTokenCount {3}, totalTokenCount {4}", new object[]
                {
                    this.serverName,
                    mailboxGuid,
                    requestedAction,
                    requestedTokenCount,
                    totalTokenCount
                });
                byte[] inBytes = ThrottlingRpcClientImpl.PackRequest(mailboxGuid, requestedAction, requestedTokenCount, totalTokenCount, clientInfo);
                requestStartTime = Stopwatch.GetTimestamp();
                byte[] responseByteArray = throttlingRpcClient.ObtainTokens(inBytes);
                requestCompletionTime = Stopwatch.GetTimestamp();
                bool flag;
                ThrottlingRpcClientImpl.UnpackResponse(responseByteArray, out flag);
                ThrottlingRpcClientImpl.tracer.TraceDebug <bool>(0L, "RPC request succeeded and returned {0}", flag);
                throttlingRpcResult = (flag ? ThrottlingRpcResult.Allowed : ThrottlingRpcResult.Denied);
            }
            catch (RpcException ex)
            {
                requestCompletionTime = Stopwatch.GetTimestamp();
                ThrottlingRpcClientImpl.tracer.TraceError <string, RpcException>(0L, "Exception in RPC request to mailbox server {0}: {1}", this.serverName, ex);
                ThrottlingRpcClientImpl.EventLogger.LogEvent(ThrottlingClientEventLogConstants.Tuple_RpcClientOperationFailure, this.serverName, new object[]
                {
                    this.serverName,
                    ex.ErrorCode,
                    ex,
                    (ex.InnerException != null) ? ex.InnerException.ToString() : "none"
                });
                throttlingRpcResult = ThrottlingRpcResult.Failed;
            }
            this.HandleResult(throttlingRpcResult, requestStartTime, requestCompletionTime, throttlingRpcClient);
            return(throttlingRpcResult);
        }
 private void HandleFailure(long failureTime, ThrottlingRpcClient client)
 {
     lock (this.syncRoot)
     {
         this.failureCount++;
         this.lastFailureTime = failureTime;
         if (client != null && this.rpcClient == client)
         {
             ThrottlingRpcClientImpl.Unref(this.rpcClient);
             this.rpcClient = null;
         }
     }
 }
 public void Dispose()
 {
     lock (this.syncRoot)
     {
         this.disposed = true;
         if (this.rpcClient != null)
         {
             if (!ThrottlingRpcClientImpl.Unref(this.rpcClient))
             {
                 throw new InvalidOperationException(string.Format("Detected extra reference(s) to RPC client instance for server {0}", this.serverName));
             }
             this.rpcClient = null;
         }
     }
 }
Exemple #7
0
        private ThrottlingRpcClientImpl GetRpcClient(string mailboxServer)
        {
            ThrottlingRpcClientImpl throttlingRpcClientImpl = null;

            lock (this.rpcClients)
            {
                if (!this.rpcClients.TryGetValue(mailboxServer, out throttlingRpcClientImpl))
                {
                    throttlingRpcClientImpl = new ThrottlingRpcClientImpl(mailboxServer);
                    this.rpcClients.Add(mailboxServer, throttlingRpcClientImpl);
                    MailboxThrottle.tracer.TraceDebug <string>(0L, "Added a new RPC client for mailbox server {0}", mailboxServer);
                }
            }
            return(throttlingRpcClientImpl);
        }
 private bool ShouldBypassRpc()
 {
     if (this.failureCount >= 2)
     {
         long msecInterval = ThrottlingRpcClientImpl.GetMsecInterval(this.lastFailureTime, Stopwatch.GetTimestamp());
         if (msecInterval < 60000L)
         {
             ThrottlingRpcClientImpl.EventLogger.LogEvent(ThrottlingClientEventLogConstants.Tuple_RpcRequestBypassed, this.serverName, new object[]
             {
                 this.serverName,
                 this.failureCount,
                 TimeSpan.FromMilliseconds((double)msecInterval)
             });
             return(true);
         }
     }
     return(false);
 }