Skip to content

Very slow evaluation of the status code #38

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

Open
koulombus opened this issue Feb 17, 2018 · 4 comments
Open

Very slow evaluation of the status code #38

koulombus opened this issue Feb 17, 2018 · 4 comments
Labels
type: imperfection Perceived defect in any part of project

Comments

@koulombus
Copy link

Hi,

I use the sample "SimpleGet" to get a UUID from a server.

The output show me a very long time on getting the status code.

making GET request

Time after get Request: 524ms
Time after get Status code: 9538ms
Time after get response body: 9566ms

Status code: 200
Response: 
{
  "uuid" : "b44c5405-7c56-4879-b4e8-ef28fc06d4a7"
}
Wait five seconds

Here the code...

void loop() {
  Serial.println("making GET request");
  long startTime = millis();
  client.get("/api/v1/uuid");

  Serial.println();
  Serial.print("Time after get Request: ");
  Serial.print(millis() - startTime);
  Serial.println("ms");

  // read the status code and body of the response
  statusCode = client.responseStatusCode();

  Serial.print("Time after get Status code: ");
  Serial.print(millis() - startTime);
  Serial.println("ms");

  response = client.responseBody();

  Serial.print("Time after get response body: ");
  Serial.print(millis() - startTime);
  Serial.println("ms");

  Serial.println();
  Serial.print("Status code: ");
  Serial.println(statusCode);
  Serial.println("Response: ");
  Serial.println(response);

  Serial.println("Wait five seconds");
  delay(5000);
}

is there something wrong with this simple code?

@koulombus koulombus reopened this Feb 17, 2018
@sandeepmistry
Copy link

@cawena what if you add a client.stop() before the wait?

In the future if would be valuable to get the entire sketch you are using, as well as the hardware you are using.

@georgeveys
Copy link

Can anyone shed any light on this? I'm also experiencing almost a second of latency on decoding the response and status code

@mmaxbar
Copy link

mmaxbar commented Apr 13, 2021

@georgeveysSFL
try this:
in "HttpClient.h" go to this entry, change the kHttpWaitForDataDelay from 1000 to 100:

// Number of milliseconds that we wait each time there isn't any data
// available to be read (during status code and header processing)
static const int kHttpWaitForDataDelay = 100; 

The one second latency comes from the code running through too quickly, so there is no response to be collected yet. This triggers a 1000ms Delay.
If you don't want to mess with the library, you could also add a sufficient wait before trying to access the response in your code.

@andersruneson
Copy link

This is fixed in below PR
#125
However, the time could be reduced even more, the client tries several times until data is returned.

@per1234 per1234 added the type: imperfection Perceived defect in any part of project label Apr 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

6 participants