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?

In reply to How can I optimize my script? by danielbenny

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.