Commit 67df78d4 authored by Xavier Guimard's avatar Xavier Guimard

Session backend perf tool

parent 2580a21f
......@@ -18,7 +18,7 @@ use lib 'lemonldap-ng-portal/blib/lib';
use lib 'lemonldap-ng-manager/blib/lib';
require './lemonldap-ng-portal/t/test-lib.pm';
use constant COUNT => 10000;
use constant COUNT => 1000;
my $portal = LLNG::Manager::Test->new(
{
......@@ -34,7 +34,6 @@ my $portal = LLNG::Manager::Test->new(
)->p;
my @chars = ( "A" .. "Z", "a" .. "z" );
my $t = time;;
foreach my $i ( 1 .. COUNT() ) {
my $string;
......@@ -105,12 +104,4 @@ foreach my $i ( 1 .. COUNT() ) {
$portal->setMacros($req);
$portal->store($req);
}
print 'LOAD TIME: '.(time - $t)."\n";
done_testing( count() );
#use LWP::UserAgent;
#my $ua = LWP::UserAgent->new;
#$ua->get('http://manager.example.com:19876/sessions.html');
#$t = time;
#$ua->get('http://manager.example.com:19876/manager.fcgi/sessions/global?groupBy=substr(_whatToTrace,1)');
#print 'READ TIME: '.(time - $t)."\n";
#!/usr/bin/perl
use strict;
use DBI;
use JSON qw(from_json to_json);
use Time::HiRes;
use LWP::UserAgent;
use Redis;
system 'make stop_web_server';
Redis->new->flushall;
my $tests = {
Redis => {
globalStorage => 'Apache::Session::Browseable::Redis',
globalStorageOptions => {},
},
BRedis => {
globalStorage => 'Apache::Session::Browseable::Redis',
globalStorageOptions => {
Index => '_whatToTrace _session_kind'
},
},
Postgres => {
globalStorage => 'Apache::Session::Browseable::Postgres',
globalStorageOptions => {
DataSource => 'dbi:Pg:host=127.0.0.1;database=sessions',
UserName => 'sso',
Password => 'sso',
Commit => 1,
},
pg => [
'DROP TABLE IF EXISTS sessions',
'DROP INDEX IF EXISTS uid1',
'DROP INDEX IF EXISTS _s1',
'CREATE TABLE sessions (id varchar(64) not null primary key, a_session text)',
],
},
UPostgres => {
globalStorage => 'Apache::Session::Browseable::Postgres',
globalStorageOptions => {
DataSource => 'dbi:Pg:host=127.0.0.1;database=sessions',
UserName => 'sso',
Password => 'sso',
Commit => 1,
},
pg => [
'DROP TABLE IF EXISTS sessions',
'DROP INDEX IF EXISTS uid1',
'DROP INDEX IF EXISTS _s1',
'CREATE UNLOGGED TABLE sessions (id varchar(64) not null primary key, a_session text)',
],
},
BPostgres => {
globalStorage => 'Apache::Session::Browseable::Postgres',
globalStorageOptions => {
DataSource => 'dbi:Pg:host=127.0.0.1;database=sessions',
UserName => 'sso',
Password => 'sso',
Commit => 1,
Index => '_whatToTrace _session_kind'
},
pg => [
'DROP TABLE IF EXISTS sessions',
'DROP INDEX IF EXISTS uid1',
'DROP INDEX IF EXISTS _s1',
'CREATE UNLOGGED TABLE sessions (id varchar(64) not null primary key, a_session text, _whatToTrace text, _session_kind text)',
'CREATE INDEX uid1 ON sessions (_whatToTrace)',
'CREATE INDEX _s1 ON sessions (_session_kind)',
],
},
PgJSON => {
globalStorage => 'Apache::Session::Browseable::PgJSON',
globalStorageOptions => {
DataSource => 'dbi:Pg:host=127.0.0.1;database=sessions',
UserName => 'sso',
Password => 'sso',
Commit => 1,
},
pg => [
'DROP TABLE IF EXISTS sessions',
'DROP INDEX IF EXISTS uid1',
'DROP INDEX IF EXISTS _s1',
'CREATE UNLOGGED TABLE sessions (id varchar(64) not null primary key, a_session json)',
],
},
};
my $times = {};
foreach my $name ( keys %$tests ) {
my $opts = $tests->{$name}->{globalStorageOptions};
if ( my $cmd = $tests->{$name}->{pg} ) {
my $dbh = DBI->connect( $opts->{DataSource}, $opts->{UserName},
$opts->{Password}, { RaiseError => 1, AutoCommit => 1 } );
foreach (@$cmd) {
print STDERR "$_\n";
$dbh->do($_);
}
$dbh->disconnect;
}
system 'make start_web_server';
print STDERR "Removing manager protection\n";
system
q(perl -i -pe 's/protection\s*=\s*manager/protection=none/' e2e-tests/conf/lemonldap-ng.ini);
print STDERR "Read conf\n";
open F, 'e2e-tests/conf/lmConf-1.json' or die;
my $conf = join '', <F>;
close F;
$conf = from_json($conf);
foreach my $k ( keys %{ $tests->{$name} } ) {
$conf->{$k} = $tests->{$name}->{$k};
}
print STDERR "Write conf\n";
open F, '>e2e-tests/conf/lmConf-1.json' or die;
print F to_json($conf);
close F;
#system 'cat e2e-tests/conf/lmConf-1.json';
sleep(1);
system 'make reload_web_server';
my $t = Time::HiRes::time();
system './e2e-tests/populate.pl';
$times->{$name}->{insert} = Time::HiRes::time() - $t;
my $ua = LWP::UserAgent->new;
$ua->get('http://manager.example.com:19876/sessions.html');
$t = Time::HiRes::time();
my $res = $ua->get(
'http://manager.example.com:19876/manager.fcgi/sessions/global?groupBy=substr(_whatToTrace,1)'
);
$times->{$name}->{read} = Time::HiRes::time() - $t;
$res = from_json($res->content);
my $letter = $res->{values}->[0]->{value};
$t = Time::HiRes::time();
$res = $ua->get(
'http://manager.example.com:19876/manager.fcgi/sessions/global?_whatToTrace='.$letter.'*&groupBy=_whatToTrace'
);
$times->{$name}->{getLetter} = Time::HiRes::time() - $t;
$res = from_json($res->content);
my $user = $res->{values}->[0]->{value};
$t = Time::HiRes::time();
$res = $ua->get(
'http://manager.example.com:19876/manager.fcgi/sessions/global?_whatToTrace='.$user
);
$times->{$name}->{getUid} = Time::HiRes::time() - $t;
$res = from_json($res->content);
my $id = $res->{values}->[0]->{session};
$t = Time::HiRes::time();
$res = $ua->get(
'http://manager.example.com:19876/manager.fcgi/sessions/global/'.$id
);
$times->{$name}->{getSession} = Time::HiRes::time() - $t;
$res = from_json($res->content);
system 'make stop_web_server';
}
use Data::Dumper;
print Dumper($times);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment