On Mon, Jun 27, 2016 at 10:25 PM, Yann Ylavic <[email protected]> wrote:
> I thought we could later follow up on this change and optimize these
> by using the new tmp_bb field (cleanup is faster than
> create/destroy)...

Something like the attached patch.
Index: modules/proxy/mod_proxy_http.c
===================================================================
--- modules/proxy/mod_proxy_http.c      (revision 1750392)
+++ modules/proxy/mod_proxy_http.c      (working copy)
@@ -1253,7 +1253,7 @@ int ap_proxy_http_process_response(apr_pool_t * p,
     const char *buf;
     char keepchar;
     apr_bucket *e;
-    apr_bucket_brigade *bb, *tmp_bb;
+    apr_bucket_brigade *bb;
     apr_bucket_brigade *pass_bb;
     int len, backasswards;
     int interim_response = 0; /* non-zero whilst interim 1xx responses
@@ -1306,16 +1306,17 @@ int ap_proxy_http_process_response(apr_pool_t * p,
     backend->r->proxyreq = PROXYREQ_RESPONSE;
     apr_table_setn(r->notes, "proxy-source-port", apr_psprintf(r->pool, "%hu",
                    origin->local_addr->port));
-    tmp_bb = apr_brigade_create(p, c->bucket_alloc);
     do {
         apr_status_t rc;
 
         apr_brigade_cleanup(bb);
 
-        rc = ap_proxygetline(tmp_bb, buffer, sizeof(buffer), backend->r, 0, 
&len);
+        rc = ap_proxygetline(backend->tmp_bb, buffer, sizeof(buffer),
+                             backend->r, 0, &len);
         if (len == 0) {
             /* handle one potential stray CRLF */
-            rc = ap_proxygetline(tmp_bb, buffer, sizeof(buffer), backend->r, 
0, &len);
+            rc = ap_proxygetline(backend->tmp_bb, buffer, sizeof(buffer),
+                                 backend->r, 0, &len);
         }
         if (len <= 0) {
             ap_log_rerror(APLOG_MARK, APLOG_ERR, rc, r, APLOGNO(01102)
Index: modules/proxy/proxy_util.c
===================================================================
--- modules/proxy/proxy_util.c  (revision 1750392)
+++ modules/proxy/proxy_util.c  (working copy)
@@ -1298,6 +1298,7 @@ PROXY_DECLARE(apr_status_t) ap_proxy_initialize_ba
 static void socket_cleanup(proxy_conn_rec *conn)
 {
     conn->sock = NULL;
+    conn->tmp_bb = NULL;
     conn->connection = NULL;
     conn->ssl_hostname = NULL;
     apr_pool_clear(conn->scpool);
@@ -1401,7 +1402,6 @@ static apr_status_t connection_cleanup(void *theco
 PROXY_DECLARE(apr_status_t) ap_proxy_ssl_connection_cleanup(proxy_conn_rec 
*conn,
                                                             request_rec *r)
 {
-    apr_bucket_brigade *bb;
     apr_status_t rv;
 
     /*
@@ -1413,22 +1413,21 @@ PROXY_DECLARE(apr_status_t) ap_proxy_ssl_connectio
      * processed. We don't expect any data to be in the returned brigade.
      */
     if (conn->sock && conn->connection) {
-        bb = apr_brigade_create(r->pool, r->connection->bucket_alloc);
-        rv = ap_get_brigade(conn->connection->input_filters, bb,
+        rv = ap_get_brigade(conn->connection->input_filters, conn->tmp_bb,
                             AP_MODE_READBYTES, APR_NONBLOCK_READ,
                             HUGE_STRING_LEN);
         if ((rv != APR_SUCCESS) && !APR_STATUS_IS_EAGAIN(rv)) {
             socket_cleanup(conn);
         }
-        if (!APR_BRIGADE_EMPTY(bb)) {
+        if (!APR_BRIGADE_EMPTY(conn->tmp_bb)) {
             apr_off_t len;
 
-            rv = apr_brigade_length(bb, 0, &len);
+            rv = apr_brigade_length(conn->tmp_bb, 0, &len);
             ap_log_rerror(APLOG_MARK, APLOG_TRACE3, rv, r,
                           "SSL cleanup brigade contained %"
                           APR_OFF_T_FMT " bytes of data.", len);
+            apr_brigade_cleanup(conn->tmp_bb);
         }
-        apr_brigade_destroy(bb);
     }
     return APR_SUCCESS;
 }
@@ -2712,9 +2711,6 @@ PROXY_DECLARE(apr_status_t) ap_proxy_check_backend
 
     if (conn->connection) {
         conn_rec *c = conn->connection;
-        if (conn->tmp_bb == NULL) {
-            conn->tmp_bb = apr_brigade_create(c->pool, c->bucket_alloc);
-        }
         rv = ap_get_brigade(c->input_filters, conn->tmp_bb,
                             AP_MODE_SPECULATIVE, APR_NONBLOCK_READ, 1);
         if (rv == APR_SUCCESS && expect_empty) {
@@ -3046,6 +3042,7 @@ static int proxy_connection_create(const char *pro
     }
 
     bucket_alloc = apr_bucket_alloc_create(conn->scpool);
+    conn->tmp_bb = apr_brigade_create(conn->scpool, bucket_alloc);
     /*
      * The socket is now open, create a new backend server connection
      */

Reply via email to