Closed jtarchie closed 6 years ago
Hi @jtarchie congrats for your library. :)
Would be interesting to look at the results of this library on your machine. Also would be very interesting to adapt the test cases of this package and run them on your library.
Notice that priority values have to be within [1,191]
or be 0
(ie., 002
is not a valid priority value) to be valid, since from them are computed the facility and the severity values as the RFC mandates.
Clearly there are a bunch of features of this library, namely:
"
, ]
, \
within sd param valuestime.Parse
to parse timestamps that all slightly slow down a bit this library.
These were chosen due to the trade-off between speed, correctness (RFC5424-compliance) and library features.
I'll take a crack at the test cases here, too.
I don't know how I feel about the best effort though. I feel that can be anti-functionality. What do you you use it for?
Ideas you give me (and I thank you!) are:
[x] Try to match any
and validate UTF-8 during the set of message part (idem for the sd param value)
Done. It fasten by 10-16% the match of inputs not containing UTF-8. At the same time it slows down the match of long syslog or syslog containing UTF-8 sequences from 20% to 60% (since we need to use
utf8.Valid
to check the validity of string and in the besteffort mode we need to iterate on the string to extract the valid UTF-8 part) ... Leaving as is for now.
[x] Try to match any
and validate UTF-8 during the set of sd param value part
As above.
[x] Try to match prival in the simple way and then check it is in the range [1,191] or 0 during the set
Done. It slows down the average case of 12% (increasing performance by 3-5% in early error cases)
The best effort thing is useful when you want to extract (and store) a syslog message also if it was not completely compliant to the rules.
Since from a lot of years a lot of software do syslog messages in a "free" way it is very common that some syslog messages are only partially compliant to that RFC5424.
With the best effort mode we can save it if it is minimally valid - ie., until the point that breaks the rules it is correct and contains almost a valid priority value and a valid version (which are the only two fields that cannot have nil values by RFC).
I do have a best effort then as I allow any prival range. 😄
Best effort does not allow any priority values, only valid ones :stuck_out_tongue_closed_eyes:
I tried out your benchmarks with my library.
Some notes:
string
conversion from the[]byte
.