chiark / gitweb /
journald: increase rate limit burst rate
[elogind.git] / src / journal / journald.c
index 9f753013a09755e2e2a479a94daa1a76e2f71896..e7231d96f78c4dfb6404a7e011179b7b243b2bc1 100644 (file)
 #define USER_JOURNALS_MAX 1024
 #define STDOUT_STREAMS_MAX 4096
 
+#define DEFAULT_RATE_LIMIT_INTERVAL (10*USEC_PER_SEC)
+#define DEFAULT_RATE_LIMIT_BURST 200
+
+#define RECHECK_AVAILABLE_SPACE_USEC (30*USEC_PER_SEC)
+
 typedef struct StdoutStream StdoutStream;
 
 typedef struct Server {
@@ -68,6 +73,9 @@ typedef struct Server {
         uint64_t max_use;
         bool compress;
 
+        uint64_t cached_available_space;
+        usec_t cached_available_space_timestamp;
+
         LIST_HEAD(StdoutStream, stdout_streams);
         unsigned n_stdout_streams;
 } Server;
@@ -108,6 +116,10 @@ static uint64_t available_space(Server *s) {
         uint64_t sum = 0, avail = 0, ss_avail = 0;
         int r;
         DIR *d;
+        usec_t ts = now(CLOCK_MONOTONIC);
+
+        if (s->cached_available_space_timestamp + RECHECK_AVAILABLE_SPACE_USEC > ts)
+                return s->cached_available_space;
 
         r = sd_id128_get_machine(&machine);
         if (r < 0)
@@ -163,6 +175,9 @@ static uint64_t available_space(Server *s) {
         if (ss_avail < avail)
                 avail = ss_avail;
 
+        s->cached_available_space = avail;
+        s->cached_available_space_timestamp = ts;
+
 finish:
         closedir(d);
 
@@ -326,6 +341,8 @@ static void server_vacuum(Server *s) {
         if (r < 0 && r != -ENOENT)
                 log_error("Failed to vacuum %s: %s", p, strerror(-r));
         free(p);
+
+        s->cached_available_space_timestamp = 0;
 }
 
 static char *shortened_cgroup_path(pid_t pid) {
@@ -1560,7 +1577,7 @@ static int server_init(Server *s) {
         if (r < 0)
                 return r;
 
-        s->rate_limit = journal_rate_limit_new(10*USEC_PER_SEC, 2);
+        s->rate_limit = journal_rate_limit_new(DEFAULT_RATE_LIMIT_INTERVAL, DEFAULT_RATE_LIMIT_BURST);
         if (!s->rate_limit)
                 return -ENOMEM;