Dear Monks,
as of my bachelor thesis I'm trying to benchmark some logging solutions (e.g. graylog, elastic stack, splunk).
In order to make sure that the logging environment could handle a massive syslog load, I needed to write a script that could simulate enough syslog traffic.
Here is my script (benchmark.pl):
#! /usr/bin/perl
use strict;
use warnings;
use Sys::Syslog qw(:standard :macros setlogsock);
die "Usage: $0 <host> <port> <count>\n" unless @ARGV == 3;
my ($host, $port, $count) = @ARGV;
my ($sender, $program) = ("localhost","loggenerator");
setlogsock({ type => "tcp", host => "$host", port => "$port" });
openlog("$sender $program", 'pid,noeol,ndelay');
syslog('info', "This is my $_ test message!" ) for (1 .. $count);
closelog();
With the following call I'm able to write one million messages to my logging infrastructure --> ./benchmark.pl 127.0.0.1 514 1000000
This takes about 50 seconds (depending on the logging software) which results in a throughput of 20000 messages per second.
Other benchmark tools have a higher throughput and a lower CPU consumption.
How can I optimize my script?