[AWS] Confirm Apache Bench "weirdness"

Thomas Løcke thomas.granvej6 at gmail.com
Wed Feb 2 09:40:38 CET 2011

Hey all,

I've grabbed the C source for Apache Bench, and as far as I can see,
there is a problem with how the total amount of received bytes are

Here's the source: http://pastebin.com/pgmdZGmK

The three important variables are:

    int requests = 1;       /* Number of requests to make */
    apr_int64_t totalbread = 0;   /* totoal amount of entity body read */
    int done = 0;              /* number of requests we have done */

"totalbread" is the variable used in the "HTML transferred" output,
and "done" is the "Complete requests".

"done" is increased whenever a connection has finished, and
"totalbread" is increased with the size of the body received. The
funny thing is that, as far as I can see, every time "done" is
increased, it happens behind a guard like this:

    if (done < requests) {

OTOH "totalbread" is simply increased when there's data on the socket:

    else {
        /* outside header, everything we have read is entity body */
        c->bread += r;
        totalbread += r;

But why does Apache Bench connect to AWS more than "requests" amount
of times? Well, in the test() function we see this:

    /* initialise lots of requests */
    for (i = 0; i < concurrency; i++) {
        con[i].socknum = i;

And in start_connect() we have this:

    if (!(started < requests))

Which appears to be a guard against starting too many requests, but
seeing as "started" is only increased at the very end of the
start_connect() function:

    /* connected first time */
    set_conn_state(c, STATE_CONNECTED);

and new connections are started as soon as a connection is closed, as
can be seen in close_connection():

    /* connect again */

There might very well arise a race condition if the server is _very_
fast, so that "magic" stuff can happen between the "if"(!(started <
requests))" guard and the "started++;" call.

Does this sound plausible, and if so, would it be possible to fix this
annoyance in Apache Bench? Or is it simply the nature of the beast?

Thomas Løcke

More information about the AWS mailing list