[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mason
Subject:    [Mason] Mason and SDBM-tied hashes
From:       Brian Reichert <reichert () numachi ! com>
Date:       2007-07-28 0:07:38
Message-ID: 20070728000738.GK42736 () numachi ! com
[Download RAW message or body]

Howdy; I have a weird symptom to report.  Dunno if it's pilot error,
or something odd with my tools.

Hopefully someone out there can offer some advice to clear up what
I'm seeing.  If there's any more data I can provide, I'd be happy
to provide it.

The background: I often use SDBM-tied hashes to share cheap slow
data across concurrent apps.  Not much luck under Mason.

I've cobbled together a Mason handler.pl that maintains such a tied
hash as a global variable.

I've written a component that lets me get/set a value in this tied
hash.

The symptom I see that after a 'set', subsequent 'gets' show me
various results; sometimes the data comes back set, sometimes not.

I wrote a loop with curl to re-hit my component, with a one-second
sleep; the component logs what it sees.

Then, I get my component in from another window, to cause the set.

Here, HASH(foo) is my tied hash reference, followed by the PID of
the apache process handling the request, and a bit representing
whether or not my data is seen as set in the tied hash.  Two complete
loops over all of my http pids:

  mod_info is HASH(0x9e0f0e4) 8846 0 at /var/www/html/error_test line 35.
  mod_info is HASH(0x9e0f0e4) 8839 0 at /var/www/html/error_test line 35.
  mod_info is HASH(0x9e0f0e4) 8840 0 at /var/www/html/error_test line 35.
  mod_info is HASH(0x9e0f0e4) 8841 0 at /var/www/html/error_test line 35.
  mod_info is HASH(0x9e0f0e4) 8844 0 at /var/www/html/error_test line 35.
  mod_info is HASH(0x9e0f0e4) 8845 0 at /var/www/html/error_test line 35.
  mod_info is HASH(0x9e0f0e4) 8838 1 at /var/www/html/error_test line 35.
  mod_info is HASH(0x9e0f0e4) 8847 0 at /var/www/html/error_test line 35.
  mod_info is HASH(0x9e0f0e4) 8846 0 at /var/www/html/error_test line 35.
  mod_info is HASH(0x9e0f0e4) 8839 0 at /var/www/html/error_test line 35.
  mod_info is HASH(0x9e0f0e4) 8840 0 at /var/www/html/error_test line 35.
  mod_info is HASH(0x9e0f0e4) 8841 0 at /var/www/html/error_test line 35.
  mod_info is HASH(0x9e0f0e4) 8844 0 at /var/www/html/error_test line 35.
  mod_info is HASH(0x9e0f0e4) 8845 0 at /var/www/html/error_test line 35.
  mod_info is HASH(0x9e0f0e4) 8838 1 at /var/www/html/error_test line 35.
  mod_info is HASH(0x9e0f0e4) 8847 0 at /var/www/html/error_test line 35.

You can see that the hash ID never alters; seemingly, it's always
the same hash.  The logs make it seem that only one of my httpd
PIDs made the change.

If I perform these same experiments with command-line tools, the
multiple processes show the data being written to the disk within
a second or so, and all of the processes showing that tied hash
reflect the change quickly.

At the end of this message is a simple tool to demonstrate what I
expect, save as 'dbreader'.  Just takes key/value pairs on the
command line, writes to the tied hash, then loops, displaying the
contents of the hash.

In one window, 
  
  ./dbreader apples cherries grapes bananas

And in another,
 
  ./dbreader apples pineapples grapes peaches

I can have as many of these as I want running at the same time, and
it Just Works.  Somehow, running this under apache/mason/mod_perl
violates my expectations.

The tools on my system:

>From RedHat:

  # uname -r
  2.6.9-42.0.10.EL

  # perl -v

  This is perl, v5.8.5 built for i386-linux-thread-multi

  (From Red Hat's perl-5.8.5-36.RHEL4)

From: http://www.openfusion.com.au/mrepo/centos4-i386/

  libapreq2-2.08-1.el4.i686.rpm
  mod_perl-2.0.3-1.of.el4.i686.rpm
  perl-libapreq2-2.08-1.el4.i686.rpm

>From Dries:

  perl-HTML-Mason-1.3101-1.2.el4.rf.noarch.rpm
  (plus depandancies)

#--------------
#!/usr/bin/perl -w

use strict;
use POSIX;
use SDBM_File;

my $dbclass = 'SDBM_File';
my $loc = 'testing';
my %info=();
my $hashref = { @ARGV };
tie (%info, $dbclass, $loc, O_RDWR|O_CREAT, 0640) ||
  die "$0: can't tie $loc: $!";
%info = %{$hashref};
while(1)
{
  print "----\n";
  foreach (sort keys %info) { print "$_: $info{$_}\n"; }
  sleep 1;
}

#--------------


-- 
Brian Reichert				<reichert@numachi.com>
55 Crystal Ave. #286			Daytime number: (603) 434-6842
Derry NH 03038-1725 USA			BSD admin/developer at large	

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Mason-users mailing list
Mason-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mason-users
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic