2014-04-02 2 views
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"; 
     } 

    } 

문제점은 다음과 같습니다 :

  1. 가 어떻게이 문제를 자동화 할 수 있습니다 예를 들어, 동일한 기능의 다중를 호출하는 대신 호출의 수를 나타냅니다 매개 변수

    나는 다음과 같이 썼다 사용자 이름과 암호가 모든 기능에 대해 동일하기 때문에 수동으로 시간을?
  2. 모든 호출이 동시에 인증을 요청하는지 잘 모르겠습니다.

어떤 팁을 주시겠습니까?

답변

1

시도해 볼 수 있습니다.

static void Main(string[] args) 
{ 
    const int numberOfTasks = 10; 

    Stopwatch stopwatch = new Stopwatch(); 
    stopwatch.Start(); 
    var startTime = DateTime.Now.ToString("hh:mm:ss.fff tt"); 

    List<Task<string>> taskList = new List<Task<string>>(); 

    for(int i = 0; i < numberOfTasks; i++) 
     taskList.Add(new Task<string> (LdsConnection.Auth("username", "password", true)) 

    foreach(var task in taskList) 
     taskList.Start(); 

    foreach(var task in taskList) 
     Console.WriteLine(task.Result); 

    Console.ReadKey(); 
} 
1

Parallel.ForEach()은 아마도 더 나은 선택 일 것입니다. this answer에서 작은 예제를 볼 수 있습니다.

타이밍을 고려할 때 서버가 중요한 것은 서버의 관점이므로이를 결정할 수 있습니다. 로그를 확인하여 요청이 얼마나 가까운 지 알 수 있습니다.

+0

감사합니다. John C, 저는 어떻게하면 루프 수를 제어 할 수 있는지 보지 못합니다. – Maro

+0

'ForEach()'의 첫 번째 매개 변수는 배열로, 동적으로 생성 할 수 있으므로 한 요청에서 필요한만큼 빠르게 확장 할 수 있습니다. –

+0

+1 고맙습니다. – Maro