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/05/29 10:59:33 UTC
svn commit: r1343608 - in /tomcat/native/trunk/native: include/tcn.h
src/poll.c
Author: mturk
Date: Tue May 29 08:59:33 2012
New Revision: 1343608
URL: http://svn.apache.org/viewvc?rev=1343608&view=rev
Log:
Port per-socket timeout optimization from 1.1.x branch
Modified:
tomcat/native/trunk/native/include/tcn.h
tomcat/native/trunk/native/src/poll.c
Modified: tomcat/native/trunk/native/include/tcn.h
URL: http://svn.apache.org/viewvc/tomcat/native/trunk/native/include/tcn.h?rev=1343608&r1=1343607&r2=1343608&view=diff
==============================================================================
--- tomcat/native/trunk/native/include/tcn.h (original)
+++ tomcat/native/trunk/native/include/tcn.h Tue May 29 08:59:33 2012
@@ -25,6 +25,7 @@
#include "apr.h"
#include "apr_general.h"
+#include "apr_lib.h"
#include "apr_pools.h"
#include "apr_portable.h"
#include "apr_network_io.h"
@@ -151,6 +152,8 @@ typedef struct {
char *jsbbuff;
char *jrbbuff;
tcn_nlayer_t *net;
+ apr_time_t last_active;
+ apr_interval_time_t timeout;
} tcn_socket_t;
/* Private helper functions */
Modified: tomcat/native/trunk/native/src/poll.c
URL: http://svn.apache.org/viewvc/tomcat/native/trunk/native/src/poll.c?rev=1343608&r1=1343607&r2=1343608&view=diff
==============================================================================
--- tomcat/native/trunk/native/src/poll.c (original)
+++ tomcat/native/trunk/native/src/poll.c Tue May 29 08:59:33 2012
@@ -40,8 +40,6 @@ typedef struct tcn_pollset {
apr_pollset_t *pollset;
jlong *set;
apr_pollfd_t *socket_set;
- apr_time_t *socket_last_active;
- apr_interval_time_t *socket_timeout;
apr_interval_time_t default_timeout;
jboolean wakeable;
#ifdef TCN_DO_STATISTICS
@@ -167,10 +165,6 @@ TCN_IMPLEMENT_CALL(jlong, Poll, create)(
TCN_CHECK_ALLOCATED(tps->set);
tps->socket_set = apr_palloc(p, size * sizeof(apr_pollfd_t));
TCN_CHECK_ALLOCATED(tps->socket_set);
- tps->socket_last_active = apr_palloc(p, size * sizeof(apr_time_t));
- TCN_CHECK_ALLOCATED(tps->socket_last_active);
- tps->socket_timeout = apr_palloc(p, size * sizeof(apr_interval_time_t));
- TCN_CHECK_ALLOCATED(tps->socket_timeout);
tps->nelts = 0;
tps->nalloc = size;
tps->pool = p;
@@ -218,21 +212,21 @@ static apr_status_t do_add(tcn_pollset_t
#endif
return APR_ENOMEM;
}
- 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;
-
if (timeout == TCN_NO_SOCKET_TIMEOUT) {
timeout = p->default_timeout;
}
if (timeout > 0)
- p->socket_last_active[p->nelts] = apr_time_now();
+ s->last_active = apr_time_now();
else
- p->socket_last_active[p->nelts] = 0;
+ s->last_active = 0;
+ s->timeout = socket_timeout;
+
+ 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_timeout[p->nelts] = socket_timeout;
p->socket_set[p->nelts] = fd;
p->nelts++;
#ifdef TCN_DO_STATISTICS
@@ -276,11 +270,13 @@ static apr_status_t do_remove(tcn_pollse
/* 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;
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) {
#ifdef TCN_DO_STATISTICS
p->sp_equals++;
@@ -289,9 +285,9 @@ static apr_status_t do_remove(tcn_pollse
}
else {
p->socket_set[dst] = p->socket_set[i];
- p->socket_last_active[dst] = p->socket_last_active[i];
- p->socket_timeout[dst] = p->socket_timeout[i];
- dst++;
+ ds->last_active = ss->last_active;
+ ds->timeout = ss->timeout;
+ ds = (tcn_socket_t *)p->socket_set[++dst].client_data;
}
}
break;
@@ -306,8 +302,9 @@ static void update_last_active(tcn_polls
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;
/* Found an instance of the fd: update last active time */
- p->socket_last_active[i] = t;
+ s->last_active = t;
break;
}
}
@@ -371,14 +368,15 @@ 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;
- if (p->socket_timeout[i] == TCN_NO_SOCKET_TIMEOUT) {
+ 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;
}
else {
- socket_timeout = p->socket_timeout[i];
+ socket_timeout = s->timeout;
}
if (socket_timeout >= 0) {
- apr_interval_time_t t = now - p->socket_last_active[i];
+ apr_interval_time_t t = now - s->last_active;
if (t >= socket_timeout) {
ptime = 0;
break;
@@ -447,18 +445,18 @@ TCN_IMPLEMENT_CALL(jint, Poll, maintain)
/* Check for timeout sockets */
for (i = 0; i < p->nelts; i++) {
apr_interval_time_t timeout = 0;
- if (p->socket_timeout[i] == TCN_NO_SOCKET_TIMEOUT) {
+ tcn_socket_t *s = (tcn_socket_t *)p->socket_set[i].client_data;
+ if (s->timeout == TCN_NO_SOCKET_TIMEOUT) {
timeout = p->default_timeout;
}
else {
- timeout = p->socket_timeout[i];
+ timeout = s->timeout;
}
if (timeout == -1) {
continue;
}
- if ((now - p->socket_last_active[i]) >= timeout) {
- fd = p->socket_set[i];
- p->set[num++] = P2J(fd.client_data);
+ if ((now - s->last_active) >= timeout) {
+ p->set[num++] = P2J(s);
}
}
if (remove && num) {
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org