Introduction
Multiple URL Stress is a tool to test the performance of servers and websites, allowing you to test multiple URLs at the same time.
It sets the number of requests for each of the sites, and few threads used, so the number of requests is multiplied by the number of configured threads.
It also has the ability to configure authentication and proxy server for your connection.
Using the Code
Browse the list of charged sites and initiates the configured number of threads for each.
foreach (string url in listBoxUrls.Items)
{
for (int i = 1; i <= Settings.CountThreads; i++)
{
Thread workerThread = new Thread(() => WorkerThreadProc(url));
workerThread.Start();
}
}
The WorkerThreadProc
method is responsible for conducting and requests to sites.
Interlocked.Increment
allows increased variable that is located in the main thread to reflect the partial results in the user view.
public void WorkerThreadProc(string url)
{
Interlocked.Increment(ref numWorkItems);
int tries = 0;
while ((!_shouldStop) && ((tries < Settings.CountRequest || (Settings.isforever))))
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.KeepAlive = true;
try
{
request.Method = "GET";
if (Settings.autenticate)
{
var cache = new CredentialCache();
cache.Add(new Uri(url), "Basic",
new NetworkCredential(Settings.authUser, Settings.authPass));
request.Credentials = cache;
}
if (Settings.proxy)
{
WebProxy myproxy = new WebProxy(Settings.proxyHost, Settings.proxyPort);
if (Settings.proxyUser != "")
myproxy.Credentials =
new NetworkCredential(Settings.proxyUser, Settings.proxyPass);
request.Proxy = myproxy;
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
Interlocked.Increment(ref count200);
if (response.StatusCode == HttpStatusCode.Unauthorized)
Interlocked.Increment(ref count401);
if (response.StatusCode == HttpStatusCode.NotFound)
Interlocked.Increment(ref count404);
if (response.StatusCode == HttpStatusCode.NotModified)
Interlocked.Increment(ref count304);
response.Close();
}
catch
{
Interlocked.Increment(ref countFailures);
}
tries++;
Interlocked.Increment(ref requests);
Interlocked.Increment(ref requestsLastSec);
}
Interlocked.Decrement(ref numWorkItems);
}
History
- 23rd October, 2015: Initial post