Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Profiling a Perl CGI script that times-out

I have a Perl CGI application that sometimes times out, causing it to be killed by Apache and 504 Gateway Time-out error to be sent to browser. I am trying to profile this application using NYTProf, however I cannot read profile data:

 $ nytprofhtml -f www/cgi-local/nytprof.out
Reading www/cgi-local/nytprof.out
Profile data incomplete, inflate error -5 ((null)) at end of input file, perhaps the process didn't exit cleanly or the file has been truncated  (refer to TROUBLESHOOTING in the documentation)

I am using sigexit=1 NYTProf option. Here's minimal CGI script that reproduces problem:

#!/usr/bin/perl -d:NYTProf

sleep 1 while 1;
like image 735
el.pescado - нет войне Avatar asked Dec 23 '13 07:12

el.pescado - нет войне


2 Answers

Setting sigexit=1 tells NYTProf to catch the following signals:

INT HUP PIPE BUS SEGV

However, when your CGI script times out, Apache sends SIGTERM. You need to catch SIGTERM:

sigexit=term

To catch SIGTERM in addition to the default signals, use:

sigexit=int,hup,pipe,bus,segv,term
like image 118
ThisSuitIsBlackNot Avatar answered Oct 04 '22 20:10

ThisSuitIsBlackNot


CGI.pm has a debug mode, which you can use to run your program from the command line, and pass your CGI parameters as key/value pairs.

It has another feature that you can use to save your params to a file, and then read that file back in later.

What I've done is added the code to save the params to a file, and run my program, via a browser. This also facilitates my abilty to insure that the browser is sending the correct data.

Then I change the code to read the params from the file, and run it as often as I need until I have everything else debugged.

Once you've got the program running to your satisfaction from the command line, you can run it via nytprof to figure out what is taking all the time.

like image 22
Len Jaffe Avatar answered Oct 04 '22 21:10

Len Jaffe