summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2009-06-23 11:22:07 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2009-06-23 11:22:07 +0200
commitd798f5b66f4ae699f352b6c40abd07495eff8f94 (patch)
treea5b7aa9e90a6639f2b86a3d7f3a5e13615055907
parentce5869f7c41c8db943d8cbe804b69af40d43e2e6 (diff)
downloadrsyslog-d798f5b66f4ae699f352b6c40abd07495eff8f94.tar.gz
rsyslog-d798f5b66f4ae699f352b6c40abd07495eff8f94.tar.xz
rsyslog-d798f5b66f4ae699f352b6c40abd07495eff8f94.zip
some more optimizations
- done malloc() instead of calloc() for msg_t, as we have large space which needs not be initialized - shrunk syslogTime structure in the hope to get better cache and write performance (non-aligned data should not hurt much here)
-rw-r--r--runtime/msg.c51
-rw-r--r--runtime/msg.h5
-rw-r--r--runtime/obj.h2
-rw-r--r--runtime/rsyslog.h1
-rw-r--r--runtime/syslogd-types.h30
5 files changed, 70 insertions, 19 deletions
diff --git a/runtime/msg.c b/runtime/msg.c
index 1a864648..6ad0ee4f 100644
--- a/runtime/msg.c
+++ b/runtime/msg.c
@@ -425,6 +425,11 @@ rsRetVal MsgEnableThreadSafety(void)
* itself but rather uses a user-supplied value. This enables the caller
* to do some tricks to save processing time (done, for example, in the
* udp input).
+ * NOTE: this constructor does NOT call calloc(), as we have many bytes
+ * inside the structure which do not need to be cleared. bzero() will
+ * heavily thrash the cache, so we do the init manually (which also
+ * is the right thing to do with pointers, as they are not neccessarily
+ * a binary 0 on all machines [but today almost always...]).
* rgerhards, 2008-10-06
*/
static inline rsRetVal msgBaseConstruct(msg_t **ppThis)
@@ -433,15 +438,53 @@ static inline rsRetVal msgBaseConstruct(msg_t **ppThis)
msg_t *pM;
assert(ppThis != NULL);
- if((pM = calloc(1, sizeof(msg_t))) == NULL)
- ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
+ CHKmalloc(pM = malloc(sizeof(msg_t)));
+ objConstructSetObjInfo(pM); /* intialize object helper entities */
- /* initialize members that are non-zero */
+ /* initialize members in ORDER they appear in structure (think "cache line"!) */
+ pM->flowCtlType = 0;
+ pM->bDoLock = 0;
+ pM->bParseHOSTNAME = 0;
pM->iRefCount = 1;
pM->iSeverity = -1;
pM->iFacility = -1;
+ pM->offAfterPRI = 0;
pM->offMSG = -1;
- objConstructSetObjInfo(pM);
+ pM->iLenInputName = 0;
+ pM->iProtocolVersion = 0;
+ pM->msgFlags = 0;
+ pM->iLenRawMsg = 0;
+ pM->iLenMSG = 0;
+ pM->iLenTAG = 0;
+ pM->iLenHOSTNAME = 0;
+ pM->iLenRcvFrom = 0;
+ pM->iLenRcvFromIP = 0;
+ pM->pszRawMsg = NULL;
+ pM->pszHOSTNAME = NULL;
+ pM->pszRcvFrom = NULL;
+ pM->pszRcvFromIP = NULL;
+ pM->pszInputName = NULL;
+ pM->pszRcvdAt3164 = NULL;
+ pM->pszRcvdAt3339 = NULL;
+ pM->pszRcvdAt_MySQL = NULL;
+ pM->pszRcvdAt_PgSQL = NULL;
+ pM->pszTIMESTAMP3164 = NULL;
+ pM->pszTIMESTAMP3339 = NULL;
+ pM->pszTIMESTAMP_MySQL = NULL;
+ pM->pszTIMESTAMP_PgSQL = NULL;
+ pM->pCSProgName = NULL;
+ pM->pCSStrucData = NULL;
+ pM->pCSAPPNAME = NULL;
+ pM->pCSPROCID = NULL;
+ pM->pCSMSGID = NULL;
+ pM->pRuleset = NULL;
+ memset(&pM->tRcvdAt, 0, sizeof(pM->tRcvdAt));
+ memset(&pM->tTIMESTAMP, 0, sizeof(pM->tTIMESTAMP));
+ pM->TAG.pszTAG = NULL;
+ pM->pszTimestamp3164[0] = '\0';
+ pM->pszTimestamp3339[0] = '\0';
+ pM->pszTIMESTAMP_SecFrac[0] = '\0';
+ pM->pszRcvdAt_SecFrac[0] = '\0';
/* DEV debugging only! dbgprintf("msgConstruct\t0x%x, ref 1\n", (int)pM);*/
diff --git a/runtime/msg.h b/runtime/msg.h
index 0f9bd95e..9113882a 100644
--- a/runtime/msg.h
+++ b/runtime/msg.h
@@ -51,6 +51,11 @@
* will be decremented. If it is 1, however, the object is actually
* destroyed. To make this work, it is vital that MsgAddRef() is
* called each time a "copy" is stored somewhere.
+ *
+ * WARNING: this structure is not calloc()ed, so be careful when
+ * adding new fields. You need to initialize them in
+ * msgBaseConstruct(). That function header comment also describes
+ * why this is the case.
*/
struct msg {
BEGINobjInstance; /* Data to implement generic object - MUST be the first data element! */
diff --git a/runtime/obj.h b/runtime/obj.h
index 3973a16e..50868cc9 100644
--- a/runtime/obj.h
+++ b/runtime/obj.h
@@ -77,8 +77,8 @@
/* the next macro MUST be called in Constructors: */
#ifndef NDEBUG /* this means if debug... */
# define objConstructSetObjInfo(pThis) \
- ASSERT(((obj_t*) (pThis))->pObjInfo == NULL); \
((obj_t*) (pThis))->pObjInfo = pObjInfoOBJ; \
+ ((obj_t*) (pThis))->pszName = NULL; \
((obj_t*) (pThis))->iObjCooCKiE = 0xBADEFEE
#else
# define objConstructSetObjInfo(pThis) ((obj_t*) (pThis))->pObjInfo = pObjInfoOBJ
diff --git a/runtime/rsyslog.h b/runtime/rsyslog.h
index 692b1327..ac068d5e 100644
--- a/runtime/rsyslog.h
+++ b/runtime/rsyslog.h
@@ -101,6 +101,7 @@ typedef struct strmLstnPortList_s strmLstnPortList_t; // TODO: rename?
typedef long long int64;
typedef long long unsigned uint64;
typedef int64 number_t; /* type to use for numbers - TODO: maybe an autoconf option? */
+typedef char intTiny; /* 0..127! */
#ifdef __hpux
typedef unsigned int u_int32_t; /* TODO: is this correct? */
diff --git a/runtime/syslogd-types.h b/runtime/syslogd-types.h
index be0dfdd8..83b38f28 100644
--- a/runtime/syslogd-types.h
+++ b/runtime/syslogd-types.h
@@ -78,23 +78,25 @@ typedef enum _EHostnameCmpMode EHostnameCmpMode;
/* rgerhards 2004-11-11: the following structure represents
* a time as it is used in syslog.
+ * rgerhards, 2009-06-23: packed structure for better cache performance
+ * (but left ultimate decision about packing to compiler)
*/
struct syslogTime {
- int timeType; /* 0 - unitinialized , 1 - RFC 3164, 2 - syslog-protocol */
- int year;
- int month;
- int day;
- int hour; /* 24 hour clock */
- int minute;
- int second;
- int secfrac; /* fractional seconds (must be 32 bit!) */
- int secfracPrecision;
+ intTiny timeType; /* 0 - unitinialized , 1 - RFC 3164, 2 - syslog-protocol */
+ intTiny month;
+ intTiny day;
+ intTiny hour; /* 24 hour clock */
+ intTiny minute;
+ intTiny second;
+ intTiny secfracPrecision;
+ intTiny OffsetMinute; /* UTC offset in minutes */
+ intTiny OffsetHour; /* UTC offset in hours
+ * full UTC offset minutes = OffsetHours*60 + OffsetMinute. Then use
+ * OffsetMode to know the direction.
+ */
char OffsetMode; /* UTC offset + or - */
- char OffsetHour; /* UTC offset in hours */
- int OffsetMinute; /* UTC offset in minutes */
- /* full UTC offset minutes = OffsetHours*60 + OffsetMinute. Then use
- * OffsetMode to know the direction.
- */
+ short year;
+ int secfrac; /* fractional seconds (must be 32 bit!) */
};
typedef struct syslogTime syslogTime_t;