Load balancing vusers without a load balancer

Recently I ran a test at a company which had a performance test environment with multiple web servers, but no load balancer. To spread my virtual users evenly across the web servers, I made a simple modification to my script.

First, I created a file-based parameter containing my web server names.
VuGen Parameter List showing parameter-based load balancing

Next, I parameterised the server name part of the URLs in my web_url() and web_submit_data() function calls.

1
2
3
4
5
6
7
8
9
web_url("Login", 
    "URL=http://{ServerName}/login.do", 
    "TargetFrame=", 
    "Resource=0", 
    "RecContentType=text/html", 
    "Referer=", 
    "Snapshot=t1.inf", 
    "Mode=HTML", 
    LAST);

So, when the script ran, the virtual user would would choose a web server at random on every iteration.

…and that was it. I didn’t say it was going to be hard. :)

Of course, my Test Summary Report was very clear that one of the limitations of the Performance Test cycle had been that there was no load balancer in the test environment, so the stability and performance characteristics of this component in the Production environment could not be predicted.


Bookmark using any bookmark manager!

 

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

2 Responses to “Load balancing vusers without a load balancer”

  1. A alternative solution uses the vuser id modulo the number of hosts.

    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
    56
    57
    58
    59
    60
    
    	static int NB_HOST = 3; // 3 differents hosts
     
    	/* load balancing computes with vuser id modulo number of hosts */
    	int id, scid;
    	char *vuser_group;
    	int valIdMod;
    	static int isInitRand = 0;
     
    	if (isInitRand == 0) {
    		//srand is called before rand 
    		srand(time(NULL)); 
    		isInitRand = 1;
    	}
     
    	lr_whoami(&id, &vuser_group, &scid);
    	lr_message( "Group: %s, vuser id: %d, scenario id %d",  vuser_group, id, scid);
     
    	/*************** BEGIN COMMENT ***********/
    	// id = 5555; // force the id to a specifique host
    	/*************** END commenter ***********/
     
    	valIdMod = id % NB_HOST;
     
    	if (valIdMod == 0) {
    		lr_save_string( "http://","P_PROTOCOLE" );
    		lr_save_string("serverA","P_SERVEUR" ); 
    		lr_save_string( "7013","P_PORT" );
    	}
     
    	if (valIdMod == 1) {
    		lr_save_string( "http://","P_PROTOCOLE" );
    		lr_save_string("serverB","P_SERVEUR" ); 
    		lr_save_string( "8080","P_PORT" );
    	}
     
    	if (valIdMod == 2) {
    		lr_save_string( "http://","P_PROTOCOLE" );
    		lr_save_string("serverC","P_SERVEUR" ); 
    		lr_save_string( "7015","P_PORT" );
    	}
     
    	// force to a specific host
    	if (id == 5555) {
    		lr_save_string( "http://","P_PROTOCOLE" );
    		lr_save_string("serverB","P_SERVEUR" ); 
    		lr_save_string( "8080","P_PORT" );
     
    	}
    	lr_log_message("P_SERVEUR = %s", lr_eval_string("{P_SERVEUR}"));
    	lr_log_message("P_PORT = %s", lr_eval_string("{P_PORT}"));
     
    	web_url("Login", 
    		"URL={P_PROTOCOLE}://{P_SERVEUR}:{P_PORT}/login.do", 
    		"TargetFrame=", 
    		"Resource=0", 
    		"RecContentType=text/html", 
    		"Referer=", 
    		"Snapshot=t1.inf", 
    		"Mode=HTML", 
    		LAST);

Leave a Reply