root / plugins / other / redis-speed @ b01c3d6e
Historique | Voir | Annoter | Télécharger (1,81 ko)
| 1 |
#!/usr/bin/perl -w |
|---|---|
| 2 |
|
| 3 |
# |
| 4 |
## Copyright (C) 2010 KARASZI Istvan <http://raszi.hu/> |
| 5 |
## |
| 6 |
## This program is free software; you can redistribute it and/or |
| 7 |
## modify it under the terms of the GNU General Public License |
| 8 |
## as published by the Free Software Foundation; version 2 dated June, |
| 9 |
## 1991. |
| 10 |
## |
| 11 |
## This program is distributed in the hope that it will be useful, |
| 12 |
## but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
## GNU General Public License for more details. |
| 15 |
## |
| 16 |
## You should have received a copy of the GNU General Public License |
| 17 |
## along with this program; if not, write to the Free Software |
| 18 |
## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 19 |
## |
| 20 |
# |
| 21 |
|
| 22 |
use strict; |
| 23 |
use Redis; |
| 24 |
use Time::HiRes qw( gettimeofday tv_interval ); |
| 25 |
|
| 26 |
my $HOST = exists $ENV{'host'} ? $ENV{'host'} : "127.0.0.1";
|
| 27 |
my $PORT = exists $ENV{'port'} ? $ENV{'port'} : 6379;
|
| 28 |
|
| 29 |
my $server = "$HOST:$PORT"; |
| 30 |
my $r = Redis->new( server => sprintf("%s:%d", $HOST, $PORT) );
|
| 31 |
|
| 32 |
my $config = ( defined $ARGV[0] and $ARGV[0] eq "config" ); |
| 33 |
|
| 34 |
sub get_time {
|
| 35 |
my ($times, $func) = @_; |
| 36 |
my $start = [ gettimeofday ]; |
| 37 |
|
| 38 |
for (my $i = 0; $i < $times; $i++) {
|
| 39 |
$func->(); |
| 40 |
} |
| 41 |
|
| 42 |
return sprintf("%f", tv_interval($start) / $times);
|
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
if ( $config ) {
|
| 47 |
print "graph_title Response time\n"; |
| 48 |
print "graph_vlabel Response time\n"; |
| 49 |
print "ping.label PING time\n"; |
| 50 |
print "get.label GET time\n"; |
| 51 |
print "set.label SET time\n"; |
| 52 |
print "graph_category redis\n"; |
| 53 |
exit 0; |
| 54 |
} |
| 55 |
|
| 56 |
my $key = "test-key"; |
| 57 |
my $times = 200; |
| 58 |
|
| 59 |
print "ping.value " . &get_time( $times, sub { $r->ping(); }) . "\n";
|
| 60 |
print "set.value " . &get_time( $times, sub { $r->set($key, 1); }) . "\n";
|
| 61 |
print "get.value " . &get_time( $times, sub { $r->get($key); }) . "\n";
|
| 62 |
|
| 63 |
# vim: ft=perl ai ts=4 sw=4 et: |
