"Fossies" - the Fresh Open Source Software Archive

Member "Apache-Session-1.93/b/mysqllock.b" (15 Sep 2009, 1524 Bytes) of package /linux/www/Apache-Session-1.93.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Limbo source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 use Benchmark;
    2 use Apache::Session::Lock::MySQL;
    3 
    4 use vars qw($s $dbh);
    5 
    6 $s = {
    7     args => {
    8         LockDataSource => 'dbi:mysql:database=test;host=desk.eng.vivaldi',
    9         LockUsername   => 'jwb',
   10         LockPassword   => ''
   11     },
   12     data => {
   13         _session_id => ''
   14     }
   15 };
   16 
   17 $dbh = DBI->connect('dbi:mysql:database=test;host=desk.eng.vivaldi', 'jwb', '', {RaiseError => 1});
   18 
   19 sub loop {
   20     $s->{data}->{_session_id} = int(rand(2**20));
   21     my $l = new Apache::Session::Lock::MySQL;
   22     $l->acquire_read_lock($s);
   23     $l->acquire_write_lock($s);
   24 }
   25 
   26 timethis(1000, \&loop, 'Connect 1000 Times');
   27 
   28 $s->{args}->{LockHandle} = $dbh;
   29 
   30 timethis(10000, \&loop, 'Connect Once, Lock 10000 Times');
   31 
   32 `mkfifo sync`;
   33 
   34 for ($n = 10; $n <= 100; $n += 10) {
   35     $dbh->disconnect;
   36 
   37     my $is_child;
   38     for (my $i = 0; $i < $n - 1; $i++) {
   39         my $pid = fork;
   40 
   41         if (!$pid) {
   42             $is_child = 1;
   43             open (SYNC, ">sync") || die $!;
   44             last;
   45         }
   46     }
   47 
   48     if (!$is_child) {
   49         print "Sleeping 2 seconds to sync children\n";
   50         sleep 2;
   51         open(GO, "<sync") || die $!;
   52     }
   53 
   54     $dbh = DBI->connect('dbi:mysql:database=test;hostname=desk.eng.vivaldi', 'jwb', '', {RaiseError => 1});
   55     $s->{args}->{LockHandle} = $dbh;
   56     timethis(-1, \&loop, "$n Children");
   57 
   58     if ($is_child) {
   59         exit();
   60     }
   61 
   62     for (my $i = 0; $i < $n - 1; $i++) {
   63         wait();
   64     }
   65 
   66     close GO;
   67 }
   68 
   69 unlink "sync";