You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by mt...@apache.org on 2012/11/19 07:38:07 UTC

svn commit: r1411077 - in /tomcat/native/branches/1.1.x/native: include/tcn.h src/network.c src/poll.c

Author: mturk
Date: Mon Nov 19 06:38:06 2012
New Revision: 1411077

URL: http://svn.apache.org/viewvc?rev=1411077&view=rev
Log:
Preformance tuning. Use APR_POLLSET_NOCOPY since we always have allocated sockets and we depend on apr-1.3.x as minimum version

Modified:
    tomcat/native/branches/1.1.x/native/include/tcn.h
    tomcat/native/branches/1.1.x/native/src/network.c
    tomcat/native/branches/1.1.x/native/src/poll.c

Modified: tomcat/native/branches/1.1.x/native/include/tcn.h
URL: http://svn.apache.org/viewvc/tomcat/native/branches/1.1.x/native/include/tcn.h?rev=1411077&r1=1411076&r2=1411077&view=diff
==============================================================================
--- tomcat/native/branches/1.1.x/native/include/tcn.h (original)
+++ tomcat/native/branches/1.1.x/native/include/tcn.h Mon Nov 19 06:38:06 2012
@@ -29,6 +29,7 @@
 #include "apr_pools.h"
 #include "apr_portable.h"
 #include "apr_network_io.h"
+#include "apr_poll.h"
 #include "apr_strings.h"
 
 #ifndef APR_HAS_THREADS
@@ -154,6 +155,7 @@ typedef struct {
     tcn_nlayer_t *net;
     apr_time_t          last_active;
     apr_interval_time_t timeout;
+    apr_pollfd_t        fd;
 } tcn_socket_t;
 
 /* Private helper functions */

