| || |
Overwriting hosts file to bypass load balancer
I'm trying to run a monitoring script that executes an end to end transaction from within our data center so we can figure out which (of 35 of them) server(s) are underperforming. Currently, my script goes through the load balancer, and as we don't have sticky load balancing, I get a different server responding during redirects. I can remedy this by setting up a hosts file under system32/drivers/etc and then all traffic goes to a specific server.
What I'd like to do is overwrite this hosts file every run (about 30 to 48 transactions per hour) and then have the VU use the new hosts setting.
I've got a SilkTest script to handle the file overwrite, and I can call it before my TMain function, but I'm not seeing the desired effect of a single server in Performer:
<font class="small">Code:</font><hr /><pre> transaction TSilk
// SilkTest simply does a copy /Y sNewHostfile hosts to replace
StExecuteTestcase("fliphost.t", "FlipHostsFile", "\"server1hostfile\"", "MyTimer1");
So my question is this...when does Performer read the host information, and is it possible to get it to re-read said info before a transaction is called?
WebSetStandardHost doesn't work because of the LB, so I still get the redirects...I suppose I could build a list of server IP addresses and try using those instead of the server names, but any other suggestions would be welcome.
Actually, I figured it out...solution here:
Wasn't that difficult after all...but here's my solution (a better answer is always welcome, but here it is if it helps anyone)...
I created a function Func_SetHost and a CSV file with the list of webservers and their corresponding IP addresses in our datacenters.
<font class="small">Code:</font><hr /><pre>dclfunc
hFile : number;
sOutput : string;
sServerName,sVar : string;
sVar := FileGetCol(hGlobal,2,20);
FOpen (hFile, "c:\\WINDOWS\\System32\\drivers\\etc\\hosts",OPT_F ILE_ACCESS_READWRITE,OPT_FILE_APPEND);
//*** a list of FWrite(hFile, sOutput+"\n",STRING_COMPLETE, OPT_FILE_APPEND); calls for each URL alias I needed
Then I just call that function at the beginning of the transaction and force DNS lookup
<font class="small">Code:</font><hr /><pre>
...rest of transaction
Now I get Server1 back for the entire run, followed by server2, server3, etc.
Re: Actually, I figured it out...solution here:
Sean, I think your approach is the one that makes the most sense. There are probably things you could have done with dynamically parsing out the redirected-to host names given by the LB and using browser-level URLs (and/or lots of WebSetStandardHosts or something like that) but I think what you've done is among the easiest to implement....