ElkArte Community

General => Site Feedback => Topic started by: radu81 on January 11, 2015, 05:10:59 pm

Title: site slow
Post by: radu81 on January 11, 2015, 05:10:59 pm
I don't know if it's just me but today the time request for loading a page here is more than five seconds

This is forum index: Page created in 5.034 seconds with 8 queries.

Do you have "Miserable user" addon here installed?  ;D  ;D  ;D Am I  so miserable?  :D

=== edit ===
now it's fast, the time for loading a page is 0,0X sec
Title: Re: site slow
Post by: Allan on January 11, 2015, 05:37:42 pm
I have been having the same issue all day, slow then fast.
Title: Re: site slow
Post by: emanuele on January 11, 2015, 05:46:07 pm
hmm...  odd.
I thought it may have been the hives (minified css/js), but the files are all dated 2014, so it should not be that.
I didn't see any slowdown, but I have been around only randomly today.
Title: Re: site slow
Post by: Spuds on January 11, 2015, 07:55:34 pm
Was slow for me as well ... not sure why, just was a bit lagging today.
Title: Re: site slow
Post by: meetdilip on January 12, 2015, 06:27:10 am
Fortunately, I missed it :P
Title: Re: site slow
Post by: TE on January 12, 2015, 09:10:02 am
Not sure what happened, probably a temporary issue with the host system..
Title: Re: site slow
Post by: meetdilip on January 12, 2015, 09:16:29 am
May be checking the logs can help.
Title: Re: site slow
Post by: emanuele on January 13, 2015, 02:08:10 pm
Just for the record, it looks like I hit some slow-loading pages myself today ("now", a couple of 10 seconds and this topic 5 seconds).

I wonder if it may be worth adding a log of slow queries/"actions".
Title: Re: site slow
Post by: Spuds on January 13, 2015, 02:17:13 pm
Kind of feels like a network issue, maybe watch net load times to see if the requests are being delayed.

Of course it never hurts to collect data in the slow query log, could be something around that we need still need to tune.
Title: Re: site slow
Post by: emanuele on January 13, 2015, 02:53:58 pm
hmm... frequently it works like that:
load a page => 5 seconds
reload "immediately" => 0.04 seconds
reload again => 5 seconds
reload "immediately" => 0.04 seconds
etc.
The timeline from chrome is attached.
Title: Re: site slow
Post by: Spuds on January 13, 2015, 03:18:24 pm
Yup thats what I'm seeing as well:

// Just the html, no js, css, images, etc ... inital request
DNS resolution 0ms
Connecting: 0ms
Sending: 0ms
Waiting: 5207ms
receiving: 3ms
Title: Re: site slow
Post by: meetdilip on January 14, 2015, 04:43:43 am
The site is slow for me now. Not sure if it is just ElkArte.net
Title: Re: site slow
Post by: TE on January 14, 2015, 09:11:26 am
The server is a vps. It seems to me there is an overload on the host system partially.  The guest  hasn't been changed for quite some time. Maybe I should contact the datacenter team? Let's inspect some more days in order to give them some more details regarding the time the vps is affected.
Title: Re: site slow
Post by: Spuds on January 14, 2015, 09:25:48 am
Makes sense, I did a quick look at the vps load and DB status and it was all cool, so its something that is happening after the DNS hand-off to the sever and it giving that to the vps container.

Whats interesting is I'm often seeing the 5 Sec wait, like something blocked/timing out.  Did it for me just now.
Title: Re: site slow
Post by: emanuele on January 14, 2015, 09:28:09 am
Fine! :D
Can we use this topic to track them?

If so, I just have the page loading in 5.092 seconds.
Honestly, these 5 seconds are quite odd in how repeatable they are, it really look just like something stopping the load for exactly 5 seconds...

