Beispiel #1
0
        public void Execute()
        {
            double time = TimeWatch.GetTotalSeconds() - mLastTime;

            mLastTime = TimeWatch.GetTotalSeconds();
            int value = (int)((double)(mCount - mLastCount) / time);

            mLastCount = mCount;
            Rps        = value;

            SendIOPer   = (long)((double)(mSendIO - mLastSendIO) / time);
            mLastSendIO = mSendIO;

            SendBytesPer   = (long)((double)(mSendBytes - mLastSendBytes) / time);
            mLastSendBytes = mSendBytes;

            ReceiveIOPer   = (long)((double)(mReceiveIO - mLastReceiveIO) / time);
            mLastReceiveIO = mReceiveIO;

            ReceiveBytesPer   = (long)((double)(mReceiveBytes - mLastReceiveBytes) / time);
            mLastReceiveBytes = mReceiveBytes;

            if (value > MaxRps)
            {
                MaxRps = value;
            }
            AvgRps = (int)(mCount / (TimeWatch.GetTotalSeconds() - mFirstTime));
        }
Beispiel #2
0
        private bool OnCompleted()
        {
            if (Status == LoaderStatus.Completed)
            {
                return(true);
            }
            var completed = false;
            var count     = System.Threading.Interlocked.Increment(ref mTotalRequest);

            if (Setting.Type == "time")
            {
                var time = TimeWatch.GetTotalSeconds();
                if (time - mStartTime > Setting.Value)
                {
                    completed = true;
                }
            }
            else
            {
                completed = count > Setting.Value;
            }
            if (completed)
            {
                this.Status = LoaderStatus.Completed;
            }
            return(completed);
        }
Beispiel #3
0
        public static void Set(string key, object data, double seconds = 60)
        {
            CacheItem item = new CacheItem();

            item.Data       = data;
            item.ActiveTime = TimeWatch.GetTotalSeconds() + seconds;
            mCache[key]     = item;
        }
Beispiel #4
0
        public void Add(long time)
        {
            long value = System.Threading.Interlocked.Increment(ref mCount);

            if (value == 1)
            {
                mFirstTime = TimeWatch.GetTotalSeconds();
                mLastTime  = mFirstTime;
            }
            if (time <= 5)
            {
                System.Threading.Interlocked.Increment(ref ms5);
            }
            else if (time <= 10)
            {
                System.Threading.Interlocked.Increment(ref ms10);
            }
            else if (time <= 20)
            {
                System.Threading.Interlocked.Increment(ref ms20);
            }
            else if (time <= 50)
            {
                System.Threading.Interlocked.Increment(ref ms50);
            }
            else if (time <= 100)
            {
                System.Threading.Interlocked.Increment(ref ms100);
            }
            else if (time <= 200)
            {
                System.Threading.Interlocked.Increment(ref ms200);
            }
            else if (time <= 500)
            {
                System.Threading.Interlocked.Increment(ref ms500);
            }
            else if (time <= 1000)
            {
                System.Threading.Interlocked.Increment(ref ms1000);
            }
            else if (time <= 2000)
            {
                System.Threading.Interlocked.Increment(ref ms2000);
            }
            else if (time <= 5000)
            {
                System.Threading.Interlocked.Increment(ref ms5000);
            }
            else if (time <= 10000)
            {
                System.Threading.Interlocked.Increment(ref ms10000);
            }
            else
            {
                System.Threading.Interlocked.Increment(ref msOther);
            }
        }
Beispiel #5
0
 public static object Get(string key)
 {
     if (mCache.TryGetValue(key, out CacheItem item))
     {
         if (TimeWatch.GetTotalSeconds() > item.ActiveTime)
         {
             return(null);
         }
         return(item.Data);
     }
     return(null);
 }
Beispiel #6
0
        public TimeStatisticsData GetData()
        {
            double now  = TimeWatch.GetTotalSeconds();
            double time = now - mLastTime;

            if (time > 1)
            {
                mData.Count   = mCount;
                this.Increase = (double)(mCount - mLastCount);
                mData.Rps     = (int)(Increase / (time));
                mLastTime     = now;
                mLastCount    = mCount;
            }
            return(mData);
        }
Beispiel #7
0
        private void OnRun()
        {
            if (Items.Count == 0)
            {
                Status = LoaderStatus.Error;
                Error  = new Exception("没有可用的测试用例!");
                return;
            }
            CreateClient();

            mTotalRequest = 0;
            mStartTime    = TimeWatch.GetTotalSeconds();
            foreach (var item in httpTcpClients)
            {
                OnTest(item);
            }
        }
