Skip to content

Commit

Permalink
in_syslog: added buffer_rcv_size option to set socket receiving buffer
Browse files Browse the repository at this point in the history
With default value of 208kb some UDP syslogs packet are lost at 10000 logs/s.
Using the option set to a high value a steady stream of 10000 log/s can be
processed without losing any log (on localhost).

Signed-off-by: Benoît GARNIER <[email protected]>
  • Loading branch information
ChezBunch authored and edsiper committed Nov 8, 2022
1 parent 636e083 commit f2c73ca
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions plugins/in_syslog/syslog.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ static struct flb_config_map config_map[] = {
0, FLB_TRUE, offsetof(struct flb_syslog, parser_name),
"Set the parser"
},
{
FLB_CONFIG_MAP_SIZE, "buffer_rcv_size", (char *)NULL,
0, FLB_TRUE, offsetof(struct flb_syslog, buffer_rcv_size),
"Set the socket receiving buffer size"
},
/* EOF */
{0}
};
Expand Down
1 change: 1 addition & 0 deletions plugins/in_syslog/syslog.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ struct flb_syslog {
flb_sds_t unix_path;
flb_sds_t unix_perm_str;
unsigned int unix_perm;
size_t buffer_rcv_size;

/* UDP buffer, data length and buffer size */
// char *buffer_data;
Expand Down
7 changes: 7 additions & 0 deletions plugins/in_syslog/syslog_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ struct flb_syslog *syslog_conf_create(struct flb_input_instance *ins,
ctx->buffer_max_size = ctx->buffer_chunk_size;
}

/* Socket rcv buffer size */
if (ctx->buffer_rcv_size == -1 || ctx->buffer_rcv_size>INT_MAX) {
flb_plg_error(ins, "invalid buffer_rcv_size");
flb_free(ctx);
return NULL;
}

/* Parser */
if (ctx->parser_name) {
ctx->parser = flb_parser_get(ctx->parser_name, config);
Expand Down
8 changes: 8 additions & 0 deletions plugins/in_syslog/syslog_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ static int syslog_server_net_create(struct flb_syslog *ctx)
return -1;
}

if (ctx->buffer_rcv_size) {
if (flb_net_socket_rcv_buffer(ctx->downstream->server_fd, ctx->buffer_rcv_size)) {
flb_error("[in_syslog] could not set rcv buffer to %ld. Aborting",
ctx->buffer_rcv_size);
return -1;
}
}

flb_net_socket_nonblocking(ctx->downstream->server_fd);

return 0;
Expand Down

0 comments on commit f2c73ca

Please sign in to comment.