OpenVZ Forum


Home » General » Support » VDS with Debian 5 performs much worse than with Debian 3. (I'm transfering my sites to a VDS running Debian 5 from a Debian 3 VDS. Now it can handle much less load than before.)
Solved: Re: VDS with Debian 5 performs much worse than with Debian 3. [message #38939 is a reply to message #38711] Sun, 21 February 2010 18:01 Go to previous messageGo to previous message
tryl is currently offline  tryl
Messages: 4
Registered: January 2010
Location: Denmark
Junior Member
I found the problem and the solution:

I the PHP scripts with the most hits I used gethostbyaddr() to get the host name of the web client. It is an advanced web counter, so I have to do this.

The problem doing it with that function is that it is relatively heavy on the system, but that had not been a problem on several PHP 4 installations over several years.

With PHP 5 that changed. Usually there were no problems, but some times a DNS request would take a long time or just hang. Maybe that hanging request blocked for others or maybe Apache had to launch more processes and maybe it hit the ceiling so it could not create more.

It probably only hit 1 of 100 requests, but with the amount of traffic I have, that quickly built up within minutes.

Solution?
<?php
$ip
= long2ip(ip2long($this->ipAddr)*1);
                
$ip = escapeshellarg($ip);
                
$out = shell_exec("host --quick --timeout=2 $ip");

                
// Parse the host name.
                
$out = split("\n", $out);
                if (
count($out) >= 2) {
                        
$out = split(" ", $out[0]);
                        if (
count($out) >= 2) {
                          
$name = $out[1];
                        }
                }
?>

where the IP address is in $this->ipAddr and the host name ends up in $name if it can be set. The script runs a process calling the version of the host command that exists on my system. Other systems may have other versions which would require the parse block to be different.

The implementation is a little paranoid: I convert the IP address to a number, multiply by 1 (so it will always be a integer) and converts it back again. Even with that, I do what you always must: Escape anything from the user which goes into a a shell, file name, SQL etc.
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: IP route issue
Next Topic: Single process freezes whole node.
Goto Forum:
  


Current Time: Fri Oct 18 12:30:06 GMT 2024

Total time taken to generate the page: 0.04845 seconds