Web applications servers need to be load tested for capacity planning on a regular basis and detailed testing is required to accurately gauge the number of connections the web servers can support before giving in to high load and crashing. If the max clients/max connections/max requests value supported by the backend web servers is known, then you can specify the MaxClient/MaxReq parameter on the NetScaler responsible for load balancing the servers to prevent the backend servers from being overwhelmed and eventually giving in.

http://support.citrix.com/proddocs/topic/netscaler-traffic-management-10-1-map/ns-lb-advancedsettings-maxclient-tsk.html

http://support.citrix.com/proddocs/topic/netscaler-traffic-management-10-1-map/ns-lb-advancedsettings-maxrequest-tsk.html

But often, organizations don’t conduct detailed testing on the web servers and decide to redirect a percentage of traffic to a maintenance page or a “sorry” page.

The method outlined below describes a way you can redirect a fraction/percentage of the traffic destined to a web server to a sorry page to buy some time and conduct proper load testing in order to accurately gauge the capacity of the web application server.

High Level Approach:

  • Insert a “Count” header into the request if there isn’t one present and start with the initial value “1″

add rewrite action company_act0 insert_http_header Count “\”1\”” -bypassSafetyCheck YES
add rewrite policy company_pol1 “!HTTP.REQ.HEADER(\”Count\”).EXISTS” company_act0

  • If “Count” header is present, and if the length of the value of the header is less than 10, then append an extra “1” to the value of the “Count” header

add rewrite action company_act2 replace “http.REQ.HEADER(\”Count\”).VALUE(0)” “HTTP.REQ.HEADER(\”Count\”).VALUE(0).APPEND(1)” -bypassSafetyCheck YES
add rewrite policy company_pol2 “HTTP.REQ.HEADER(\”Count\”).EXISTS&& HTTP.REQ.HEADER(\”Count\”).VALUE(0).LENGTH<10” company_act2

  • If “Count” header is present, and the length of the header is exactly 10, then replace the value (expected to be “1111111111” then) with “1” to start the count to 10 again

add rewrite action company_act3 replace “http.REQ.HEADER(\”Count\”).VALUE(0)” “\”1\”” -bypassSafetyCheck YES
add rewrite policy company_pol3 “http.REQ.HEADER(\”Count\”).EXISTS&&HTTP.REQ.HEADER(\”Count\”).VALUE(0).LENGTH.EQ(10)” company_act3

  • Create a rewrite policy to redirect to the “Sorry.html” page if the count equals “3”, “6” or “9” (to redirect to the maintenance page 3 out of 10 times for 30%)

add rewrite action company_redirect replace http.REQ.URL “\”sorry.html\”” -bypassSafetyCheck YES
add rewrite policy company_redirect_pol “HTTP.REQ.HEADER(\”Count\”).VALUE(0).LENGTH.EQ(3)||http.REQ.HEADER(\”Count\”).VALUE(0).LENGTH.EQ(6)||http.REQ.HEADER(\”Count\”).VALUE(0).LENGTH.EQ(9)” company_redirect

  • Create a policy label to run these rewrites in the above specified sequence using the action “NEXT”, “NEXT” and “END”.

add rewrite policylabel company_policylabel http_req
bind rewrite policylabel company_policylabel company_pol1 100 NEXT
bind rewrite policylabel company_policylabel company_pol2 110 NEXT
bind rewrite policylabel company_policylabel company_pol3 120 NEXT
bind rewrite policylabel company_policylabel company_redirect 130 END