473,387 Members | 3,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

sharing complex data structures between threads in mod_perl2

Hi, All!

I have two questions: strategic and technical.
Technical one first:
I need to share an array of objects (implemented as hashes, having
references to other objects and hashes, sharing done after blessing)
between all of the mod_perl2 threads. The structure can grow quite big
- tenths of thousands of array elements. It can grow as system
operates (not possible to construct at apache startup). Sharing array
is OK, but inserting mixed structures of hash refs (sometimes blessed)
afterward into it is problematic.
I've written a small routine that attempts to do a deep copy of
arbitrary data structure in order to accomplish the objective. The
problem is that threads::shared::share (or routine logic) seems to
replace original references. Hence circular reference handling code
does not help. Anyway routine does not work for more elaborated
structures.
Maybe there are some better approaches to the task, which I'm missing
out. Code of the routine is underneath.

Strategic one: I'm dealing with ex-CGI application, that has to run
under mod_perl 2. The main bottleneck is authorization system, which
is highly configurable and allows to define permissions up to a single
attribute of a particular row. It works nice under mod_perl 1. Changes
to object structure are automatically reflected in authorization in
both database and application server memory. The part in "application
server memory" speeds up the whole thing greatly. Now under 2nd
mod_perl every thread maintains its own idea of current state of
authorization information, which is sometimes way out of date.
I see currently several options of addressing the issue:
1. Insert everywhere quite expensive database checks and bring
authorization info of every thread up-to-date as needed - more
development and some performance trade-offs
2. Flush authorization info stored in every thread after some changes
to reflected object structure - little development, but significant
performance tradeoff :-)
3. Share the whole thing between all of the threads - great memory and
performance gains, seemingly simple development, lack of stable
platform
Although giving the best benefits the third option has already turned
out to be a two day long nightmare.
I would greatly appreciate any opinions, ideas or comments on the two
questions above.

Thanks for reading it this far,
Dennis

sub share_struct {
my $struct = shift;
my $level = shift;
my $map = shift || {};
return unless ($] > 5.006001);
require threads;
require threads::shared;
import threads;
import threads::shared;
my $type = ref $struct;
if (exists $map->{$struct}) {
return $struct;
} elsif ($type) {
$map->{$struct} = $struct; }
die "Structure complexity exceeds maximum supported level" if
($level>5000);
if ($type) {
if ($type eq 'ARRAY') {
my @arr_copy = @{$struct};
for (my $i=0; $i<=$#arr_copy; $i++) {
$arr_copy[$i] = ${&share_struct(\$arr_copy[$i], $level++,
$map)}; }
share($struct);
@{$struct} = @arr_copy;
} elsif ($type eq 'REF' or $type eq 'SCALAR') {
if (ref $struct) {
&share_struct($$struct, $level++, $map); share($struct);
}
} else { my %hash_copy = %{$struct};
foreach my $key (keys %hash_copy) {
$hash_copy{$key} = ${&share_struct(\$hash_copy{$key}, $level++,
$map)};
}
share($struct);
%{$struct} = %hash_copy;
}
}
return $struct;
}
Jul 19 '05 #1
1 4084
I've decided that sharing the entire structure is too much of a
project for now and came up with a compromise solution. I need to have
a flag variable shared between all of the mod_perl2 threads. Even this
does not seem to work. I declare couple of shared variables and set
their value to current time when flag has to be raised. Every other
thread should check its local variable with last update time and
update the structure if time in global variable is greater than one in
local, setting local variable to update start time.
Although code gives no error, supposedly shared varibales appear to
have different values in every thread.
I do it like this:

use threads;
use threads::shared;
my $tree_flush_t_global : shared;

sub mark_tree_dirty {
$tree_flush_t_global = time;
$tree_flush_t_local = $tree_flush_t_global;
}

sub self {
....
if ($tree_flush_t_global > $tree_flush_t_local) {
....
}

I just can't get what I am doing wrong. Logic is so straightforward
and has been verified so many times that I can not imagine having
programing or design error.
I'd really appreciate any comment or idea, except for switching to
Java, for example, that already has well established threads support.
Those I've heard already :-)
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ivan | last post by:
Hi All, I have a problem with marshaling complex structures (containing numbers, strings, arrays of another structures) to native C function in dll. I have already posted same question to...
4
by: Tony Liu | last post by:
Hi, how can I create multiple new file handles of a file without having to share to file to the other processes? I have a file that will be accessed by multiple threads in my application, each...
0
by: Ivan | last post by:
Hi All, I have a problem with marshaling complex structures (containing numbers, strings, arrays of another structures) to native C function in dll. I have already posted same question to...
6
by: Moshe Kravchik | last post by:
Hi all! I have 2 web services, one writtenin C++ (ATL) and another one in C#. Is there a way to define data stuctures in a single place both services could use? The structures are the same, but if...
0
by: Daniel P. | last post by:
http://danutp.blogspot.com/ Web Services - sharing data between client and server Dealing a lot with web services a friend of mine (Ehsan Samani) and I ran into another issue: when we move...
19
by: Zytan | last post by:
I want multiple instances of the same .exe to run and share the same data. I know they all can access the same file at the same time, no problem, but I'd like to have this data in RAM, which they...
4
by: cleanrabbit | last post by:
Hello! I hate having to do this, because im almost certain there is someone in the world that has come across this problem and i just havent found their solution yet, so i do appologise if this...
9
by: Peri | last post by:
Dear All, Is there a way in which 2 application can share a common memory location to access static data? Say for example I have a product master data that is available in a single place, and...
2
by: Andreas Lundgren | last post by:
Hi! I want to put some values in static memory, and then be able to reference this data from my code in a decent way by referencing AllData.Data. (All code beneth is placed outside functions.) ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.