[Redis] Perl Redis Client news
Steffen Mueller
smueller at cpan.org
Tue Nov 19 19:58:45 GMT 2013
On 11/19/2013 04:51 PM, Pavel Shaydo wrote:
> On Mon Nov 18 18:20:29 2013
> melo at simplicidade.org (Pedro Melo) wrote:
>> RedisDB (I *think* its RedisDB…) has a XS interface. We could
>> compare it with our read()-based performance…
>
> It was some time ago, and I have no time right now to repeat
> benchmarks, but if I remember correctly RedisDB XS parser is about 30%
> faster than RedisDB PP parser.
Interesting!
I did a fairly naive[1] XS implementation of a parser and another fairly
naive Perl implementation using non-consuming regexes (/\G.../gcs). On
the simple response below, here's what I get:
my $reply = join "\r\n", qw(
*3
:123
$-1
$9
hhhhhhhhh
), "";
use Benchmark qw(timethese);
timethese(-2, {
xs => sub {my $x = xs_redis_parse($reply)},
perl => sub {my $x = perl_redis_parse($reply)},
});
Benchmark: running perl, xs for at least 2 CPU seconds...
perl: 2 wallclock secs ( 2.05 usr + 0.00 sys = 2.05 CPU) @
125871.71/s (n=258037)
xs: 2 wallclock secs ( 2.10 usr + 0.00 sys = 2.10 CPU) @ 2184528.57/s
(n=4587510)
So that's a factor of ~17x. :)
The XS implementation is here:
https://github.com/tsee/smuellers_randomstuff/blob/master/redis-protocol-parser/XSFun.xs
The test and Perl implementation is here:
https://github.com/tsee/smuellers_randomstuff/blob/master/redis-protocol-parser/t/redis.t
(Yes, it's a mess, but I checked it in to my "random stuff" repository
for a reason.)
Now mind you, this is just for turning that response into a Perl array
reference (or a string (status+error) or undef ("*-1")). It doesn't
actually PROCESS what needs doing and it doesn't include reading from a
stream. The latter would likely make a significant difference.
Best regards,
Steffen
[1] Naive here means that it's not fully validating. The C
implementation should be safe to the point of "won't segfault" and
"won't eat all your RAM", but it only traps a small number of error
conditions as exceptions and otherwise relies on GIGO.
More information about the Redis
mailing list