ETA: or what teh Spuds said! :P
Title: Re: site slow
Post by: TE on January 14, 2015, 11:35:02 am
I have disabled hostname lookup. Let's see if it fixes the delay..
Title: Re: site slow
Post by: Spuds on January 14, 2015, 07:51:18 pm
Not to jinx us, but since you turned that off I have not had a slowdown ... interesting !
Title: Re: site slow
Post by: Allan on January 14, 2015, 09:12:40 pm
I haven't had any issues after that was turned off.
Title: Re: site slow
Post by: TE on January 15, 2015, 12:27:21 am
Quote from: Spuds – Not to jinx us, but since you turned that off I have not had a slowdown ... interesting !
hostname lookup is cached for 600 seconds, that's why the first request ( most likely not cached) is soo slow. After a quick check the related function host_from_ip() in Subs.php checks:
Code: [Select]
@shell_exec('host...
then
Code: [Select]
@shell_exec('nslookup...
then
Code: [Select]
@gethostbyaddr(...
I'd bet that both shell_exec calls fail.. Maybe should we switch the order of hostname lookups and start with the gethostbyaddr() ?
Title: Re: site slow
Post by: ahrasis on January 15, 2015, 05:52:16 am
Quote from: TE – I'd bet that both shell_exec calls fail.. Maybe should we switch the order of hostname lookups and start with the gethostbyaddr() ?

I will try this as well.
Title: Re: site slow
Post by: radu81 on February 27, 2017, 04:55:28 pm
There is something wrong with the home page (http://www.elkarte.net/), it takes several seconds to be loaded and sometimes is not displayed correctly, the right blocks are not displayed. It's somehow random, now seems working fine, but today I saw it 2-3 times loading very slow. Try it also in incognito mode.
The forum is loading fine
Am I the only one with this problem?
Title: Re: site slow
Post by: Spuds on February 27, 2017, 07:34:15 pm
Had not noticed anything, but I don't tend to land on that page.   It's possible that fetching the "latest" data (commits etc) for display was/is causing a page block, maybe GitHub is slow today
Title: Re: site slow
Post by: emanuele on February 28, 2017, 11:01:59 am
Yep, that's what I was thinking as well.
Title: Re: site slow
Post by: emanuele on March 31, 2018, 12:14:07 pm
It's a few days that randomly I get page loads way out of the average like this one few moments ago:
Page created in 13.742 seconds with 18 queries.
It almost feels like it's recaching too frequently the CSS/JS hives...
Title: Re: site slow
Post by: Trekkie101 on July 28, 2022, 09:31:17 am
This is back as a new head to the same issue. PHP 8.1 on cPanel seems to come without shell_exec.

I've match a patch to check if it's disabled first before even attempting it.

Issue: https://github.com/elkarte/Elkarte/issues/3656
Patch: https://github.com/elkarte/Elkarte/pull/3660

However maybe we're better going to gethostbyaddr() in all cases and accepting sometimes it doesn't work?
Title: Re: site slow
Post by: Spuds on July 28, 2022, 08:52:55 pm
Thanks for the bug report and patch!

Indeed this is a new behavior in 8.1, but they have been warning for some time that @ is a bad idea.

In a couple of areas that I've "Fixed" I did so with  if (function_exists('some_function')) which seemed to work in conjunction with functions placed on the disabled list.  Do you happen to have the list of functions that CP has added to that list?  I just want to do a code search to check if there are other unprotected areas.
Quote from: Trekkie101 – However maybe we're better going to gethostbyaddr()
Looking at that code, you may be right! 
Title: Re: site slow
Post by: Trekkie101 on July 29, 2022, 12:34:24 pm
So down the rabbit hole I went:

gethostbyaddr() in PHP may be incredibly slow. In fact it may be the cause of all the slow reports entirely. So maybe not as the new behaviour haha

The shell_exec / nslookup method is apparently faster, likely why it made it in. It's also why the 'disable hostname lookups' is included as an option.

Function exists may come with bugs vs being explicitly disabled but if function_exists is working, it's defo neater.

Quote from: https://www.php.net/manual/en/function.function-exists.phpNote:
A function name may exist even if the function itself is unusable due to configuration or compiling options (with the image functions being an example).

By default on Cloudlinux cPanel PHP 8.1 the following are disabled.
Code: [Select]
"system, exec, shell_exec, passthru, show_source"

Title: Re: site slow
Post by: Spuds on July 29, 2022, 01:33:24 pm
I'm guessing that PHP does not set any timeout in gethostbyaddr  and so the breakout which sets a 1 second timeout on host and nslookup 

I feel that function can be cleaned up some ... nslookup appears to be part of bind-utils so if you have the host command you should have nslookup.  There is also that hidden modSettings value that could get set (if your host command does not use W) but its not unset if you update your system or move to a new host or ...

Then there is the mt_rand as well, which provides a good chance it going to use gethostbyaddr anyway.  It all seems a bit suspect.
Title: Re: site slow
Post by: Trekkie101 on July 29, 2022, 01:41:56 pm
From 8.1

gethostbyaddr() is gonna be the only method anyway (excluding $SERVER['REMOTE_HOST']

Maybe simplify to that and then turn it off by default?

Trying to save you effort. I've got it off anyway.
Title: Re: site slow
Post by: tino on July 29, 2022, 02:46:24 pm
Code: [Select]
function gethostbyaddr_timeout($ip, $dns, $timeout = 1000)
{
    // random transaction number (for routers etc to get the reply back)
    $data = rand(0, 99);
    // trim it to 2 bytes
    $data = substr($data, 0, 2);
    // request header
    $data .= "\1\0\0\1\0\0\0\0\0\0";
    // split IP up
    $bits = explode(".", $ip);
    // error checking
    if (count($bits) != 4) return "ERROR";
    // there is probably a better way to do this bit...
    // loop through each segment
    for ($x=3; $x>=0; $x--)
    {
        // needs a byte to indicate the length of each segment of the request
        switch (strlen($bits[$x]))
        {
            case 1: // 1 byte long segment
                $data .= "\1"; break;
            case 2: // 2 byte long segment
                $data .= "\2"; break;
            case 3: // 3 byte long segment
                $data .= "\3"; break;
            default: // segment is too big, invalid IP
                return "INVALID";
        }
        // and the segment itself
        $data .= $bits[$x];
    }
    // and the final bit of the request
    $data .= "\7in-addr\4arpa\0\0\x0C\0\1";
    // create UDP socket
    $handle = @fsockopen("udp://$dns", 53);
    // send our request (and store request size so we can cheat later)
    $requestsize = @fwrite($handle, $data);
 
    @socket_set_timeout($handle, $timeout - $timeout%1000, $timeout%1000);
    // hope we get a reply
    $response = @fread($handle, 1000);
    @fclose($handle);
    if ($response == "")
        return $ip;
    // find the response type
    $type = @unpack("s", substr($response, $requestsize+2));
    if ($type[1] == 0x0C00)  // answer
    {
        // set up our variables
        $host = "";
        $len = 0;
        // set our pointer at the beginning of the hostname
        // uses the request size from earlier rather than work it out
        $position = $requestsize+12;
        // reconstruct hostname
        do
        {
            // get segment size
            $len = unpack("c", substr($response, $position));
            // null terminated string, so length 0 = finished
            if ($len[1] == 0)
                // return the hostname, without the trailing .
                return substr($host, 0, strlen($host) -1);
            // add segment to our host
            $host .= substr($response, $position+1, $len[1]) . ".";
            // move pointer on to the next segment
            $position += $len[1] + 1;
        }
        while ($len != 0);
        // error - return the hostname we constructed (without the . on the end)
        return $ip;
    }
    return $ip;
}

Is probably a quicker way to do it at socket level if you have fsockopen or sockets enabled.
Title: Re: site slow
Post by: Spuds on July 29, 2022, 06:45:39 pm
Just to add to the info.

Quote from: tino –
Code: [Select]
function gethostbyaddr_timeout($ip, $dns, $timeout = 1000)
That is an interesting approach .. looks like it would have to be improved to support ipv6 as well