You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Mark Puttnam <ma...@freightlist.com> on 2003/05/15 17:01:29 UTC

move from CGI to Apache::Registry using Frank D. Cringle fixes

Hi,

I have a couple of questions that if answered would give me the comfort
level that I need to move code from dev to prod. I have been through the
mailing list and have incorporated some of the changes and
recommendations to patch the code to move it to mod_perl environment.
But before I ask the question, here is the background.

1)
http://mathforum.org/epigone/modperl/zharphoigeld/modperl36@forum.swarth
more.edu

The fix that was suggested by the above posting and I quote ......
"You should pass variables into the subroutines as parameters, either
singly or preferably wrapped up in an object, or at least a hash." 
I did that on all the cgi code not the 'use'd or require'd' code.

2)
http://mathforum.org/epigone/modperl/pleeshendkoi/modperl1710@forum.swar
thmore.edu 

>From the above posting I used the statement I quote .....
"No complaints were visible in error.log or on STDERR of the sever
either, despite $^W=1 and 'use strict' and all that good stuff."
, and placed $^W=1 and use'd strict in all cgi code. 

3) http://www.apacheweek.com/features/mod_perl12

>From the above article, I pre-loaded all of my use'd, require'd and cgi
code. Using the startup.pl. 

Now that I have explained my set up. Here are the questions.

Q.1) Before I did the placed the fix suggested in link 1, I got a whole
bunch of "Variable $e will not stay shared at /path/to/cgi line 200"
warnings. After the fix I no longer have these. Does this mean that I
have taken care of the global variable issues? 

Q.2) After I did what was told in link 2, what is "all the that good
stuff" I am looking for in the server error logs or on STDERR to find
out if harmful global variables are still present in the code?

Q.3) I have loaded everything in the startup. Does this mean, the child
processes are going to smaller in size? 

Q.4) I am currently trying to run the webserver in httpd -X mode. How
many concurrent users do I need to be hitting to server to catch the
harmful global variable problems?

Q.5) I wish there were some kind of testing plan, that the developers of
mod_perl could post on the perl.apache.com site so that people who are
trying to port their apps could follow? This would help a great deal in
helping company's trying to move towards mod_perl.


RE: move from CGI to Apache::Registry using Frank D. Cringle fixes

Posted by Perrin Harkins <pe...@elem.com>.
On Thu, 2003-05-15 at 15:10, Mark Puttnam wrote:
> >>Good, that catches most mod_perl problems.
> 
> When you say the mod_perl errors, you mean the "Variable $somevariable
> will not stay shared at /path/to/cgi line 200", errors. Or are there
> anything that we need look out for, to catch the closure issues.

I'm talking about those errors, and global variables, and general Perl
problems like accidental globals due to typos.  These are all caught by
warnings and strict.

> >>Yes, although these were closure issues, not globals.  You had lexical
> >>variables that were going to keep persistent values until you fixed
> >>that.
> 
> Wouldn't the lexical variables holding persistent values be the root
> cause for one user viewing another user's data?

Yes, that and global variables.

> We have done rigorous
> test, with our testing software to see if this is happening on our
> applications, after the fixes. We have not caught anything yet. Neither
> have we seen any of the messages mentioned in Q.1 in the error log.

Good, that's about as much as you can do.

> The only thing we see now are the following.
>   1. null: Use of uninitialized value at /path/to/lib/custommodule.pm or
> /path/to/cgi  200 etc
>   2. (eval 297): Odd number of elements in hash assignment at (eval 297)
> 
> 
> which I shall look into. Feel free to give suggestions for the above
> warnings.

Both are probably simple coding mistakes unrelated to mod_perl.

> >>In -X mode it will only handle one request at a time, so you don't use
> >>any concurrency with it.  The thing to do is just test your software
> >>normally to see if it behaves as expected.
> The functionality tests until now have had perfect results. The fear is
> the data caching. (A seeing B's data and vice versa)

You can try writing a test that will alternate between users and check
for correct output.  You've already done all of the standard things you
can do, i.e. cleaning up sub params and globals.

- Perrin

RE: move from CGI to Apache::Registry using Frank D. Cringle fixes

Posted by Mark Puttnam <ma...@freightlist.com>.
Thank you so much for your response. It was really helpful.
I have added so more info and plan to respond to Ged questions too.

Mark

On Thu, 2003-05-15 at 11:01, Mark Puttnam wrote:
> 1)
>
http://mathforum.org/epigone/modperl/zharphoigeld/modperl36@forum.swarth
> more.edu
> 
> The fix that was suggested by the above posting and I quote ......
> "You should pass variables into the subroutines as parameters, either
> singly or preferably wrapped up in an object, or at least a hash." 
> I did that on all the cgi code not the 'use'd or require'd' code.

