Monday, 5 October 2015

Changing Pacing time while a test is running

You might have noticed that once you have started your load test, it is possible to increase the number of transactions per hour by adding virtual users, but not by changing the pacing time.
The VuGen Pacing runtime setting is only read at the start of the test so, to change it, it is necessary to stop the test, then make the change and restart.
Fortunately (if you need to), you can write code to control the pacing of your virtual users instead of using the runtime settings. If you write code to pick up a pacing setting from a file, and check the file on each iteration, then you can cause your script to delay for the right amount of time to meet your desired transaction rate.

Obviously, if you are controlling the pacing yourself, you should have the Pacing runtime setting set to “start new iteration as soon as the previous iteration ends”. And if you are using think time for the pacing delay, you should have the Think Time runtime setting set to “replay think time” (or use think time that can’t be ignored).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
Action()
{
  merc_timer_handle_t timer; 
  double duration;
  double pacing_time;
 
  // Read desired pacing timer from a text file.
  // The text file should contain the number of seconds to be used for pacing. 
  pacing_time = (double)jds_read_pacing_time("C:\\TEMP\\vugen_pacing.txt");
 
  // Start the timer.
  timer = lr_start_timer(); 
 
  // Call Action function that you want to control pacing for.
  // Note that if you do it this way (rather than putting the pacing code at the start and end of the 
  // Action), then you need to first go to the Run Logic area of the runtime settings, and right-click the 
  // Search Action and select "remove item" from the context menu.
  Search();
 
  // Stop the timer
  duration = lr_end_timer(timer); 
 
  // Wait for the necessary number of seconds to elapse before starting the next iteration.
  if (duration < pacing_time) {
    lr_think_time(pacing_time - duration);
  } else {
    lr_error_message("Pacing time exceeded. Target: %G seconds. Actual: %g seconds", pacing_time, duration);
  }
 
  return 0;
}
 
// Read pacing time from a file. Returns time in seconds (whole seconds only).
// Note that file can be on a shared network drive.
int jds_read_pacing_time(char* file_name) {
  long fs; // file stream
  int number_from_file;
 
  // Open the file for reading
  fs = fopen(file_name, "r+");
  if (fs == NULL) {
    lr_error_message("Error opening file: %s", file_name);
    return -1;
  }
 
  // Read number from file.
  if (fscanf(fs, "%d", &number_from_file) != 1) {
    lr_error_message("Error reading number from file: %s", file_name);
    return -1;
  }
 
  fclose(fs);
 
  return number_from_file;
}

No comments:

Post a Comment