You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Marc Slemko <ma...@znep.com> on 1998/02/16 20:08:39 UTC

mod_webbench

Below is a mod_webbench I made to output the stuff that ZD's WebBench
wants for dynamic content.  Any comments or errors would be
appreciated.  It doesn't appear like they are willing to make the
massive changes required to include it in this test (although I
will certainly do everything I can to make sure it is done in the
future) but you never know...

Yes, I could speed it up by redoing add_*_vars and not using table_get
but going through the table myself and having a hash or whatever of 
what I want.  But...

This actually gives be better rates than serving static content from
disk in some situations.

/*
 * mod_webbench: written to output the data that Ziff Davis's WebBench 
 * program requires for dynamic content tests.
 *
 * To enable, add something resembling the following into one of your
 * Apache config files:
 *
 * <Location /webbench>
 * SetHandler webbench-handler
 * </Location>
 *
 * ...and restart the server.  Then all request for a document under 
 * "/webbench will be processed by this handler.
 *
 * Written by Marc Slemko <ma...@znep.com>, 98/02/16
 *
 * This code may be freely distributed and used, and integrated into any
 * other product.  
 *
 *
 * Notes: 
 *  - Different servers set different subsets of the requested variables, 
 *    which means that some will have larger responses.  In general, the
 *    larger the response the more total data that can be put onto the 
 *    network.
 *  - The results depend far too much on the code used by the server to 
 *    set and search for environment variables.  In Apache 1.2, this is a 
 *    linear search to set or retrieve each variable.  This clearly doesn't
 *    test the typical case of dynamic content.
 *  - Setting the content-length header actually is a loss if the test
 *    does not attempt persistent connections because we have more 
 *    header overhead, and WebBench (bogusly) does not include that
 *    at all in the final numbers.
 */

#include "httpd.h"
#include "http_config.h"
#include "http_core.h"
#include "http_protocol.h"
#include "http_main.h"
#include "util_script.h"

module webbench_module;

/* 
 * the list of variables that should be output, excluding content-length
 */
static char *names[] =  {
    "SERVER_SOFTWARE",
    "SERVER_NAME",
    "GATEWAY_INTERFACE",
    "SERVER_PROTOCOL",
    "SERVER_PORT",
    "REQUEST_METHOD",
    "HTTP_ACCEPT",
    "HTTP_USER_AGENT",
    "HTTP_REFERER",
    "PATH_INFO",
    "PATH_TRANSLATED",
    "SCRIPT_NAME",
    "QUERY_STRING",
    "REMOTE_HOST",
    "REMOTE_ADDR",
    "REMOTE_USER",
    "AUTH_TYPE",
    "CONTENT_TYPE",
    "ANNOTATION_SERVER",
    NULL
};

/* the length of the buffer allocated for output */
#define SEND_LENGTH 4000
/* the number of bytes left in the output buffer; if the response ends up
 * being too large, it will simply be truncated.  That is, however, _very_
 * unlikely due to the relatively fixed nature of the content.
 */
#define LEN_LEFT (send_start + SEND_LENGTH - send_data)

/*
 * the guts of the module.  Handles requests directed to it and spits
 * out to the client.
 */
int webbench_handler (request_rec *r)
{
    int i = 0;
    int content_length;
    char *send_data = palloc(r->pool, SEND_LENGTH);
    char *send_start;

    send_start = send_data;

    /* we only implement GET */
    r->allowed = (1 << M_GET) | (1 << M_TRACE);
    if (r->method_number != M_GET) return HTTP_METHOD_NOT_ALLOWED;

    r->content_type = "text/html";

    /*
     * add all the environment variables that a CGI would get
     */
    add_common_vars(r);
    add_cgi_vars(r);
    
    send_data += ap_snprintf(send_data, LEN_LEFT, 
	"<HTML><HEAD> <TITLE>WebBench 1.1 "
	"Apache API Application</TITLE></HEAD><BODY><BR>");

    while (names[i]) {
        char *e = table_get(r->subprocess_env, names[i]);
    	if (e) {
    	    send_data += ap_snprintf(send_data, 
		LEN_LEFT, "%s = %s<BR>", names[i], e);
    	} else {
    	    send_data += ap_snprintf(send_data, 
		LEN_LEFT, "%s = <BR>", names[i]);
    	}
    	i++;
    }

    /* 
     * To allow for persistent (aka keepalive) connections, we need to 
     * figure out the content-length ahead of time.  We go under the 
     * assumption that it can not be longer than 5 digits, which is a 
     * fair assumption for this module.
     */
    content_length = send_data - send_start + 
	strlen("CONTENT_LENGTH = 00000</BODY></HTML>\n");
    send_data += ap_snprintf(send_data, LEN_LEFT, 
	"CONTENT_LENGTH = %05d</BODY></HTML>\n", content_length);

    /* now set the content-length header, then send the headers */
    set_content_length(r, send_data - send_start);
    send_http_header(r);
    if (r->header_only) 
	return 0;

    /* finally, output the body all at once */
    rputs(send_start, r);

    return 0;
}

handler_rec webbench_handlers[] =
{
    { "webbench-handler", webbench_handler },
    { NULL }
};

module webbench_module =
{
   STANDARD_MODULE_STUFF,
   NULL,			/* initializer */
   NULL,			/* dir config creater */
   NULL,			/* dir merger --- default is to override */
   NULL,			/* server config */
   NULL,			/* merge server config */
   NULL,			/* command table */
   webbench_handlers,		/* handlers */
   NULL,			/* filename translation */
   NULL,			/* check_user_id */
   NULL,			/* check auth */
   NULL,			/* check access */
   NULL,			/* type_checker */
   NULL,			/* fixups */
   NULL,			/* logger */
   NULL				/* header parser */
};


Re: mod_webbench

Posted by Marc Slemko <ma...@worldgate.com>.
On Mon, 16 Feb 1998, Marc Slemko wrote:

> Below is a mod_webbench I made to output the stuff that ZD's WebBench
> wants for dynamic content.  Any comments or errors would be
> appreciated.  It doesn't appear like they are willing to make the
> massive changes required to include it in this test (although I
> will certainly do everything I can to make sure it is done in the
> future) but you never know...

Oh, let me note that I am leaving in three hours or so for the airport
and may not check email until Thursday when I'm back (a laptop, a laptop...
all my old O'Reillys for a laptop...) so any comments need be soon.