>>You really should do that anyway, no matter where you run your code. 
>>It's a good practice and makes your code easier to read.
Yep, We always do that. But in this case the code was passed down to us,
to
maintain and port to modperl.

> 2)
>
http://mathforum.org/epigone/modperl/pleeshendkoi/modperl1710@forum.swar
> thmore.edu 
> 
> From the above posting I used the statement I quote .....
> "No complaints were visible in error.log or on STDERR of the sever
> either, despite $^W=1 and 'use strict' and all that good stuff."
> , and placed $^W=1 and use'd strict in all cgi code. 

>>Good, that catches most mod_perl problems.

When you say the mod_perl errors, you mean the "Variable $somevariable
will not stay shared at /path/to/cgi line 200", errors. Or are there
anything that we need look out for, to catch the closure issues.  

> 3) http://www.apacheweek.com/features/mod_perl12
> 
> From the above article, I pre-loaded all of my use'd, require'd and
cgi
> code. Using the startup.pl. 

>>Good, that will help reduce memory. 

> Now that I have explained my set up. Here are the questions.
> 
> Q.1) Before I did the placed the fix suggested in link 1, I got a
whole
> bunch of "Variable $somevariable will not stay shared at /path/to/cgi
line 200"
> warnings. After the fix I no longer have these. Does this mean that I
> have taken care of the global variable issues?

>>Yes, although these were closure issues, not globals.  You had lexical
>>variables that were going to keep persistent values until you fixed
>>that.

Wouldn't the lexical variables holding persistent values be the root
cause for one user viewing another user's data? We have done rigorous
test, with our testing software to see if this is happening on our
applications, after the fixes. We have not caught anything yet. Neither
have we seen any of the messages mentioned in Q.1 in the error log. (The
question, is there anything else we might be missing to check?) 


> Q.2) After I did what was told in link 2, what is "all the that good
> stuff" I am looking for in the server error logs or on STDERR to find
> out if harmful global variables are still present in the code?

>>If there are no complaints in the error log with warnings and strict
on,
>>you are in good shape. 
The only thing we see now are the following.
  1. null: Use of uninitialized value at /path/to/lib/custommodule.pm or
/path/to/cgi  200 etc
  2. (eval 297): Odd number of elements in hash assignment at (eval 297)


which I shall look into. Feel free to give suggestions for the above
warnings.

> Q.3) I have loaded everything in the startup. Does this mean, the
child
> processes are going to smaller in size? 

>>Yes.  Make sure you read about how to tell how big your processes are
in
>>the mod_perl documentation:
>>http://perl.apache.org/docs/1.0/guide/performance.html#Sharing_Memory
Thanks. I shall do that.

> Q.4) I am currently trying to run the webserver in httpd -X mode. How
> many concurrent users do I need to be hitting to server to catch the
> harmful global variable problems?

>>In -X mode it will only handle one request at a time, so you don't use
>>any concurrency with it.  The thing to do is just test your software
>>normally to see if it behaves as expected.
The functionality tests until now have had perfect results. The fear is
the data caching. (A seeing B's data and vice versa)

> Q.5) I wish there were some kind of testing plan, that the developers
of
> mod_perl could post on the perl.apache.com site so that people who are
> trying to port their apps could follow? This would help a great deal
in
> helping company's trying to move towards mod_perl.

>>Well, there's no general test that can tell whether or not your
software
>>behaves as you intended it to.  You've already done all the general
>>things.
That's good to know.

- Perrin


Re: move from CGI to Apache::Registry using Frank D. Cringle fixes

Posted by Perrin Harkins <pe...@elem.com>.
On Thu, 2003-05-15 at 11:01, Mark Puttnam wrote:
> 1)
> http://mathforum.org/epigone/modperl/zharphoigeld/modperl36@forum.swarth
> more.edu
> 
> The fix that was suggested by the above posting and I quote ......
> "You should pass variables into the subroutines as parameters, either
> singly or preferably wrapped up in an object, or at least a hash." 
> I did that on all the cgi code not the 'use'd or require'd' code.

You really should do that anyway, no matter where you run your code. 
It's a good practice and makes your code easier to read.

> 2)
> http://mathforum.org/epigone/modperl/pleeshendkoi/modperl1710@forum.swar
> thmore.edu 
> 
> From the above posting I used the statement I quote .....
> "No complaints were visible in error.log or on STDERR of the sever
> either, despite $^W=1 and 'use strict' and all that good stuff."
> , and placed $^W=1 and use'd strict in all cgi code. 

Good, that catches most mod_perl problems.

> 3) http://www.apacheweek.com/features/mod_perl12
> 
> From the above article, I pre-loaded all of my use'd, require'd and cgi
> code. Using the startup.pl. 

Good, that will help reduce memory.

