From b53542336b3d0160521b6b8b994935a6c78768df Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sun, 12 Oct 2008 15:12:37 -0700 Subject: [PATCH] Avoid using DNS lookup for base server if possible. The config can specify a hardcoded IP address now. This means glibc doesn't have to load an extra shared library, reducing memory footprint by 192 kilobytes. --- nph-offload.c | 5 +++-- offload_server_config.h | 12 +++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/nph-offload.c b/nph-offload.c index fc528f7..7e18aeb 100644 --- a/nph-offload.c +++ b/nph-offload.c @@ -95,6 +95,7 @@ * -DGDEBUGDIR='"/home/icculus/offload2.icculus.org/logs"' \ * -DSHM_NAME='"mod-offload-offload2-icculus-org"' \ * -DGBASESERVER='"icculus.org"' \ + * -DGBASESERVERIP='"67.106.77.212"' \ * -DGLISTENPORT=9090 \ * -DGLISTENDAEMONIZE=1 \ * -DGLISTENTRUSTFWD='"127.0.0.1", "66.33.209.154"' \ @@ -125,7 +126,7 @@ #include #include -#define GVERSION "1.1.5" +#define GVERSION "1.1.6" #define GSERVERSTRING "nph-offload.c/" GVERSION #include "offload_server_config.h" @@ -1061,7 +1062,7 @@ static int doHttp(const char *method, list **headers) hints.ai_flags = AI_NUMERICSERV | AI_V4MAPPED | AI_ALL | AI_ADDRCONFIG; struct addrinfo *dns = NULL; - if ((rc = getaddrinfo(GBASESERVER, GBASESERVERPORTSTR, &hints, &dns)) != 0) + if ((rc = getaddrinfo(GBASESERVERIP, GBASESERVERPORTSTR, &hints, &dns)) != 0) { debugEcho("getaddrinfo failure: %s", gai_strerror(rc)); failure("503 Service Unavailable", "Offload base server hostname lookup failure."); diff --git a/offload_server_config.h b/offload_server_config.h index edfbb75..f44b2a9 100644 --- a/offload_server_config.h +++ b/offload_server_config.h @@ -69,11 +69,21 @@ #define GLOGFILE "/usr/local/apache/logs/access.log" #endif -// This is a list of servers that you are offloading. +// This is the server that you are offloading's hostname. #ifndef GBASESERVER #define GBASESERVER "example.com" #endif +// This is the server that you are offloading's IP address. +// We use this for DNS lookups (GBASESERVER is used for the "Host:" field in +// HTTP requests, etc). If you know the IP address will never change, you can +// save the several hundred kilobytes of address space that glibc uses...it +// loads a separate shared library for the DNS lookup, but it doesn't need +// to if GBASESERVERIP is an IP address in "xxx.xxx.xxx.xxx" format. +#ifndef GBASESERVERIP +#define GBASESERVERIP GBASESERVER +#endif + // This is the port on the base server to connect to (default for HTTP is 80). #ifndef GBASESERVERPORT #define GBASESERVERPORT 80