9k1l4oc8
Posts: 4
Joined: Sat Dec 29, 2018 6:22 pm

Pi slow to respond to initial connection, fast after

Sun Jan 13, 2019 2:01 am

Hello everyone, I do believe this is my first post!

Raspberry Pi 3B+ is working amazingly with the exception of one thing. Whenever I go to connect to it over the internet or over wifi it lags at first before it connects. Connections after the initial connection are quite quick. I have this issue with both SSH and HTTP.

I looked over the forums, but did not see anything similar. Maybe I am missing something and if I am please do inform me. I wouldn't mind diagnosing this myself, but I am not sure what the cause could be. My thought would be maybe the Pi goes into some kind of sleep mode and then only checks for connections so often. I have tried pinging the Pi and the first couple of attempts will not work, but afterwards it works fine and connects very quickly each time after without failure.

Any ideas? Any information I can provide to help?

Thank you so much for your time!

pcmanbob
Posts: 6410
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Pi slow to respond to initial connection, fast after

Sun Jan 13, 2019 11:27 am

Hi.

So the first question is how is your pi connected to your network ?

I am guessing its wifi connected , I have a pi zero that's like this, but I think its because its on the edge of the wifi range as its out in my garage, if I bring it indoors I have no problem with it.

If you can try connecting with a LAN cable to the router you will probably find there is no lag at all.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

9k1l4oc8
Posts: 4
Joined: Sat Dec 29, 2018 6:22 pm

Re: Pi slow to respond to initial connection, fast after

Sun Jan 13, 2019 8:24 pm

pcmanbob wrote:
Sun Jan 13, 2019 11:27 am
Hi.

So the first question is how is your pi connected to your network ?

I am guessing its wifi connected , I have a pi zero that's like this, but I think its because its on the edge of the wifi range as its out in my garage, if I bring it indoors I have no problem with it.

If you can try connecting with a LAN cable to the router you will probably find there is no lag at all.

Code: Select all

C:\Users\#####>ping -n 20 10.0.0.180 // 3:20 PM 13 JAN 2019

Pinging 10.0.0.180 with 32 bytes of data:
Request timed out.
Request timed out.
Reply from 10.0.0.180: bytes=32 time=69ms TTL=64
Reply from 10.0.0.180: bytes=32 time=3ms TTL=64
Reply from 10.0.0.180: bytes=32 time=5ms TTL=64
Reply from 10.0.0.180: bytes=32 time=7ms TTL=64
Reply from 10.0.0.180: bytes=32 time=8ms TTL=64
Reply from 10.0.0.180: bytes=32 time=3ms TTL=64
Reply from 10.0.0.180: bytes=32 time=3ms TTL=64
Reply from 10.0.0.180: bytes=32 time=2ms TTL=64
Reply from 10.0.0.180: bytes=32 time=4ms TTL=64
Reply from 10.0.0.180: bytes=32 time=6ms TTL=64
Reply from 10.0.0.180: bytes=32 time=5ms TTL=64
Reply from 10.0.0.180: bytes=32 time=5ms TTL=64
Reply from 10.0.0.180: bytes=32 time=3ms TTL=64
Reply from 10.0.0.180: bytes=32 time=7ms TTL=64
Reply from 10.0.0.180: bytes=32 time=6ms TTL=64
Reply from 10.0.0.180: bytes=32 time=11ms TTL=64
Reply from 10.0.0.180: bytes=32 time=5ms TTL=64
Reply from 10.0.0.180: bytes=32 time=7ms TTL=64

Ping statistics for 10.0.0.180:
    Packets: Sent = 20, Received = 18, Lost = 2 (10% loss),
Approximate round trip times in milli-seconds:
    Minimum = 2ms, Maximum = 69ms, Average = 8ms
    
---------------------------------------------------------------------------------------------

C:\Users\#####>ping -n 20 10.0.0.180 // 12:54PM 13 JAN 2019

