Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lwIP http request takes too long at altcp_connect() in TLS example #411

Open
svetlollc opened this issue Aug 5, 2023 · 7 comments
Open

Comments

@svetlollc
Copy link

Problem

I successfully build and run a TLS client Example (picow_tls_client_background executable) from the GitHub, however a simple http GET request takes about 20 seconds. It does not actually depend on the server response: I tested server, that responds empty string at all, and server with about few kb output - no matter, it takes about 20 seconds to make a request.

As the result of debug, I understand, that 99% of the request time takes altcp_connect- before that, it takes several miliseconds, and after that, starting from the callback, i.e. tls_client_connected, it takes about millisecond until the request is made:

Pico W turned on -- [few ms]  -- altcp_connect() -- [19 sec] -- tls_client_connected() -- [1 ms] -- I see comleted incoming request on the server

Tried to solve

I made a reserch, I found that such behaviour, can be caused by lwIP configuration in lwipopts.h. It already sounds weird, because it probably should been tested by Raspberry Pi developers, who posted the code on GitHub.

So I set #define MEMP_SANITY_CHECK 0, set

#define LWIP_DEBUG 0 
#define ALTCP_MBEDTLS_DEBUG  LWIP_DBG_OFF

I also tried to reduce TCP_WND or\and TCP_MSS, but any signficant changes produced cmake errors, that something overflows something. However, I reduced a bit that values, without errors at building.

However, all of that actions did not change request time - it still the same.

@svetlollc
Copy link
Author

I also tried (although, as I wroted, this step is passed fast) to connect to ip directly, instead of DNS resolving by hostname, and it still takes same long.

@svetlollc
Copy link
Author

Also, in the code, I tried to set big (45) as well as small (1-5) values of TLS_CLIENT_TIMEOUT_SECS - it does not affect anything

@svetlollc
Copy link
Author

picow_tls_client_poll executable makes ~20 sec HTTP request as well.
Changing delay value in cyw43_arch_wait_for_work_until(make_timeout_time_ms(1000)); does not solve the problem

@svetlollc
Copy link
Author

svetlollc commented Aug 21, 2023

I also tried to call altcp_nagle_disable, when setup callbacks, tried to define TPC_NODELAY, I also tried another Pico W board — no changes at all.

Can someone at least tell do they have or not same experience? Maybe it just how things works?

@svetlollc
Copy link
Author

svetlollc commented Aug 21, 2023

So, in case of other people have at least few seconds long requests, after weeks of searching, I have only few possible issues:

  1. In some examples, I saw that people somewhere defines country. In the Pico W examples, country doesn’t specify, maybe it is the reason.
  2. Some examples call ntp_time_init() and get_ntp_time() — I do not know what it is, but maybe it relates to the problem, when you try to open some site on pc with wrong date, and browser doesn’t open it with error, that the clock is late.
  3. Some examples call functions that setup mask, ip-adress, and similar stuff, as understand Pico W itself.
  4. Low power supply, although I tried to connect Pico W to different sources: laptop usb, just a phone usb charger, other.
  5. This how things works - it is not a full computer, it has only 133 MHz clock, so it works slow (hope this is wrong, at least because I saw, how Pico can output some graphics on VGA in with 60 fps, and do other relatively heave work).

@svetlollc
Copy link
Author

svetlollc commented Aug 22, 2023

Today I finally managed to make debug work, here is what Pico W outputs (nothing special):

resolving <hostIspecified>
DNS resolving complete
connecting to server IP <123.456.7.8(ip that host pointing to)> port 443
connected to server, sending request
***
new data received from server:
***

HTTP/1.1 200 OK
Content-Length: 0
Content-Type: text/html; charset=UTF-8
Date: Tue, 22 Aug 2023 16:11:54 GMT
Server: Apache
X-Powered-By: PHP/7.0.32
Connection: close


connection was closed gracefully
connection closed
Test passed
All done
  • stuff with brackets <> is edited.

So, of course 99% of time (about 18 seconds) takes connecting to server IP <123.456.7.8(ip that host pointing to)> port 443 line

@svetlollc
Copy link
Author

Today I decided to run python, instead of C, to test http request on the Pico W, and it works fine (takes few seconds).

So, it is definetely me doing somehing wrong.

Can someone please at least point the direction, where should look to?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant