Increase LINK_TABLE_OUT_SIZE from 101 to 4001 like LINK_TABLE_IN_SIZE

to reduce performance degradation under heavy outgoing scan/flood.
Scalability is now much more important then several kilobytes of RAM.

Remove unneded TCP-specific expiration handeling. Before this connected
TCP sessions could never expire. Now connected TCP sessions will expire
after 24hours of inactivity.

Simplify HouseKeeping() to avoid several mul/div-s per packet. Taking into
account increased LINK_TABLE_OUT_SIZE, precision is still much more then
required.
This commit is contained in:
Alexander Motin 2008-06-01 18:34:58 +00:00
parent efc66711f9
commit ef30318ee9
2 changed files with 23 additions and 70 deletions

View File

@ -180,8 +180,9 @@ static LIST_HEAD(, libalias) instancehead = LIST_HEAD_INITIALIZER(instancehead)
*/
/* Parameters used for cleanup of expired links */
#define ALIAS_CLEANUP_INTERVAL_SECS 60
#define ALIAS_CLEANUP_MAX_SPOKES 30
/* NOTE: ALIAS_CLEANUP_INTERVAL_SECS must be less then LINK_TABLE_OUT_SIZE */
#define ALIAS_CLEANUP_INTERVAL_SECS 64
#define ALIAS_CLEANUP_MAX_SPOKES (LINK_TABLE_OUT_SIZE/5)
/* Timeouts (in seconds) for different link types */
#define ICMP_EXPIRE_TIME 60
@ -814,20 +815,12 @@ static void
CleanupAliasData(struct libalias *la)
{
struct alias_link *lnk;
int i, icount;
int i;
LIBALIAS_LOCK_ASSERT(la);
icount = 0;
for (i = 0; i < LINK_TABLE_OUT_SIZE; i++) {
lnk = LIST_FIRST(&la->linkTableOut[i]);
while (lnk != NULL) {
struct alias_link *link_next;
link_next = LIST_NEXT(lnk, list_out);
icount++;
while ((lnk = LIST_FIRST(&la->linkTableOut[i])) != NULL)
DeleteLink(lnk);
lnk = link_next;
}
}
la->cleanupIndex = 0;
@ -837,39 +830,13 @@ CleanupAliasData(struct libalias *la)
static void
IncrementalCleanup(struct libalias *la)
{
int icount;
struct alias_link *lnk;
struct alias_link *lnk, *lnk_tmp;
LIBALIAS_LOCK_ASSERT(la);
icount = 0;
lnk = LIST_FIRST(&la->linkTableOut[la->cleanupIndex++]);
while (lnk != NULL) {
int idelta;
struct alias_link *link_next;
link_next = LIST_NEXT(lnk, list_out);
idelta = la->timeStamp - lnk->timestamp;
switch (lnk->link_type) {
case LINK_TCP:
if (idelta > lnk->expire_time) {
struct tcp_dat *tcp_aux;
tcp_aux = lnk->data.tcp;
if (tcp_aux->state.in != ALIAS_TCP_STATE_CONNECTED
|| tcp_aux->state.out != ALIAS_TCP_STATE_CONNECTED) {
DeleteLink(lnk);
icount++;
}
}
break;
default:
if (idelta > lnk->expire_time) {
DeleteLink(lnk);
icount++;
}
break;
}
lnk = link_next;
LIST_FOREACH_SAFE(lnk, &la->linkTableOut[la->cleanupIndex++],
list_out, lnk_tmp) {
if (la->timeStamp - lnk->timestamp > lnk->expire_time)
DeleteLink(lnk);
}
if (la->cleanupIndex == LINK_TABLE_OUT_SIZE)
@ -1137,12 +1104,12 @@ _FindLinkOut(struct libalias *la, struct in_addr src_addr,
LIBALIAS_LOCK_ASSERT(la);
i = StartPointOut(src_addr, dst_addr, src_port, dst_port, link_type);
LIST_FOREACH(lnk, &la->linkTableOut[i], list_out) {
if (lnk->src_addr.s_addr == src_addr.s_addr
&& lnk->server == NULL
&& lnk->dst_addr.s_addr == dst_addr.s_addr
&& lnk->dst_port == dst_port
&& lnk->src_port == src_port
&& lnk->link_type == link_type) {
if (lnk->dst_addr.s_addr == dst_addr.s_addr &&
lnk->src_addr.s_addr == src_addr.s_addr &&
lnk->src_port == src_port &&
lnk->dst_port == dst_port &&
lnk->link_type == link_type &&
lnk->server == NULL) {
lnk->timestamp = la->timeStamp;
break;
}
@ -2189,7 +2156,7 @@ SetDestCallId(struct alias_link *lnk, u_int16_t cid)
void
HouseKeeping(struct libalias *la)
{
int i, n, n100;
int i, n;
#ifndef _KERNEL
struct timeval tv;
struct timezone tz;
@ -2209,24 +2176,14 @@ HouseKeeping(struct libalias *la)
#endif
/* Compute number of spokes (output table link chains) to cover */
n100 = LINK_TABLE_OUT_SIZE * 100 + la->houseKeepingResidual;
n100 *= la->timeStamp - la->lastCleanupTime;
n100 /= ALIAS_CLEANUP_INTERVAL_SECS;
n = n100 / 100;
n = LINK_TABLE_OUT_SIZE * (la->timeStamp - la->lastCleanupTime);
n /= ALIAS_CLEANUP_INTERVAL_SECS;
/* Handle different cases */
if (n > ALIAS_CLEANUP_MAX_SPOKES) {
n = ALIAS_CLEANUP_MAX_SPOKES;
if (n > 0) {
if (n > ALIAS_CLEANUP_MAX_SPOKES)
n = ALIAS_CLEANUP_MAX_SPOKES;
la->lastCleanupTime = la->timeStamp;
la->houseKeepingResidual = 0;
for (i = 0; i < n; i++)
IncrementalCleanup(la);
} else if (n > 0) {
la->lastCleanupTime = la->timeStamp;
la->houseKeepingResidual = n100 - 100 * n;
for (i = 0; i < n; i++)
IncrementalCleanup(la);
} else if (n < 0) {
@ -2235,7 +2192,6 @@ HouseKeeping(struct libalias *la)
fprintf(stderr, "something unexpected in time values\n");
#endif
la->lastCleanupTime = la->timeStamp;
la->houseKeepingResidual = 0;
}
}
@ -2529,7 +2485,6 @@ LibAliasInit(struct libalias *la)
la->timeStamp = tv.tv_sec;
la->lastCleanupTime = tv.tv_sec;
#endif
la->houseKeepingResidual = 0;
for (i = 0; i < LINK_TABLE_OUT_SIZE; i++)
LIST_INIT(&la->linkTableOut[i]);

View File

@ -60,7 +60,7 @@
#endif
/* Sizes of input and output link tables */
#define LINK_TABLE_OUT_SIZE 101
#define LINK_TABLE_OUT_SIZE 4001
#define LINK_TABLE_IN_SIZE 4001
struct proxy_entry;
@ -110,8 +110,6 @@ struct libalias {
* IncrementalCleanup() */
/* was called */
int houseKeepingResidual; /* used by HouseKeeping() */
int deleteAllLinks; /* If equal to zero, DeleteLink() */
/* will not remove permanent links */