> Now that I have explained my set up. Here are the questions.
> 
> Q.1) Before I did the placed the fix suggested in link 1, I got a whole
> bunch of "Variable $e will not stay shared at /path/to/cgi line 200"
> warnings. After the fix I no longer have these. Does this mean that I
> have taken care of the global variable issues?

Yes, although these were closure issues, not globals.  You had lexical
variables that were going to keep persistent values until you fixed
that.

> Q.2) After I did what was told in link 2, what is "all the that good
> stuff" I am looking for in the server error logs or on STDERR to find
> out if harmful global variables are still present in the code?

If there are no complaints in the error log with warnings and strict on,
you are in good shape.

> Q.3) I have loaded everything in the startup. Does this mean, the child
> processes are going to smaller in size? 

Yes.  Make sure you read about how to tell how big your processes are in
the mod_perl documentation:
http://perl.apache.org/docs/1.0/guide/performance.html#Sharing_Memory

> Q.4) I am currently trying to run the webserver in httpd -X mode. How
> many concurrent users do I need to be hitting to server to catch the
> harmful global variable problems?

In -X mode it will only handle one request at a time, so you don't use
any concurrency with it.  The thing to do is just test your software
normally to see if it behaves as expected.

> Q.5) I wish there were some kind of testing plan, that the developers of
> mod_perl could post on the perl.apache.com site so that people who are
> trying to port their apps could follow? This would help a great deal in
> helping company's trying to move towards mod_perl.

Well, there's no general test that can tell whether or not your software
behaves as you intended it to.  You've already done all the general
things.

- Perrin

Re: move from CGI to Apache::Registry using Frank D. Cringle fixes

Posted by Ged Haywood <ge...@www2.jubileegroup.co.uk>.
Hi there,

On Thu, 15 May 2003, Mark Puttnam wrote:

> I have a couple of questions that if answered would give me the comfort
> level that I need to move code from dev to prod.

I'd want more than a fuzzy warm feeling from the mailing list before I
made that kind of a move... :)

> I have been through the mailing list and have incorporated some of
> the changes and recommendations to patch the code to move it to
> mod_perl environment.

Hmmm.  You seem to have converted a bunch of CGI scripts to run under
Apache::Registry - this is kind of a kludge, you might be better off
using mod_perl handlers.

How much code are you working with?  What does it do?  How much of it,
and how often does it do it?  And so on...?

> 1) "You should pass variables into the subroutines as parameters,
> 
> I did that on all the cgi code not the 'use'd or require'd' code.

Are the modules your own?  If not your own, what are they?

> 2) placed $^W=1 and use'd strict in all cgi code. 

:)

> 3) pre-loaded all of my use'd, require'd and cgi code.

:)

> Now that I have explained my set up.

There could be an issue here... :)

> Q.1) Before I did the placed the fix suggested in link 1, I got a whole
> bunch of "Variable $e will not stay shared at /path/to/cgi line 200"
> warnings. After the fix I no longer have these. Does this mean that I
> have taken care of the global variable issues? 

Well probably some of them.  How are we to know?  Try it.  If all your
variables have names like $e then I think there may be more to look at
than the effects of eval{}.

> Q.2) in link 2, what is "all the that good stuff"

Have you read the mod_perl Guide?

> Q.3) I have loaded everything in the startup. Does this mean, the child
> processes are going to smaller in size? 

It depends.  Smaller than what?  You can easily bloat a process by
careless programming - for example if you make a habit of swallowing
huge arrays, entire files etc. your processes' memory consumption can
quickly get out of hand.

> Q.4) I am currently trying to run the webserver in httpd -X mode. How
> many concurrent users do I need to be hitting to server to catch the
> harmful global variable problems?

If you're using httpd -X as there's only one process serving requests,
so you aren't serving concurrent users.  Of course you wouldn't normally
do that in a production server, you'd only do it for example to try to
find out why you were getting crazy problems that you didn't expect when
you didn't use -X.

> Q.5) I wish there were some kind of testing plan, that the developers of
> mod_perl could post on the perl.apache.com site so that people who are
> trying to port their apps could follow?

That's like saying there should be some kind of testing plan for the
design of your new vehicle - without telling anyone if it has wheels or
wings.  It's quite unrealistic to expect anything of the kind.  You're
the only one who can know what kind of a testing plan is appropriate.
Maybe you don't need one.  Maybe people will die if you get it wrong.
As I hinted earlier, you haven't really told us very much.

It seems to me that you're in the very early stages of getting use to
mod_perl and you're nothing like ready to go into production, whatever
that means.  Perhaps you can try things out gingerly, say one piece at
a time, or on a staging server, or something, to see what breaks and
why.  Make sure you have a fallback plan (that's easy with Apache), so
when things fail you can get back to a working system quickly and fix
them at leisure without getting all frazzled because your telephone
won't stop ringing.

But without knowing a lot more about your situation it's difficult to
comment further.

73,
Ged.