Esempio n. 1
0
        private static void CreateRequest(RequestState requestState)
        {
            var rootUrls = Configuration.Urls;
            var rootUrlCount = rootUrls.Length;
            var urlidx = requestState.Id % rootUrlCount;
            int finalUrlIdx = urlidx;
            var rootUrl = rootUrls[finalUrlIdx];

            if (Configuration.EnableEqualLoad)
            {
                lock (_urlRequestsLock)
                {
                    var currentCount = _urlRequests[finalUrlIdx];
                    while (currentCount >= _maxUrlRequests)
                    {
                        urlidx++;
                        finalUrlIdx = urlidx % rootUrlCount;
                        rootUrl = rootUrls[finalUrlIdx];
                        currentCount = _urlRequests[finalUrlIdx];
                    }
                    _urlRequests[finalUrlIdx] = _urlRequests[finalUrlIdx] + 1;
                    requestState.UrlIndex = finalUrlIdx;
                }
            }

            var uri = String.Format("{0}?benchmarkaction=createcontent&contenttype={1}&snpath={2}{3}",
                rootUrl, requestState.ContentTypeName, requestState.SnPath, requestState.FsPath == null ? string.Empty : "&fspath=" + requestState.FsPath);
            var req = WebRequest.Create(uri);
            req.Timeout = Configuration.RequestTimeout * 1000;
            requestState.Request = req;
        }
Esempio n. 2
0
 private static void EnqueueTask(RequestState requestState)
 {
     lock (_taskQueueSync)
     {
         _taskQueue.Enqueue(requestState);
         TaskQueueCount = _taskQueue.Count;
     }
 }
Esempio n. 3
0
 private static IEnumerable<RequestState> GetFiles(RequestState requestState)
 {
     var count = Configuration.FileProfile.Length;
     var result = new RequestState[count];
     for (int i = 0; i < count; i++)
     {
         result[i] = new RequestState
         {
             Id = _nextId++,
             ContentTypeName = "File",
             Level = requestState.Level + 1,
             SnPath = String.Concat(requestState.SnPath, "/", Configuration.FileProfileNames[i]),
             FsPath = Configuration.FileProfile[i],
             FileSize = Configuration.FileProfileSizes[i]
         };
     }
     return result;
 }
Esempio n. 4
0
        private static IEnumerable<RequestState> GetChildren(RequestState requestState)
        {
            var level = requestState.Level;
            var fileLevel = Configuration.FolderProfile.Length;
            if (level > fileLevel)
                return new RequestState[0];

            if (level == fileLevel)
                return GetFiles(requestState);

            var count = Configuration.FolderProfile[level];
            var result = new RequestState[count];
            for (int i = 0; i < count; i++)
            {
                result[i] = new RequestState
                {
                    Id = _nextId++,
                    ContentTypeName = "Folder",
                    Level = level + 1,
                    SnPath = String.Concat(requestState.SnPath, "/Folder-", i)
                };
            }
            return result;
        }
Esempio n. 5
0
        private static void FinalizeTask(RequestState task)
        {
            if (task.ContentTypeName == "File")
                return;

            task.Request = null;
            task.Response = null;

            lock (_unprocessedFolderTasksSync)
                _unprocessedFolderTasks.Enqueue(task);

            if (TaskQueueCount <= Configuration.MaxTaskQueueSize)
            {
                RequestState t = null;
                lock (_unprocessedFolderTasksSync)
                {
                    if (_unprocessedFolderTasks.Count > 0)
                        t = _unprocessedFolderTasks.Dequeue();
                }
                if (t != null)
                    EnqueueTasks(GetChildren(t));
            }
        }
Esempio n. 6
0
        internal static void WriteDetail(RequestState requestState, bool error)
        {
            if (!Configuration.SaveDetailedLog)
                return;

            var waitLength = (requestState.StartTime - requestState.InitTime);
            var responseTime = requestState.ResponseTime;
            var totalDuration = waitLength + responseTime;

            var line = string.Concat(
                requestState.Id, ";",
                requestState.Request.RequestUri, ";",
                requestState.SnPath, ";",
                requestState.Level, ";",
                requestState.ContentTypeName, ";",
                requestState.FileSize, ";",
                FormatTimeStamp(waitLength), ";",
                FormatTimeStamp(responseTime), ";",
                FormatTimeStamp(totalDuration), ";",
                error ? "ERROR" : "OK",
                GetResponseLogData(requestState.Response == null ? null : requestState.Response.ResponseLog)
                );
            lock (_detailedLogSync)
            {
                _detailedLogLines += line + Environment.NewLine;
            }
        }