Monday, March 31, 2014

Replay server log while observing the timestamp

   One of the common requests from the companies in need of performance testing is to replay the server logs.  Replaying server logs can give the server(s) a very realistic test because the HTTP requests are actually from the real world.  To make this approach even more realistic, it would be nice to replay the server logs according to the time stamps of log entries. Multiple such questions (1 2) were asked in the StackOverflow forum.   In this blog we will explain in detail a script implemented on the NetGend performance test platform.

    Before diving into the script, I want to point out that there are implementations, by using scripting languages such as Ruby, that are quite involved from a test engineer's point of view. In addition, these implementations do not support many concurrent connections (say, 5000) which are required to accurately make use of the time stamps in the server log.  Why is it important to have many connections?  Sometimes, there are bursts of requests to the server, and, without enough connections, you will not be able to generate sufficient requests to simulate the burst.

    There are some solutions on platforms such as JMeter, but they require installing complicated plugins and/or having deep knowledge of the relevant programming language - again above the heads of many testers.

   In contrast, the NetGend script is refreshingly simple.   In the following example, we assume the log only contains two fields:  timestamp, in seconds (with decimal places), and the URL.  More complex logs can be handled similarly.

  Here is the script. As you see, it is quite simple.  Note that in this test scenario, “virtual users” are different from what they mean in other test scenarios: they are not used to emulate real users, but instead they are used as workers to get a job and execute it.   So, a "VUSER" should be understood as a worker”.

function userInit() { 
     var fd = openFile("srvLogs.txt"); 
     var startTime = 0; 
     var startTick; 
function VUSER() { 
     while (1) { 
          line = getLine(fd); 
          if (line == "") { break; } 
          b = qsplit(line); 
          if (startTime == 0) { startTime = b[0]; startTick = currentTick;} 
          delay = (b[0] - startTime) * 1000 - (currentTick - startTick);  
          if (delay > 0) { sleep(delay); } 

  • Line 2-4, we open the server log file and declare two global variables, 
    • startTime:  holds the first timestamp in the server log.
    • startTick:   holds the time (in ticks, 1tick = 1ms) on the test platform when it's ready to process the first log entry.
  • The VUSER() function just consists of a while loop.
  • Line 8,  each worker gets a line from the server log file.
  • Line 9,  if it's empty, then come out the loop since we have reached the end.
  • Line 10,  split the line into fields.
  • Line 11,  set the starting timestamp (startTime), we will set it only once.
  • Line 12,  calculate the delay that we need to sleep before running.
  • Line 13, sleep according to the delay from previous step.
  • Line 14, send the HTTP request.

  We can start 10,000 such workers, each following the above logic.  Overall, the test platform is  replaying the server log while following timestamp,  even if there is a big burst of requests.

  Note that the script will work not only with Apache server log, but also with other server logs such as Nignx, MS IIS.

   Application Development and Testing Teams will require many different scenarios for replaying server logs. Based on the built-in flexibility and power of the NetGend platform, we are confident that we will be able to handle them all. Give us a call or drop us a note with any questions, or if you would like to use NetGend in your project.

No comments:

Post a Comment