Beispiel #8
0
        public CodeStatisticsData GetData()
        {
            if (TimeWatch.GetTotalSeconds() - mLastTime > 1)
            {
                if (System.Threading.Interlocked.CompareExchange(ref mGetStatus, 1, 0) == 0)
                {
                    CodeStatisticsData result = mStatisticsData;
                    result.CreateTime = TimeWatch.GetTotalSeconds();
                    result.Count      = Count;
                    double now  = TimeWatch.GetTotalSeconds();
                    double time = now - mLastTime;
                    result.Increase = (double)(mCount - mLastCount);
                    result.Rps      = (int)((result.Increase) / time);

                    mLastTime  = now;
                    mLastCount = mCount;
                    mGetStatus = 0;
                }
            }
            return(mStatisticsData);
        }
Beispiel #9
0
        public bool Match(HttpRequest request, out RouteMatchResult result, QueryString queryString)
        {
            result = null;
            RouteGroup rg       = null;
            UrlRoute   urlRoute = null;
            string     key      = $"{request.GetHostBase()}{request.BaseUrl}";

            if (mRouteCached.TryGetValue(key, out UrlRouteAgent cached))
            {
                cached.ActiveTime = TimeWatch.GetTotalSeconds();
                if (cached.Route == null && cached.Version == this.mVersion)
                {
                    if (request.Server.EnableLog(EventArgs.LogType.Info))
                    {
                        request.Server.Log(EventArgs.LogType.Info, $"HTTP {request.ID} {request.RemoteIPAddress} {request.Method} {key} rewrite cached miss");
                    }
                    return(false);
                }
                if (cached.Route != null && cached.Version == this.mVersion)
                {
                    if (cached.Parameters.Count > 0)
                    {
                        foreach (var item in cached.Parameters)
                        {
                            queryString.Add(item.Key, item.Value);
                        }
                    }
                    result = cached.MatchResult;
                    if (request.Server.EnableLog(EventArgs.LogType.Info))
                    {
                        request.Server.Log(EventArgs.LogType.Info, $"HTTP {request.ID} {request.RemoteIPAddress} {request.Method} {key} rewrite cached hit");
                    }
                    return(true);
                }
            }
            bool iscached = true;
            Dictionary <string, string> parameters = new Dictionary <string, string>();

            result = new RouteMatchResult();
            if (mRoutes.TryGetValue(request.Path, out rg))
            {
                urlRoute = rg.Match(request.BaseUrl, ref result, parameters, request.Ext, request);
            }
            if (urlRoute == null)
            {
                RouteGroup[] rgs = mMatchRoutes;
                if (rgs != null)
                {
                    for (int i = 0; i < rgs.Length; i++)
                    {
                        rg = rgs[i];
                        if (rg.PathLevel == request.PathLevel)
                        {
                            iscached = rg.Cached;
                            urlRoute = rg.Match(request.BaseUrl, ref result, parameters, request.Ext, request);
                            if (urlRoute != null)
                            {
                                if (urlRoute.Prefix != null && urlRoute.Prefix.Type == UrlPrefix.PrefixType.Host)
                                {
                                    iscached = true;
                                }
                                break;
                            }
                        }
                    }
                }
            }
            if (urlRoute != null)
            {
                result.HasQueryString = urlRoute.HasQueryString;
            }
            if (urlRoute != null && urlRoute.Prefix?.Type == UrlPrefix.PrefixType.Param)
            {
                return(urlRoute != null);
            }
            var agent = new UrlRouteAgent {
                Route = urlRoute, Version = this.mVersion, MatchResult = result, Parameters = parameters
            };

            if (parameters.Count > 0)
            {
                foreach (var ps in parameters)
                {
                    queryString.Add(ps.Key, ps.Value);
                }
            }
            if (iscached)
            {
                UrlRouteAgent exits = (UrlRouteAgent)mRouteCached.ExistOrAdd(key, agent);
                if (request.Server.EnableLog(EventArgs.LogType.Info))
                {
                    request.Server.Log(EventArgs.LogType.Info, $"HTTP {request.ID} {request.RemoteIPAddress} {request.Method} {key} rewrite save to cached");
                }
                if (exits != null)
                {
                    exits.Route       = urlRoute;
                    exits.Version     = mVersion;
                    exits.MatchResult = result;
                    exits.Parameters  = parameters;
                }
            }
            return(urlRoute != null);
        }
