Persistent Perl on the Virtual Host Page 2
2. When you run Speedy on a virtual host, Speedy forks off another version of itself for each user so it isn't advisable that you run every script with it. Speedy has a time-out variable that can be set on each script that will keep the Speedy process running even if the user quits using the script. If you set this time-out to 600 seconds it takes that long for the process to stop. This can cause problems for the server if you suddenly have a lot of Speedy processes that are sitting there waiting to quit. Under heavy load you may run out of sockets since they hang around in a TIME_WAIT state after closing. Most servers are set up to handle at least 256 users so it shouldn't be a problem as long as you keep your time-outs at around 60 seconds.
If you have root access and are running the Apache Web server then this is no problem because Speedy also comes with mod_speedy, which keeps the program from forking another process for each request. You can't install mod_speedy without root access though.
By the way, mod_speedy doesn't hook into the Apache Web server the way mod_perl and FastCGI do so it's a very safe way for Web farms to implement persistence on their servers!
To install SpeedyCGI on a virtual host takes a little extra work than a standard module, but it's worth it. The first thing you need to do is download the module from search.cpan.org, then unpack it into a directory on your host. For those not familiar with how to do this, here's a step by step guide.
To unpack and install type the following commands at the telnet prompt: (SpeedyCGI can't be installed on NT so don't waste your time trying).
gunzip CGI-SpeedyCGI-1.8.3.tar.gz tar -xvf CGI-SpeedyCGI-1.8.3.tar cd CGI-SpeedyCGI-1.8.3 perl Makefile.PL PREFIX=/home/domain (full path to your domain) make make test
Now here's the trick to get it to install because it will always fail in it's default state. Depending on your path to perl this might be a little different, but it will be easy to spot if the make install fails.
Create a "bin" directory in your domain: /home/domain/bin
With Perl located in /usr/local/bin/ you may have to create the directory /home/domain/local/bin. It appears that Speedy is trying to emulate where Perl is installed on the server. If you get an error and it complains about not being able to find the directory then this is most likely the problem and you can simply create the required directory and run make install again.
Once that directory is created, go back into the SpeedyCGI directory and type:
If all goes well you will now have Speedy installed. The shebang line will be a little different than what you're used to, though. The following line reflects that you are running the Speedy executable in your own domain space.
#!/home/domain/bin/speedy -w -- -t60
SpeedyCGI command line options will always follow the -- on the shebang line. Any options before the -- are perl options. The above line reflects a time-out of 60 seconds. There are some other useful options so you should refer to the documentation to get a thorough understanding of Speedy commands.
About the author:
Mark Porter is a Perl Monger and has been programming perl for about three years. He currently owns his own business, imChat Inc which is merging with another business, Balsa-Tech Inc. They sell business intelligence software, do custom CGI programming and are currently looking for startup capitol. Contact Mark at firstname.lastname@example.org.