aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2008-10-26 07:14:48 +0300
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2008-10-26 07:14:48 +0300
commitcc5343692b448c27485a24ea7f1b24d714bb82f6 (patch)
treed659a1795fad4da55e18c8fc6297233d5b71b57e
parentc52d0879cc03345a6c41c724db6a3de59cca7d07 (diff)
downloadrspamd-cc5343692b448c27485a24ea7f1b24d714bb82f6.tar.gz
rspamd-cc5343692b448c27485a24ea7f1b24d714bb82f6.zip
* Add determining page size function to mem_pool library
* Add simple statistic structure that is placed in shared memory and used for gathering server's stats
-rw-r--r--controller.c7
-rw-r--r--main.c6
-rw-r--r--main.h15
-rw-r--r--mem_pool.c11
-rw-r--r--mem_pool.h3
-rw-r--r--worker.c9
6 files changed, 39 insertions, 12 deletions
diff --git a/controller.c b/controller.c
index 3f4f9b358..1efb8c35c 100644
--- a/controller.c
+++ b/controller.c
@@ -282,12 +282,9 @@ accept_socket (int fd, short what, void *arg)
new_session->worker = worker;
new_session->sock = nfd;
new_session->cfg = worker->srv->cfg;
-#ifdef HAVE_GETPAGESIZE
- new_session->session_pool = memory_pool_new (getpagesize () - 1);
-#else
- new_session->session_pool = memory_pool_new (4095);
-#endif
+ new_session->session_pool = memory_pool_new (memory_pool_get_size () - 1);
memory_pool_add_destructor (new_session->session_pool, (pool_destruct_func)bufferevent_free, new_session->bev);
+ worker->srv->stat->control_connections_count ++;
/* Read event */
new_session->bev = bufferevent_new (nfd, read_socket, write_socket, err_socket, (void *)new_session);
diff --git a/main.c b/main.c
index 81effd61d..d2dec7e47 100644
--- a/main.c
+++ b/main.c
@@ -172,6 +172,7 @@ main (int argc, char **argv)
rspamd = (struct rspamd_main *)g_malloc (sizeof (struct rspamd_main));
bzero (rspamd, sizeof (struct rspamd_main));
+ rspamd->server_pool = memory_pool_new (memory_pool_get_size ());
cfg = (struct config_file *)g_malloc (sizeof (struct config_file));
rspamd->cfg = cfg;
if (!rspamd || !rspamd->cfg) {
@@ -186,8 +187,11 @@ main (int argc, char **argv)
do_reopen_log = 0;
active_worker = NULL;
+ rspamd->stat = memory_pool_alloc_shared (rspamd->server_pool, sizeof (struct rspamd_stat));
+ bzero (rspamd->stat, sizeof (struct rspamd_stat));
+
bzero (rspamd->cfg, sizeof (struct config_file));
- rspamd->cfg->cfg_pool = memory_pool_new (32768);
+ rspamd->cfg->cfg_pool = memory_pool_new (memory_pool_get_size ());
init_defaults (rspamd->cfg);
bzero (&signals, sizeof (struct sigaction));
diff --git a/main.h b/main.h
index 3a4671bfb..efb716ab0 100644
--- a/main.h
+++ b/main.h
@@ -82,6 +82,16 @@ struct rspamd_worker {
struct pidfh;
struct config_file;
+/* Server statistics */
+struct rspamd_stat {
+ unsigned int messages_scanned;
+ unsigned int messages_spam;
+ unsigned int messages_ham;
+ unsigned int connections_count;
+ unsigned int control_connections_count;
+ unsigned int messages_learned;
+};
+
/* Struct that determine main server object (for logging purposes) */
struct rspamd_main {
struct config_file *cfg;
@@ -89,7 +99,10 @@ struct rspamd_main {
/* Pid file structure */
struct pidfh *pfh;
enum process_type type;
- unsigned ev_initialized:1;
+ unsigned int ev_initialized;
+ struct rspamd_stat *stat;
+
+ memory_pool_t *server_pool;
TAILQ_HEAD (workq, rspamd_worker) workers;
};
diff --git a/mem_pool.c b/mem_pool.c
index f720138dc..f116fff73 100644
--- a/mem_pool.c
+++ b/mem_pool.c
@@ -344,6 +344,17 @@ memory_pool_stat (memory_pool_stat_t *st)
st->chunks_freed = chunks_freed;
}
+#define FIXED_POOL_SIZE 4095
+size_t
+memory_pool_get_size ()
+{
+#ifdef HAVE_GETPAGESIZE
+ return getpagesize () - 1;
+#else
+ return FIXED_POOL_SIZE;
+#endif
+}
+
/*
* vi:ts=4
*/
diff --git a/mem_pool.h b/mem_pool.h
index 70678e9fc..4027b5de2 100644
--- a/mem_pool.h
+++ b/mem_pool.h
@@ -53,6 +53,9 @@ void memory_pool_delete (memory_pool_t* pool);
void memory_pool_stat (memory_pool_stat_t *st);
+/* Get optimal pool size based on page size for this system */
+size_t memory_pool_get_size ();
+
#define memory_pool_free(x) ((x)->len - ((x)->pos - (x)->begin))
#endif
diff --git a/worker.c b/worker.c
index 741a351a1..268e8123b 100644
--- a/worker.c
+++ b/worker.c
@@ -190,6 +190,8 @@ process_message (struct worker_task *task)
msg_info ("process_message: found %d parts in message", task->parts_count);
+ task->worker->srv->stat->messages_scanned ++;
+
return process_filters (task);
}
@@ -313,13 +315,10 @@ accept_socket (int fd, short what, void *arg)
new_task->cfg = worker->srv->cfg;
TAILQ_INIT (&new_task->urls);
TAILQ_INIT (&new_task->parts);
-#ifdef HAVE_GETPAGESIZE
- new_task->task_pool = memory_pool_new (getpagesize () - 1);
-#else
- new_task->task_pool = memory_pool_new (TASK_POOL_SIZE);
-#endif
+ new_task->task_pool = memory_pool_new (memory_pool_get_size ());
/* Add destructor for recipients list (it would be better to use anonymous function here */
memory_pool_add_destructor (new_task->task_pool, (pool_destruct_func)rcpt_destruct, new_task);
+ worker->srv->stat->connections_count ++;
/* Read event */
new_task->bev = bufferevent_new (nfd, read_socket, write_socket, err_socket, (void *)new_task);