ApacheBench

 view release on metacpan or  search on metacpan

src/apachebench/execute.c  view on Meta::CPAN

        registry->con[i].run = registry->ready_to_run_queue[i].run;
        registry->con[i].state = STATE_READY;
        registry->con[i].thread = registry->ready_to_run_queue[i].thread;
    }

#ifdef AB_DEBUG
    printf("AB_DEBUG: test() - stage 1\n");
#endif

    registry->stats = calloc(registry->number_of_urls, sizeof(struct data *));
    for (i = 0; i < registry->number_of_runs; i++) {
        int j;
        for (j = registry->position[i]; j < registry->position[i+1]; j++)
            registry->stats[j] = calloc(registry->repeats[i], sizeof(struct data));
    }

#ifdef AB_DEBUG
    printf("AB_DEBUG: test() - stage 2\n");
#endif

    FD_ZERO(&registry->readbits);
    FD_ZERO(&registry->writebits);

#ifdef AB_DEBUG
    printf("AB_DEBUG: test() - stage 3\n");
#endif

    /* ok - lets start */
    gettimeofday(&registry->starttime, 0);

#ifdef AB_DEBUG
    printf("AB_DEBUG: test() - stage 4\n");
#endif

    /* initialise lots of requests */

    registry->head = registry->concurrency;
    for (i = 0; i < registry->concurrency; i++)
        start_connect(registry, &registry->con[i]);

#ifdef AB_DEBUG
    printf("AB_DEBUG: test() - stage 5\n");
#endif

    while (registry->done < registry->need_to_be_done) {
        int n;

#ifdef AB_DEBUG
        printf("AB_DEBUG: test() - stage 5.1, registry->done = %d\n", registry->done);
#endif

        /* setup bit arrays */
        memcpy(&sel_except, &registry->readbits, sizeof(registry->readbits));
        memcpy(&sel_read, &registry->readbits, sizeof(registry->readbits));
        memcpy(&sel_write, &registry->writebits, sizeof(registry->writebits));

#ifdef AB_DEBUG
        printf("AB_DEBUG: test() - stage 5.2, registry->done = %d\n", registry->done);
#endif

        /* Timeout of 30 seconds, or minimum time limit specified by config. */
        timeout.tv_sec = registry->min_tlimit.tv_sec;
        timeout.tv_usec = registry->min_tlimit.tv_usec;
        n = select(FD_SETSIZE, &sel_read, &sel_write, &sel_except, &timeout);
#ifdef AB_DEBUG
        printf("AB_DEBUG: test() - stage 5.3, registry->done = %d\n", registry->done);
#endif
        if (!n)
            myerr(registry->warn_and_error, "Server timed out");
        if (n < 1)
            myerr(registry->warn_and_error, "Select error.");
#ifdef AB_DEBUG
        printf("AB_DEBUG: test() - stage 5.4, registry->done = %d\n", registry->done);
#endif
        /* check for time limit expiry */
        gettimeofday(&now, 0);
        if (registry->tlimit &&
            timedif(now, registry->starttime) > (registry->tlimit * 1000)) {
            char *warn = malloc(256 * sizeof(char));
            sprintf(warn, "Global time limit reached (%.2f sec), premature exit", registry->tlimit);
            myerr(registry->warn_and_error, warn);
            free(warn);
            registry->need_to_be_done = registry->done;        /* break out of loop */
        }

        for (i = 0; i < registry->concurrency; i++) {
            int s = registry->con[i].fd;
#ifdef AB_DEBUG
            printf("AB_DEBUG: test() - stage 5.5, registry->done = %d, i = %d\n", registry->done, i);
#endif
            if (registry->started[registry->con[i].url]
                > registry->finished[registry->con[i].url]) {
                struct connection * c = &registry->con[i];
                struct timeval url_now;

                /* check for per-url time limit expiry */
                gettimeofday(&url_now, 0);

#ifdef AB_DEBUG
                printf("AB_DEBUG: test() - stage 5.5.4, Time taken for current request = %d ms; Per-url time limit = %.4f sec; for run %d, url %d\n", timedif(url_now, c->start_time), registry->url_tlimit[c->url], c->run, c->url - registry->position[c...
                printf("AB_DEBUG: test() - stage 5.5.5, registry->done = %d, i = %d\n", registry->done, i);
#endif
                if (registry->url_tlimit[c->url] &&
                    timedif(url_now, c->start_time) > (registry->url_tlimit[c->url] * 1000)) {
                    char *warn = malloc(256 * sizeof(char));
#ifdef AB_DEBUG
                    printf("AB_DEBUG: test() - stage 5.5.5.3, registry->done = %d, i = %d\n", registry->done, i);
#endif
                    sprintf(warn, "Per-url time limit reached (%.3f sec) for run %d, url %d, iteration %d; connection closed prematurely", registry->url_tlimit[c->url], c->run, c->url - registry->position[c->run], c->thread);
                    myerr(registry->warn_and_error, warn);
                    free(warn);

                    registry->failed[c->url]++;
                    close_connection(registry, c);
                    continue;
                }
            }

            if (registry->con[i].state == STATE_DONE)
                continue;
#ifdef AB_DEBUG



( run in 0.861 second using v1.01-cache-2.11-cpan-39bf76dae61 )