Skip to content

Commit

Permalink
journald: add minimal client metadata caching
Browse files Browse the repository at this point in the history
Cache client metadata, in order to be improve runtime behaviour under
pressure.

This is inspired by @vcaputo's work, specifically:

#2280

That code implements related but different semantics.

For a longer explanation what this change implements please have a look
at the long source comment this patch adds to journald-context.c.

After this commit:

        # time bash -c 'dd bs=$((1024*1024)) count=$((1*1024)) if=/dev/urandom | systemd-cat'
        1024+0 records in
        1024+0 records out
        1073741824 bytes (1.1 GB, 1.0 GiB) copied, 11.2783 s, 95.2 MB/s

        real	0m11.283s
        user	0m0.007s
        sys	0m6.216s

Before this commit:

        # time bash -c 'dd bs=$((1024*1024)) count=$((1*1024)) if=/dev/urandom | systemd-cat'
        1024+0 records in
        1024+0 records out
        1073741824 bytes (1.1 GB, 1.0 GiB) copied, 52.0788 s, 20.6 MB/s

        real	0m52.099s
        user	0m0.014s
        sys	0m7.170s

As side effect, this corrects the journal's rate limiter feature: we now
always use the unit name as key for the ratelimiter.
  • Loading branch information
poettering committed Jul 18, 2017
1 parent 6cd5a92 commit 91d4231
Show file tree
Hide file tree
Showing 12 changed files with 898 additions and 370 deletions.
2 changes: 2 additions & 0 deletions Makefile.am
Expand Up @@ -4519,6 +4519,8 @@ libjournal_core_la_SOURCES = \
src/journal/journald-audit.h \
src/journal/journald-rate-limit.c \
src/journal/journald-rate-limit.h \
src/journal/journald-context.c \
src/journal/journald-context.h \
src/journal/journal-internal.h

nodist_libjournal_core_la_SOURCES = \
Expand Down
7 changes: 7 additions & 0 deletions src/basic/string-util.h
Expand Up @@ -200,3 +200,10 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(char *, string_free_erase);
#define _cleanup_string_free_erase_ _cleanup_(string_free_erasep)

bool string_is_safe(const char *p) _pure_;

static inline size_t strlen_ptr(const char *s) {
if (!s)
return 0;

return strlen(s);
}
2 changes: 1 addition & 1 deletion src/journal/journald-audit.c
Expand Up @@ -413,7 +413,7 @@ static void process_audit_string(Server *s, int type, const char *data, size_t s
goto finish;
}

server_dispatch_message(s, iov, n_iov, n_iov_allocated, NULL, NULL, NULL, 0, NULL, LOG_NOTICE, 0);
server_dispatch_message(s, iov, n_iov, n_iov_allocated, NULL, NULL, LOG_NOTICE, 0);

finish:
/* free() all entries that map_all_fields() added. All others
Expand Down

0 comments on commit 91d4231

Please sign in to comment.