Modified: tomcat/native/branches/1.1.x/native/src/network.c
URL: http://svn.apache.org/viewvc/tomcat/native/branches/1.1.x/native/src/network.c?rev=1411077&r1=1411076&r2=1411077&view=diff
==============================================================================
--- tomcat/native/branches/1.1.x/native/src/network.c (original)
+++ tomcat/native/branches/1.1.x/native/src/network.c Mon Nov 19 06:38:06 2012
@@ -206,8 +206,10 @@ TCN_IMPLEMENT_CALL(jlong, Socket, create
     a->sock = s;
     if (family >= 0)
         a->net = &apr_socket_layer;
-    a->opaque   = s;
-
+    a->opaque  = s;
+    a->fd.desc_type   = APR_POLL_SOCKET;
+    a->fd.desc.s      = a->sock;
+    a->fd.client_data = a;
     return P2J(a);
 cleanup:
     if (c)
@@ -367,6 +369,9 @@ TCN_IMPLEMENT_CALL(jlong, Socket, accept
         a->net    = &apr_socket_layer;
         a->sock   = n;
         a->opaque = n;
+        a->fd.desc_type   = APR_POLL_SOCKET;
+        a->fd.desc.s      = a->sock;
+        a->fd.client_data = a;
     }
 
 cleanup:
@@ -407,6 +412,9 @@ TCN_IMPLEMENT_CALL(jlong, Socket, accept
         a->net    = &apr_socket_layer;
         a->sock   = n;
         a->opaque = n;
+        a->fd.desc_type   = APR_POLL_SOCKET;
+        a->fd.desc.s      = a->sock;
+        a->fd.client_data = a;
     }
     return P2J(a);
 cleanup:

Modified: tomcat/native/branches/1.1.x/native/src/poll.c
URL: http://svn.apache.org/viewvc/tomcat/native/branches/1.1.x/native/src/poll.c?rev=1411077&r1=1411076&r2=1411077&view=diff
==============================================================================
--- tomcat/native/branches/1.1.x/native/src/poll.c (original)
+++ tomcat/native/branches/1.1.x/native/src/poll.c Mon Nov 19 06:38:06 2012
@@ -21,8 +21,6 @@
  */
 
 #include "tcn.h"
-#include "apr_poll.h"
-
 
 #ifdef TCN_DO_STATISTICS
 static int sp_created       = 0;
@@ -39,7 +37,7 @@ typedef struct tcn_pollset {
     apr_int32_t   nalloc;
     apr_pollset_t *pollset;
     jlong         *set;
-    apr_pollfd_t  *socket_set;
+    apr_pollfd_t **socket_set;
     apr_interval_time_t default_timeout;
 #ifdef TCN_DO_STATISTICS
     int sp_added;
@@ -103,7 +101,7 @@ TCN_IMPLEMENT_CALL(jlong, Poll, create)(
     apr_pool_t *p = J2P(pool, apr_pool_t *);
     apr_pollset_t *pollset = NULL;
     tcn_pollset_t *tps = NULL;
-    apr_uint32_t f = (apr_uint32_t)flags;
+    apr_uint32_t f = (apr_uint32_t)flags | APR_POLLSET_NOCOPY;
     UNREFERENCED(o);
     TCN_ASSERT(pool != 0);
 
@@ -125,7 +123,7 @@ TCN_IMPLEMENT_CALL(jlong, Poll, create)(
     tps->pollset = pollset;
     tps->set        = apr_palloc(p, size * sizeof(jlong) * 2);
     TCN_CHECK_ALLOCATED(tps->set);
-    tps->socket_set = apr_palloc(p, size * sizeof(apr_pollfd_t));
+    tps->socket_set = apr_palloc(p, size * sizeof(apr_pollfd_t *));
     TCN_CHECK_ALLOCATED(tps->socket_set);
     tps->nelts  = 0;
     tps->nalloc = size;
@@ -160,7 +158,6 @@ static apr_status_t do_add(tcn_pollset_t
                            apr_interval_time_t socket_timeout) {
 
     apr_interval_time_t timeout = socket_timeout;
-    apr_pollfd_t fd;
 
     if (p->nelts == p->nalloc) {
 #ifdef TCN_DO_STATISTICS
@@ -176,20 +173,15 @@ static apr_status_t do_add(tcn_pollset_t
     else
         s->last_active = 0;
     s->timeout = socket_timeout;
+    s->fd.reqevents = reqevents;
 
-    memset(&fd, 0, sizeof(apr_pollfd_t));
-    fd.desc_type = APR_POLL_SOCKET;
-    fd.reqevents = reqevents;
-    fd.desc.s    = s->sock;
-    fd.client_data = s;
-
-    p->socket_set[p->nelts] = fd;
+    p->socket_set[p->nelts] = &s->fd;
     p->nelts++;
 #ifdef TCN_DO_STATISTICS
     p->sp_added++;
     p->sp_max_count = TCN_MAX(p->sp_max_count, p->sp_added);
 #endif
-    return (jint)apr_pollset_add(p->pollset, &fd);
+    return (jint)apr_pollset_add(p->pollset, &s->fd);
 }
 
 TCN_IMPLEMENT_CALL(jint, Poll, add)(TCN_STDARGS, jlong pollset,
@@ -222,18 +214,18 @@ static apr_status_t do_remove(tcn_pollse
     apr_int32_t i;
 
     for (i = 0; i < p->nelts; i++) {
-        if (fd->desc.s == p->socket_set[i].desc.s) {
+        if (fd->desc.s == p->socket_set[i]->desc.s) {
             /* Found an instance of the fd: remove this and any other copies */
             apr_int32_t dst = i;
             apr_int32_t old_nelts = p->nelts;
-            tcn_socket_t *ds = (tcn_socket_t *)p->socket_set[dst].client_data;
+            tcn_socket_t *ds = (tcn_socket_t *)p->socket_set[dst]->client_data;
             p->nelts--;
 #ifdef TCN_DO_STATISTICS
             p->sp_removed++;
 #endif
             for (i++; i < old_nelts; i++) {
-                tcn_socket_t *ss = (tcn_socket_t *)p->socket_set[i].client_data;
-                if (fd->desc.s == p->socket_set[i].desc.s) {
+                tcn_socket_t *ss = (tcn_socket_t *)p->socket_set[i]->client_data;
+                if (fd->desc.s == p->socket_set[i]->desc.s) {
 #ifdef TCN_DO_STATISTICS
                     p->sp_equals++;
 #endif
@@ -243,7 +235,7 @@ static apr_status_t do_remove(tcn_pollse
                     p->socket_set[dst] = p->socket_set[i];
                     ds->last_active = ss->last_active;
                     ds->timeout     = ss->timeout;
-                    ds = (tcn_socket_t *)p->socket_set[++dst].client_data;
+                    ds = (tcn_socket_t *)p->socket_set[++dst]->client_data;
                 }
             }
             break;
@@ -257,8 +249,8 @@ static void update_last_active(tcn_polls
     apr_int32_t i;
 
     for (i = 0; i < p->nelts; i++) {
-        if (fd->desc.s == p->socket_set[i].desc.s) {
-            tcn_socket_t *s = (tcn_socket_t *)p->socket_set[i].client_data;
+        if (fd->desc.s == p->socket_set[i]->desc.s) {
+            tcn_socket_t *s = (tcn_socket_t *)p->socket_set[i]->client_data;
             /* Found an instance of the fd: update last active time */
             s->last_active = t;
             break;
@@ -272,20 +264,16 @@ TCN_IMPLEMENT_CALL(jint, Poll, remove)(T
 {
     tcn_pollset_t *p = J2P(pollset,  tcn_pollset_t *);
     tcn_socket_t *s  = J2P(socket, tcn_socket_t *);
-    apr_pollfd_t fd;
 
     UNREFERENCED_STDARGS;
     TCN_ASSERT(socket != 0);
 
-    memset(&fd, 0, sizeof(apr_pollfd_t));
-    fd.desc_type = APR_POLL_SOCKET;
-    fd.desc.s    = s->sock;
-    fd.reqevents = APR_POLLIN | APR_POLLOUT;
+    s->fd.reqevents = APR_POLLIN | APR_POLLOUT;
 #ifdef TCN_DO_STATISTICS
     p->sp_remove++;
 #endif
 
-    return (jint)do_remove(p, &fd);
+    return (jint)do_remove(p, &s->fd);
 }
 
 
@@ -312,7 +300,7 @@ TCN_IMPLEMENT_CALL(jint, Poll, poll)(TCN
         /* Find the minimum timeout */
         for (i = 0; i < p->nelts; i++) {
             apr_interval_time_t socket_timeout = 0;
-            tcn_socket_t *s = (tcn_socket_t *)p->socket_set[i].client_data;
+            tcn_socket_t *s = (tcn_socket_t *)p->socket_set[i]->client_data;
             if (s->timeout == TCN_NO_SOCKET_TIMEOUT) {
                 socket_timeout = p->default_timeout;
             }
@@ -381,7 +369,7 @@ TCN_IMPLEMENT_CALL(jint, Poll, maintain)
     tcn_pollset_t *p = J2P(pollset,  tcn_pollset_t *);
     apr_int32_t  i = 0, num = 0;
     apr_time_t now = apr_time_now();
-    apr_pollfd_t fd;
+    apr_pollfd_t *fd;
 
     UNREFERENCED(o);
     TCN_ASSERT(pollset != 0);
@@ -389,7 +377,7 @@ TCN_IMPLEMENT_CALL(jint, Poll, maintain)
     /* Check for timeout sockets */
     for (i = 0; i < p->nelts; i++) {
         apr_interval_time_t timeout = 0;
-        tcn_socket_t *s = (tcn_socket_t *)p->socket_set[i].client_data;
+        tcn_socket_t *s = (tcn_socket_t *)p->socket_set[i]->client_data;
         if (s->timeout == TCN_NO_SOCKET_TIMEOUT) {
             timeout = p->default_timeout;
         }
@@ -404,16 +392,14 @@ TCN_IMPLEMENT_CALL(jint, Poll, maintain)
         }
     }
     if (remove && num) {
-        memset(&fd, 0, sizeof(apr_pollfd_t));
 #ifdef TCN_DO_STATISTICS
          p->sp_maintained += num;
          p->sp_max_maintained = TCN_MAX(p->sp_max_maintained, num);
 #endif
         for (i = 0; i < num; i++) {
-            fd.desc_type = APR_POLL_SOCKET;
-            fd.reqevents = APR_POLLIN | APR_POLLOUT;
-            fd.desc.s = (J2P(p->set[i], tcn_socket_t *))->sock;
-            do_remove(p, &fd);
+            fd = &(J2P(p->set[i], tcn_socket_t *)->fd);
+            fd->reqevents = APR_POLLIN | APR_POLLOUT;
+            do_remove(p, fd);
         }
     }
     if (num)
@@ -440,17 +426,17 @@ TCN_IMPLEMENT_CALL(jint, Poll, pollset)(
                                         jlongArray set)
 {
     tcn_pollset_t *p = J2P(pollset,  tcn_pollset_t *);
-    apr_int32_t  i = 0;
-    apr_pollfd_t fd;
+    apr_int32_t   i = 0;
+    apr_pollfd_t *fd;
 
     UNREFERENCED(o);
     TCN_ASSERT(pollset != 0);
 
     for (i = 0; i < p->nelts; i++) {
-        p->socket_set[i].rtnevents = APR_POLLHUP | APR_POLLIN;
+        p->socket_set[i]->rtnevents = APR_POLLHUP | APR_POLLIN;
         fd = p->socket_set[i];
-        p->set[i*2+0] = (jlong)(fd.rtnevents);
-        p->set[i*2+1] = P2J(fd.client_data);
+        p->set[i*2+0] = (jlong)(fd->rtnevents);
+        p->set[i*2+1] = P2J(fd->client_data);
     }
     if (p->nelts)
         (*e)->SetLongArrayRegion(e, set, 0, p->nelts * 2, p->set);



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org