1
我想模擬登錄壓力測試到LDAP。 同時從多個請求向LDAP發送認證請求。登錄壓力測試
我寫了下面:
static void Main(string[] args)
{
string a = "", b = "", c = "", d = "",
e = "", f = "", g = "", h = "", i = "", j = "", k = "";
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
var startTime = DateTime.Now.ToString("hh:mm:ss.fff tt");
Parallel.Invoke
(
() => a = LdsConnection.Auth("username", "password", true),
() => b = LdsConnection.Auth("username", "password", true),
() => c = LdsConnection.Auth("username", "password", true),
() => d = LdsConnection.Auth("username", "password", true),
() => e = LdsConnection.Auth("username", "password", true),
() => f = LdsConnection.Auth("username", "password", true),
() => g = LdsConnection.Auth("username", "password", true),
() => h = LdsConnection.Auth("username", "password", true),
() => i = LdsConnection.Auth("username", "password", true),
() => j = LdsConnection.Auth("username", "password", true),
() => k = LdsConnection.Auth("username", "password", true)
);
stopwatch.Stop();
var endTime = DateTime.Now.ToString("hh:mm:ss.fff tt");
Console.WriteLine(a + "\n");
Console.WriteLine(b + "\n");
Console.WriteLine(c + "\n");
Console.WriteLine(d + "\n");
Console.WriteLine(e + "\n");
Console.WriteLine(f + "\n");
Console.WriteLine(g + "\n");
Console.WriteLine(h + "\n");
Console.WriteLine(j + "\n");
Console.WriteLine(k + "\n");
// Total run time
Console.WriteLine("Started:{0}\nEnded: {1}\nElapsed: {2}",
startTime, endTime, stopwatch.Elapsed);
Console.ReadKey();
}
public static string Auth (string username, string password, bool fullDn)
{
var url = GenerateUrl(fullDn);
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
var startTime = DateTime.Now.ToString("hh:mm:ss.fff tt");
try
{
Connect(username, password, url);
stopwatch.Stop();
var elaps = stopwatch.Elapsed.ToString();
var endTime = DateTime.Now.ToString("hh:mm:ss.fff tt");
return string.Format("Started:{0}\nEnded: {1}\nElapsed: {2}",
startTime, endTime, elaps);
}
catch (Exception exception)
{
return "Error";
}
}
的問題是:
- 我怎麼能自動化此,例如其代表的地方調用同一個功能多的呼叫的數量參數時間手動becuase的用戶名和密碼是相同的所有功能?
- 我不確定是否所有的呼叫都同時請求認證。
請提出任何提示?
謝謝約翰C,我不明白我該如何控制循環次數。 – Maro
ForEach()的第一個參數是一個可以動態生成的數組,因此您可以根據需要快速擴展一個請求。 –
+1非常感謝 – Maro