Beispiel #10
0
        public StatisticsData GetData()
        {
            if (mStatisticsData == null || TimeWatch.GetTotalSeconds() - mStatisticsData.CreateTime >= 1)
            {
                if (System.Threading.Interlocked.CompareExchange(ref mGetStatus, 1, 0) == 0)
                {
                    StatisticsData result = new StatisticsData();
                    result.CreateTime = TimeWatch.GetTotalSeconds();
                    result.Count      = Count;
                    result.Rps        = Rps;
                    result.Name       = Name;
                    result.Times.Add(Time10ms);
                    result.Times.Add(Time20ms);
                    result.Times.Add(Time50ms);
                    result.Times.Add(Time100ms);
                    result.Times.Add(Time200ms);
                    result.Times.Add(Time500ms);
                    result.Times.Add(Time1000ms);
                    result.Times.Add(Time2000ms);
                    result.Times.Add(Time5000ms);
                    result.Times.Add(Time10000ms);
                    result.Times.Add(TimeOtherms);
                    double now  = TimeWatch.GetTotalSeconds();
                    double time = now - mLastRpsTime;

                    int value = (int)((double)(ms10 - ms10LastCount) / time);
                    ms10LastCount = ms10;
                    result.TimesRps.Add(value);


                    value         = (int)((double)(ms20 - ms20LastCount) / time);
                    ms20LastCount = ms20;
                    result.TimesRps.Add(value);


                    value         = (int)((double)(ms50 - ms50LastCount) / time);
                    ms50LastCount = ms50;
                    result.TimesRps.Add(value);


                    value          = (int)((double)(ms100 - ms100LastCount) / time);
                    ms100LastCount = ms100;
                    result.TimesRps.Add(value);


                    value          = (int)((double)(ms200 - ms200LastCount) / time);
                    ms200LastCount = ms200;
                    result.TimesRps.Add(value);


                    value          = (int)((double)(ms500 - ms500LastCount) / time);
                    ms500LastCount = ms500;
                    result.TimesRps.Add(value);


                    value           = (int)((double)(ms1000 - ms1000LastCount) / time);
                    ms1000LastCount = ms1000;
                    result.TimesRps.Add(value);


                    value           = (int)((double)(ms2000 - ms2000LastCount) / time);
                    ms2000LastCount = ms2000;
                    result.TimesRps.Add(value);


                    value           = (int)((double)(ms5000 - ms5000LastCount) / time);
                    ms5000LastCount = ms5000;
                    result.TimesRps.Add(value);


                    value            = (int)((double)(ms10000 - ms10000LastCount) / time);
                    ms10000LastCount = ms10000;
                    result.TimesRps.Add(value);


                    value            = (int)((double)(msOther - msOtherLastCount) / time);
                    msOtherLastCount = msOther;
                    result.TimesRps.Add(value);

                    mLastRpsTime = now;

                    mStatisticsData = result;

                    mGetStatus = 0;
                }
            }
            return(mStatisticsData);
        }
Beispiel #11
0
        public StatisticsData GetData()
        {
            StatisticsData result = new StatisticsData();

            result.Count  = Count;
            result.Rps    = Rps;
            result.MaxRps = MaxRps;
            result.AvgRps = AvgRps;

            result.Name = Name;
            result.Times.Add(Time10ms);
            result.Times.Add(Time20ms);
            result.Times.Add(Time50ms);
            result.Times.Add(Time100ms);
            result.Times.Add(Time200ms);
            result.Times.Add(Time500ms);
            result.Times.Add(Time1000ms);
            result.Times.Add(Time2000ms);
            result.Times.Add(Time5000ms);
            result.Times.Add(Time10000ms);
            result.Times.Add(TimeOtherms);
            double now  = TimeWatch.GetTotalSeconds();
            double time = now - mLastRpsTime;

            int value = (int)((double)(ms10 - ms10LastCount) / time);

            ms10LastCount = ms10;
            result.TimesRps.Add(value);


            value         = (int)((double)(ms20 - ms20LastCount) / time);
            ms20LastCount = ms20;
            result.TimesRps.Add(value);


            value         = (int)((double)(ms50 - ms50LastCount) / time);
            ms50LastCount = ms50;
            result.TimesRps.Add(value);


            value          = (int)((double)(ms100 - ms100LastCount) / time);
            ms100LastCount = ms100;
            result.TimesRps.Add(value);


            value          = (int)((double)(ms200 - ms200LastCount) / time);
            ms200LastCount = ms200;
            result.TimesRps.Add(value);


            value          = (int)((double)(ms500 - ms500LastCount) / time);
            ms500LastCount = ms500;
            result.TimesRps.Add(value);


            value           = (int)((double)(ms1000 - ms1000LastCount) / time);
            ms1000LastCount = ms1000;
            result.TimesRps.Add(value);


            value           = (int)((double)(ms2000 - ms2000LastCount) / time);
            ms2000LastCount = ms2000;
            result.TimesRps.Add(value);


            value           = (int)((double)(ms5000 - ms5000LastCount) / time);
            ms5000LastCount = ms5000;
            result.TimesRps.Add(value);


            value            = (int)((double)(ms10000 - ms10000LastCount) / time);
            ms10000LastCount = ms10000;
            result.TimesRps.Add(value);


            value            = (int)((double)(msOther - msOtherLastCount) / time);
            msOtherLastCount = msOther;
            result.TimesRps.Add(value);


            mLastRpsTime = now;
            return(result);
        }