镜像分发工具压测解决方案——hijack压测

来源:互联网 发布:淘宝加盟代理 编辑:程序博客网 时间:2024/06/05 02:49
最近需要对缓存代理服务器的镜像重定向分发工具做压力测试,需要做到下面的要求:

1,为了保证流量足够大和不影响其他网络的正常访问,整个测试流程最好在局域内完成;

2,压测结果必须能够实时有效的显示

经研究提出了下面的解决方案,如图:

架构设计图

1,由webbench做压测客户端,压测结果可实时显示在界面上
2,客户端到nginx web上请求,再有hijack模拟数据返回,具体操作流程如下:
A:hijack抓取网卡数据,并将构造的数据模拟nginx web返回给客户端
B:Nginx Web延迟数据返回,这个需要修改Nginx源代码才可以实现

Niginx修改到的http的入口程序源码文件——ngx_http_request.c

voidngx_http_process_request(ngx_http_request_t *r){    ngx_connection_t  *c;    c = r->connection;    //此处为修改到的源码    ngx_msleep(16);#if (NGX_HTTP_SSL)    if (r->http_connection->ssl) {        long                      rc;        X509                     *cert;        ngx_http_ssl_srv_conf_t  *sscf;        if (c->ssl == NULL) {            ngx_log_error(NGX_LOG_INFO, c->log, 0,                          "client sent plain HTTP request to HTTPS port");            ngx_http_finalize_request(r, NGX_HTTP_TO_HTTPS);            return;        }        sscf = ngx_http_get_module_srv_conf(r, ngx_http_ssl_module);        if (sscf->verify) {            rc = SSL_get_verify_result(c->ssl->connection);            if (rc != X509_V_OK                && (sscf->verify != 3 || !ngx_ssl_verify_error_optional(rc)))            {                ngx_log_error(NGX_LOG_INFO, c->log, 0,                              "client SSL certificate verify error: (%l:%s)",                              rc, X509_verify_cert_error_string(rc));                ngx_ssl_remove_cached_session(sscf->ssl.ctx,                                       (SSL_get0_session(c->ssl->connection)));                ngx_http_finalize_request(r, NGX_HTTPS_CERT_ERROR);                return;            }            if (sscf->verify == 1) {                cert = SSL_get_peer_certificate(c->ssl->connection);                if (cert == NULL) {                    ngx_log_error(NGX_LOG_INFO, c->log, 0,                                  "client sent no required SSL certificate");                    ngx_ssl_remove_cached_session(sscf->ssl.ctx,                                       (SSL_get0_session(c->ssl->connection)));                    ngx_http_finalize_request(r, NGX_HTTPS_NO_CERT);                    return;                }                X509_free(cert);            }        }    }#endif    if (c->read->timer_set) {        ngx_del_timer(c->read);    }#if (NGX_STAT_STUB)    (void) ngx_atomic_fetch_add(ngx_stat_reading, -1);    r->stat_reading = 0;    (void) ngx_atomic_fetch_add(ngx_stat_writing, 1);    r->stat_writing = 1;#endif    c->read->handler = ngx_http_request_handler;    c->write->handler = ngx_http_request_handler;    r->read_event_handler = ngx_http_block_reading;    ngx_http_handler(r);    ngx_http_run_posted_requests(c);}
0 0