[syslog-ng] [PATCH] basicfuncs: Implement a few numeric template functions.

Gergely Nagy algernon at balabit.hu
Tue May 3 23:11:37 CEST 2011


Balazs Scheidler <bazsi at balabit.hu> writes:

> Hi Gergely,
>
> Thanks for the patch, I see an immediate use-case for this.
>
> I applied the patch to the 3.4 tree, and at the same time, I've changed
> it slightly.
>
> On Tue, 2011-05-03 at 22:19 +0200, Gergely Nagy wrote:
>> Implement addition, substraction, multiplication, division and modulus
>> template functions: $(+ N M), $(- N M), $(* N M), $(/ N M) and $(% N
>> M), respectively.
>> 
>> All of them take two numeric arguments, and log an error,
>
> instead of logging an error, always, insert a "NaN" into the output
> stream, which stands for Not-a-Number, commonly used to represent
> non-numbers in underflows. I know it's not that intuitive, but in
> production environments, generating loads of error messages such as
> these in the fast path (even more, since you can several invocation of
> these functions per message), would do no good.

Sounds reasonable, and this makes it easier to detect errors too. Thanks
for the explanation & idea, I'll use a similar approach in future
template functions =)

> Also, while I was at it, I've changed all g_string_append_printf() calls
> to format_int32_padded(), which is much faster.
>
> g_string_append_printf() is double slow, because:
>
>   1) it uses printf, but to measure the length of the string, it runs
> printf without storing its results, and then
>   2) allocates a buffer to format this result, and then
>   3) moves the temp buffer to the end of the gstring
>   4) frees the buffer.
>
> So it is not even double, but quadraple slow. :)

Yikes.

> This is the commit message, please let me know if you disagree with my
> changes.

I completely agree with your changes.

Thanks!

-- 
|8]



More information about the syslog-ng mailing list