Esempio n. 1
0
int http_show_state(int n)
{
    int nok = 0;
    TIMER_SAMPLE(timer);
    nok = n - ntimeouts;
    if(PT_USEC_U(timer) > 0 && nok  > 0)
    {
        if(is_quiet)
        {
            REALLOG(logger, "timeout:%d error:%d ok:%d total:%d "
                    "time used:%lld request per sec:%lld avg_time:%lld", 
                    ntimeouts, nerrors, nok, n, PT_USEC_U(timer), 
                    (((long long int)nok * 1000000ll)/PT_USEC_U(timer)),
                    (PT_USEC_U(timer)/nok));
        }
        else
        {
            fprintf(stdout, "timeout:%d error:%d ok:%d total:%d\n"
                    "time used:%lld request per sec:%lld avg_time:%lld\n", 
                    ntimeouts, nerrors, nok, n, PT_USEC_U(timer), 
                    ((long long int)nok * 1000000ll/PT_USEC_U(timer)),
                    (PT_USEC_U(timer)/nok));
        }
    }
    running_status = 0;sbase->stop(sbase);
    return 0;
}
Esempio n. 2
0
int http_show_state(int n)
{
    TIMER_SAMPLE(timer);
    if(PT_USEC_U(timer) > 0 && ncompleted > 0)
    {
        if(is_quiet)
        {
            REALLOG(logger, "timeout:%d error:%d total:%d "
                    "time used:%lld request per sec:%lld avg_time:%lld", 
                    ntimeout, nerrors, ncompleted, PT_USEC_U(timer), 
                    ((long long int)ncompleted * 1000000ll/PT_USEC_U(timer)),
                    (PT_USEC_U(timer)/ncompleted));
        }
        else
        {
            fprintf(stdout, "timeout:%d error:%d total:%d\n"
                    "time used:%lld request per sec:%lld avg_time:%lld\n", 
                    ntimeout, nerrors, ncompleted, PT_USEC_U(timer), 
                    ((long long int)ncompleted * 1000000ll/PT_USEC_U(timer)),
                    (PT_USEC_U(timer)/ncompleted));
        }
    }
    if(is_daemon == 0){running_status = 0;sbase->stop(sbase);}
    return 0;
}
Esempio n. 3
0
/* http over */
int http_over(CONN *conn, int respcode)
{
    int id = 0, n = 0, m = 0, nerror = 0, ntimeout = 0;

    if(conn)
    {
        MUTEX_LOCK(mutex);
        if(ncompleted < ntasks)
        {
            n = ++ncompleted; 
            m = nrequests;
            nerror = nerrors; 
            ntimeout = ntimeouts;
        }
        MUTEX_UNLOCK(mutex);
        //WARN_LOGGER(logger, "complete %d conn[%s:%d] via %d", n, conn->local_ip, conn->local_port, conn->fd);
        id = conn->c_id;
        if(n > 0 && n <= ntasks && (n%1000) == 0)
        {
            if(is_quiet)
            {
                REALLOG(logger, "requests:%d completed:%d error:%d timeout:%d concurrecy:%d", m, n, nerror, ntimeout, ncurrent);
            }
            else 
            {
                fprintf(stdout, "requests:%d completed:%d error:%d timeout:%d concurrecy:%d\n", m, n, nerror, ntimeout, ncurrent);
            }
        }
        if(m < ntasks)
        {
            if(conn->d_state  == 0 && is_keepalive && respcode == 200) 
            {
                return http_request(conn);
            }
            else
            {
                if(is_keepalive) conn->close(conn);
                //if(respcode != 0 && respcode != 200)nerrors++;
                if(http_newconn(id, server_ip, server_port, server_is_ssl)  == NULL) 
                {
                    if(ncurrent > 0)--ncurrent;
                }
            }
        }
        else 
        {
            --ncurrent;
            conn->close(conn);
        }
        if(running_status && n == ntasks)
        {
            return http_show_state(n);
        }
    }
    return -1;
}
Esempio n. 4
0
/* http over */
int http_over(CONN *conn, int respcode)
{
    int id = 0, n = 0;

    if(conn)
    {
        conn->over_cstate(conn);
        id = conn->c_id;
        if(ncompleted < ntasks) 
            ++ncompleted;
        else 
            return conn->over(conn);
        n = ncompleted;
        if(n > 0 && n <= ntasks && (n%1000) == 0)
        {
            if(is_quiet)
            {
                REALLOG(logger, "completed %d current:%d", n, ncurrent);
            }
            else fprintf(stdout, "completed %d current:%d\n", n, ncurrent);
        }
        if(ncompleted < ntasks)
        {
            if(conn->d_state == 0 && is_keepalive && respcode != 0) 
                return http_request(conn);
            else
            {
                conn->close(conn);
                if(respcode != 0 && respcode != 200)nerrors++;
                if(http_newconn(id, server_ip, server_port, server_is_ssl)  == NULL) 
                {
                    if(ncurrent > 0)--ncurrent;
                }
            }
        }
        else 
        {
            conn->close(conn);
            if(n == ntasks) return http_show_state(n);
        }
    }
    return -1;
}