]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
log: throttle message submission, trim recent
authorSage Weil <sage@newdream.net>
Tue, 27 Mar 2012 18:14:15 +0000 (11:14 -0700)
committerSage Weil <sage@newdream.net>
Tue, 27 Mar 2012 18:20:53 +0000 (11:20 -0700)
Signed-off-by: Sage Weil <sage@newdream.net>
src/log/EntryQueue.h
src/log/Log.cc
src/log/Log.h

index b1befae6db0a465072aeacb149e0bfb068cec39e..d125540c43b52ac1a68c6f764f67c54391c78484 100644 (file)
@@ -10,7 +10,7 @@ namespace ceph {
 namespace log {
 
 struct EntryQueue {
-  int m_len, m_max_len;
+  int m_len;
   struct Entry *m_head, *m_tail;
 
   bool empty() const {
@@ -50,9 +50,10 @@ struct EntryQueue {
     return e;
   }
 
-  EntryQueue(int max=0)
-    : m_len(0), m_max_len(max),
-      m_head(NULL), m_tail(NULL)
+  EntryQueue()
+    : m_len(0),
+      m_head(NULL),
+      m_tail(NULL)
   {}
   ~EntryQueue() {
     Entry *t;
index b668b583de570113f3cfbc00a6e6a049d13a1215..38c875239b2d3ef40d9ad06703897b4bb8762a9f 100644 (file)
@@ -14,7 +14,7 @@
 #include "common/Clock.h"
 #include "include/assert.h"
 
-#define DEFAULT_MAX_NEW     1000
+#define DEFAULT_MAX_NEW    100
 #define DEFAULT_MAX_RECENT 10000
 
 #define PREALLOC 1000000
@@ -32,11 +32,13 @@ static void log_on_exit(int r, void *p)
 Log::Log(SubsystemMap *s)
   : m_indirect_this(new (Log*)(this)),   // we will deliberately leak this
     m_subs(s),
-    m_new(DEFAULT_MAX_NEW), m_recent(DEFAULT_MAX_RECENT),
+    m_new(), m_recent(),
     m_fd(-1),
     m_syslog_log(-2), m_syslog_crash(-2),
     m_stderr_log(1), m_stderr_crash(-1),
-    m_stop(false)
+    m_stop(false),
+    m_max_new(DEFAULT_MAX_NEW),
+    m_max_recent(DEFAULT_MAX_RECENT)
 {
   int ret;
 
@@ -81,6 +83,16 @@ Log::~Log()
 
 ///
 
+void Log::set_max_new(int n)
+{
+  m_max_new = n;
+}
+
+void Log::set_max_recent(int n)
+{
+  m_max_recent = n;
+}
+
 void Log::set_log_file(string fn)
 {
   m_log_file = fn;
@@ -116,8 +128,13 @@ void Log::set_stderr_level(int log, int crash)
 void Log::submit_entry(Entry *e)
 {
   pthread_mutex_lock(&m_queue_mutex);
-  m_new.enqueue(e);
   pthread_cond_signal(&m_cond);
+
+  // wait for flush to catch up
+  while (m_new.m_len > m_max_new)
+    pthread_cond_wait(&m_cond, &m_queue_mutex);
+
+  m_new.enqueue(e);
   pthread_mutex_unlock(&m_queue_mutex);
 }
 
@@ -144,8 +161,15 @@ void Log::flush()
   pthread_mutex_lock(&m_queue_mutex);
   EntryQueue t;
   t.swap(m_new);
+  pthread_cond_signal(&m_cond);
   pthread_mutex_unlock(&m_queue_mutex);
   _flush(&t, &m_recent, false);
+
+  // trim
+  while (m_recent.m_len > m_max_recent) {
+    delete m_recent.dequeue();
+  }
+
   pthread_mutex_unlock(&m_flush_mutex);
 }
 
@@ -214,13 +238,12 @@ void Log::dump_recent()
   pthread_mutex_unlock(&m_flush_mutex);
 
   pthread_mutex_lock(&m_queue_mutex);
-  EntryQueue t(1);
+  EntryQueue t;
   t.swap(m_new);
   pthread_mutex_unlock(&m_queue_mutex);
   _flush(&t, &m_recent, false);
 
-  EntryQueue old(0);
-
+  EntryQueue old;
   _log_message("--- begin dump of recent events ---", true);
   _flush(&m_recent, &old, true);  
   _log_message("--- end dump of recent events ---", true);
index c0c3a7e1f857d69ab18a7a4df0782cd16eb2cd87..372cc789ba41d11c43096c6af69dd1ba6cf9bfc4 100644 (file)
@@ -37,6 +37,8 @@ class Log : private Thread
 
   bool m_stop;
 
+  int m_max_new, m_max_recent;
+
   void *entry();
 
   void _flush(EntryQueue *q, EntryQueue *requeue, bool crash);