Using mod_backhand for a better test environment

Setting up a good apache test website can be a pain. Mod_backhand can help simply things.

Usually your have your live website, www.mycompany.com, then you may have a dev website called something like dev.www.mycompany.com. Sometimes using a non production domain name causes problems. It shouldn't but sometimes when you use legacy code or third party programs, you don't have total control of everything. Then you can get into DNS tricks, changing host files, etc...

I use mod_backhand for a load balancer for Apache 1.3. Mod_backhand allows http requests to be redirected to any server in your cluster, based on system load or other criteria.

An Apache server sits on the perimeter and listens to all http requests. When a request comes in, mod_backhand redirects the request to a web server in the server farm. This works pretty well. We just add more machines to the server farm as our need grows.

Mod_backhand allows you to redirect requests based on a couple of different criteria: number of used threads, cpu usage, etc.. . You can also write your own criteria. To help with testing, I wrote a criteria that would let our QA department go to the dev site, even when they pointed their browsers at the production website, www.mycompany.com. The first step was to write a new mod_backhand candidate. This new candidate will redirect requests from the QA department to the dev server, but all other requests will go to the production servers. That way, the urls the QA department sees will match what they would in production.

I use cookies to identify which users will be redirected to the dev website. First they go to the production website and get a cookie named modbackhand_test. Any requests that contain that cookie will be directed to the dev site.

Backhand removeSelf
BackhandFromSO libexec/byTest.so byTest dev.www.mycompany.com
Backhand byAge
Backhand byBusyChildren
Backhand byRandom

The criteria byTest, checks for the modbackhand_test cookie. If found, the request goes to the dev site. If the cookie is not found, then mod_backhand uses byAge, byBusyChild and byRandom to determine which server to send the request to. The only reqests that will be sent to the dev server, are requests that match the byTest candidate. When the QA department wants to stop using the dev server, they just remove the modbackhand_test cookie.

Source code for byTest.

There is still a small problem with this method. Since the dev url matches the production url, sometimes it can be hard to tell which server you are on. To get around this, I have apache add a header or footer to the webpage. There are a number of ways to do this. You can use mod_layout, proxyheaders, etc. . I want to keep the apache configuration on my dev server as close to production as possible. The servers in the farm serve up a range of pages: static content, perl/cgi, proxyied pages from tomcat, etc. . Instead of using a combination of mod_layout and others, I made a small change to httpd. This adds a header to all outgoing pages no matter where they came from (proxy, perl, static, etc.).

I modified http_protocol.c. In routine ap_finalize_request_protocol I added:

if (   !r->next
    && !r->header_only
        && yahoo_footer_check_content_type(r)
        &&!ap_table_get(r->headers_out, "Content-Length")
        &&!ap_table_get(r->headers_out, "Content-Range")
        )
{
    ap_hard_timeout("send pre-finalize body", r);
    ap_rvputs(r, " ", "TEST  SERVER", " ",
              "uncompressed", " ",
              ap_gm_timestr_822(r->pool, r->request_time),
              " \n", NULL
                          );
    ap_kill_timeout(r);
}

What this does is check if html or some binary (gif,png, etc..) is being served up. If html is being served up, the "TEST SERVER" is tacked on as a header. That makes it easier for everyone to know which server they are on.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is used to make sure you are a human visitor and to prevent spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.