Pinging 10.0.0.180 with 32 bytes of data:
Request timed out.
Request timed out.
Reply from 10.0.0.180: bytes=32 time=139ms TTL=64
Reply from 10.0.0.180: bytes=32 time=8ms TTL=64
Reply from 10.0.0.180: bytes=32 time=17ms TTL=64
Reply from 10.0.0.180: bytes=32 time=10ms TTL=64
Reply from 10.0.0.180: bytes=32 time=13ms TTL=64
Reply from 10.0.0.180: bytes=32 time=7ms TTL=64
Reply from 10.0.0.180: bytes=32 time=5ms TTL=64
Reply from 10.0.0.180: bytes=32 time=13ms TTL=64
Reply from 10.0.0.180: bytes=32 time=5ms TTL=64
Reply from 10.0.0.180: bytes=32 time=35ms TTL=64
Reply from 10.0.0.180: bytes=32 time=10ms TTL=64
Reply from 10.0.0.180: bytes=32 time=7ms TTL=64
Reply from 10.0.0.180: bytes=32 time=5ms TTL=64
Reply from 10.0.0.180: bytes=32 time=5ms TTL=64
Reply from 10.0.0.180: bytes=32 time=5ms TTL=64
Reply from 10.0.0.180: bytes=32 time=8ms TTL=64
Reply from 10.0.0.180: bytes=32 time=6ms TTL=64
Reply from 10.0.0.180: bytes=32 time=2ms TTL=64

Ping statistics for 10.0.0.180:
    Packets: Sent = 20, Received = 18, Lost = 2 (10% loss),
Approximate round trip times in milli-seconds:
    Minimum = 2ms, Maximum = 139ms, Average = 16ms
I went on ahead did two different pings at two different times. As you can see the Raspberry Pi fails to respond at first, but once it does it works great.

"I am guessing its wifi connected..."

I don't think that is it because as you can see it is the only initial reach out to the Pi that is an issue. It is like it wakes up after.

Does anyone understand what I am saying?

User avatar
PeterO
Posts: 4873
Joined: Sun Jul 22, 2012 4:14 pm

Re: Pi slow to respond to initial connection, fast after

Sun Jan 13, 2019 9:01 pm

9k1l4oc8 wrote:
Sun Jan 13, 2019 2:01 am
Hello everyone, I do believe this is my first post!

Raspberry Pi 3B+ is working amazingly with the exception of one thing. Whenever I go to connect to it over the internet or over wifi it lags at first before it connects. Connections after the initial connection are quite quick. I have this issue with both SSH and HTTP.

I looked over the forums, but did not see anything similar. Maybe I am missing something and if I am please do inform me. I wouldn't mind diagnosing this myself, but I am not sure what the cause could be. My thought would be maybe the Pi goes into some kind of sleep mode and then only checks for connections so often. I have tried pinging the Pi and the first couple of attempts will not work, but afterwards it works fine and connects very quickly each time after without failure.

Any ideas? Any information I can provide to help?

Thank you so much for your time!
I've seen similar behaviour caused by DNS name resolution problems. Sometimes nothing happens until some timeout happens then it carries on as normal. If the result is cached locally then next time the timeout doesn't happen.

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

9k1l4oc8
Posts: 4
Joined: Sat Dec 29, 2018 6:22 pm

Re: Pi slow to respond to initial connection, fast after

Sun Jan 13, 2019 9:22 pm

PeterO wrote:
Sun Jan 13, 2019 9:01 pm
I've seen similar behaviour caused by DNS name resolution problems. Sometimes nothing happens until some timeout happens then it carries on as normal. If the result is cached locally then next time the timeout doesn't happen.

PeterO
Well since there is no domain and this is happening just locally over the WiFi do you have any suggestions on how this is fixed?

Is there a main fix for the DNS issues that come up that might apply here?

pcmanbob
Posts: 6410
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Pi slow to respond to initial connection, fast after

Mon Jan 14, 2019 10:14 am

Its just possible that your router is dropping the connection to your pi as it puts the wifi connection to sleep due to a lack of traffic on the connection, once the connection is established again because there is traffic between the pi and the route the wifi connection remains established.

That's why I said try a wired connection if your pi always responds to a ping even after so period of inactivity it would prove it was the wifi connection.

On my own pi zero I have it ping the route once every 5min just to keep the connection active.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

9k1l4oc8
Posts: 4
Joined: Sat Dec 29, 2018 6:22 pm

Re: Pi slow to respond to initial connection, fast after

Mon Jan 14, 2019 10:02 pm

pcmanbob wrote:
Mon Jan 14, 2019 10:14 am
Its just possible that your router is dropping the connection to your pi as it puts the wifi connection to sleep due to a lack of traffic on the connection, once the connection is established again because there is traffic between the pi and the route the wifi connection remains established.

That's why I said try a wired connection if your pi always responds to a ping even after so period of inactivity it would prove it was the wifi connection.

On my own pi zero I have it ping the route once every 5min just to keep the connection active.
Oh! Thanks for the response. That explanation made so much more sense. Thank you and I will play around with that.

Return to “Troubleshooting”