root / plugins / redis / redis-speed @ 9894864b
Historique | Voir | Annoter | Télécharger (1,89 ko)
| 1 | b01c3d6e | KARASZI Istvan | #!/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 | 9894864b | minitux | my $PASSWORD = exists $ENV{'password'} ? $ENV{'password'} : undef ;
|
| 29 | b01c3d6e | KARASZI Istvan | |
| 30 | my $server = "$HOST:$PORT"; |
||
| 31 | 9894864b | minitux | my $r = Redis->new( server => $server, password => $PASSWORD ); |
| 32 | b01c3d6e | KARASZI Istvan | |
| 33 | my $config = ( defined $ARGV[0] and $ARGV[0] eq "config" ); |
||
| 34 | |||
| 35 | sub get_time {
|
||
| 36 | my ($times, $func) = @_; |
||
| 37 | my $start = [ gettimeofday ]; |
||
| 38 | |||
| 39 | for (my $i = 0; $i < $times; $i++) {
|
||
| 40 | $func->(); |
||
| 41 | } |
||
| 42 | |||
| 43 | return sprintf("%f", tv_interval($start) / $times);
|
||
| 44 | } |
||
| 45 | |||
| 46 | |||
| 47 | if ( $config ) {
|
||
| 48 | print "graph_title Response time\n"; |
||
| 49 | print "graph_vlabel Response time\n"; |
||
| 50 | print "ping.label PING time\n"; |
||
| 51 | print "get.label GET time\n"; |
||
| 52 | print "set.label SET time\n"; |
||
| 53 | print "graph_category redis\n"; |
||
| 54 | exit 0; |
||
| 55 | } |
||
| 56 | |||
| 57 | my $key = "test-key"; |
||
| 58 | ae65a7d2 | MaxDudu | my $times = 20; |
| 59 | b01c3d6e | KARASZI Istvan | |
| 60 | print "ping.value " . &get_time( $times, sub { $r->ping(); }) . "\n";
|
||
| 61 | ae65a7d2 | MaxDudu | print "set.value " . &get_time( $times, sub { $r->set($key => 'SET ' . $key . ' 1'); }) . "\n";
|
| 62 | b01c3d6e | KARASZI Istvan | print "get.value " . &get_time( $times, sub { $r->get($key); }) . "\n";
|
| 63 | |||
| 64 | # vim: ft=perl ai ts=4 sw=4 et: |
